i18next missing key whereas the key exists?
Asked Answered
A

3

6

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.

Anaerobe answered 17/8, 2017 at 16:43 Comment(0)
A
3

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.

Anaerobe answered 17/8, 2017 at 16:43 Comment(1)
if having keys with . just set the keySeparator to false on init.Myriagram
M
4

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
Myriagram answered 18/8, 2017 at 10:24 Comment(0)
A
3

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.

Anaerobe answered 17/8, 2017 at 16:43 Comment(1)
if having keys with . just set the keySeparator to false on init.Myriagram
O
2

  // 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

Oesophagus answered 5/2, 2021 at 17:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.