i18next 缺少密钥而密钥存在?

i18next missing key whereas the key exists?

我经常遇到以下错误:

i18next::translator: missingKey fr common my key.

而密钥在翻译文件中(已正确加载并考虑在内)。为什么?

编辑: 当我在翻译文件的键中有一个 .(点字符)时,就会发生这种情况。

翻译文件必须是有效的 JSON 文件并且不能包含带有 .(点)字符的键。如果密钥包含点,i18next 将抱怨缺少密钥。

如果我能猜到的话,我很确定您正在访问 t 函数,以便在从后端加载的翻译之前提前访问。

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

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

将其添加到 i18n.use(LanguageDetector).init({})

中的 i18n.js

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