This plugin caches your user's language in [@capacitor/references](https://github.com/ionic-team/capacitor-plugins/tree/main/preferences).
npm install i18next-capacitor-language-detectorBash
npm i i18next-capacitor-language-detector
`
Then pass it to your i18n instance
`JavaScript
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):
`JavaScript
// 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))
``