react-i18next: [React Native] undefined languages warning when using iOS Simulator
🐛 Bug Report
When initialising i18next on React Native app on iOS simulator, warning appears (translations and display is working fine). On Android emulator / real device, no warning is appearing. The “quick fix” is to set lng
config option, but with this option detector is not working anymore and force language.
The warning :
WARN react-i18next:: i18n.languages were undefined or empty undefined
With debug set to true, I have another warning which says this :
WARN i18next::translator: key "screenTitles.trackingOrderTitle" for languages "en" won't get resolved as namespace "translation" was not yet loaded This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!
I’ve set this condition on my App root to be sure that i18n is initialised before using any translation hook :
const AppConfig = () => {
return i18n.isInitialized ? (
<AppContainer />
) : (
<></>
)
}
I’ve also tried to use init callback to set a boolean state, same behaviour.
To Reproduce
import i18n from 'i18next'
import i18nextReactNative from 'i18next-react-native-language-detector'
import enTranslation from './en/translation.json'
import frTranslation from './fr/translation.json'
import esTranslation from './es/translation.json'
import deTranslation from './de/translation.json'
import { initReactI18next } from 'react-i18next'
const resources = {
en: { translation: enTranslation },
fr: { translation: frTranslation },
es: { translation: esTranslation },
de: { translation: deTranslation },
}
void i18n
.use(initReactI18next)
.use(i18nextReactNative)
.init({
resources,
fallbackLng: 'en',
interpolation: {
escapeValue: false,
},
})
export default i18n
Expected behavior
No warning appearing
Your Environment
- React Native 0.64.0, React 17.0.2
- i18next 20.2.1 / react-i18next 11.8.13 / i18next-react-native-language-detector 1.0.2
- MacOS
- iOS Simulator “iPhone 12 Pro” with iOS 14.4
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 20 (11 by maintainers)
Types fixed with: v20.2.4
In theory it’s string or array…