Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i18next missing key whereas the key exists?

I often get the following error:

i18next::translator: missingKey fr common my key.

whereas the key is in the translation file (which is correctly loaded and taken into account). Why?

Edit: This happens when I have a . (dot character) in a key in the translation file.

like image 392
arthur.sw Avatar asked Aug 17 '17 16:08

arthur.sw


3 Answers

The translation file must be a valid JSON file and cannot contain keys with the . (dot) character. i18next will complain of a missing key if the key contains a dot.

like image 199
arthur.sw Avatar answered Nov 07 '22 15:11

arthur.sw


If i could guess i'm rather sure you're accessing the t function to early -> before the translations where loaded from the backend.

i18next.init({
  lng: 'en',
  debug: true
}, function(err, t) {
  // initialized and ready to go!
  i18next.t('key'); // -> ok
});

i18next.t('key'); // -> not ok as not yet loaded translations
like image 21
jamuhl Avatar answered Nov 07 '22 15:11

jamuhl


  // allow keys to be phrases having `:`, `.`
keySeparator: false, 
nsSeparator: false, 

Add that to your i18n.js inside i18n.use(LanguageDetector).init({})

Documentation https://www.i18next.com/principles/fallback#key-fallback

like image 1
Anna Logacheva Avatar answered Nov 07 '22 17:11

Anna Logacheva