Détail du package

i18next-capacitor-language-detector

Pioooooo1.1kMIT0.1.0

This plugin caches your user's language in @capacitor/references.

ionic, capacitor, i18n, i18next

readme

i18next Capacitor Language Detector

This plugin caches your user's language in @capacitor/references.

Stole most code from i18next-react-native-async-storage.

Getting Started

Install using:

npm i i18next-capacitor-language-detector

Then pass it to your i18n instance

import LanguageDetector from "i18next-capacitor-language-detector"

i18n.use(LanguageDetector());

Fallback mechanism

You can pass a fallback function or language to the plugin in case it fails to find the user's language in the local storage (typically on the app's first run):

// With a fallback language
i18n.use(LanguageDetector('en'))

// With a fallback function
const detectUserLanguage = (callback) => {
  return Expo
    .DangerZone
    .Localization
    .getCurrentLocaleAsync()
    .then(lng => { callback(lng.replace('_', '-')); })
}

/*
const detectUserLanguage = () => {    
  return navigator.language;
}
*/

i18n.use(LanguageDetector(detectUserLanguage))