i18next 缺少密钥但找到了其他密钥
我什么都不懂了。
我使用 i18next 并想要访问我的密钥,但它不起作用。
i18next::translator: missingKey de translation profile profile
i18next::translator: missingKey de translation profile profile
i18next::translator: missingKey de translation profile profile
这是我的 Translation.json
{
"app_name": "Test (NEW DE)",
"profile": "ss"
}
这有效:
<Text>{ t('app_name') }</Text>
这不起作用:
<Text>{ t('profile') }</Text>
任何人都可以解释我为什么它不能正常工作吗?
i18下一个
import i18next from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from 'i18next-browser-languagedetector';
import HttpApi from 'i18next-http-backend';
i18next
.use(HttpApi)
.use(LanguageDetector)
.use(initReactI18next)
.init({
react: {
useSuspense: false
},
fallbackLng: 'en',
compatibilityJSON: 'v3',
lng: 'de',
debug: process.env.NODE_ENV === 'development',
backend: {
loadPath: `http://192.168.0.249:4000/public/locales/{{lng}}/translation.json`,
},
interpolation: {
escapeValue: false,
},
keySeparator: '.',
});
export default i18next;
I dont understand nothing anymore.
I use i18next and want to access to my key but it does not work.
i18next::translator: missingKey de translation profile profile
i18next::translator: missingKey de translation profile profile
i18next::translator: missingKey de translation profile profile
this is my translation.json
{
"app_name": "Test (NEW DE)",
"profile": "ss"
}
this works:
<Text>{ t('app_name') }</Text>
this not working:
<Text>{ t('profile') }</Text>
can anyone explain me why its not working correctly ?
i18next
import i18next from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from 'i18next-browser-languagedetector';
import HttpApi from 'i18next-http-backend';
i18next
.use(HttpApi)
.use(LanguageDetector)
.use(initReactI18next)
.init({
react: {
useSuspense: false
},
fallbackLng: 'en',
compatibilityJSON: 'v3',
lng: 'de',
debug: process.env.NODE_ENV === 'development',
backend: {
loadPath: `http://192.168.0.249:4000/public/locales/{{lng}}/translation.json`,
},
interpolation: {
escapeValue: false,
},
keySeparator: '.',
});
export default i18next;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我怀疑,您太早调用 t 函数并且没有等待翻译完全加载。
如果您不使用 Suspense:
useSuspense: false
您需要确保检查就绪标志。https://react.i18next.com/latest/usetranslation-hook#不使用挂起
https://react.i18next.com/latest/withtranslation-hoc#not-using-suspense
I suspect, you're calling the t function too early and are not waiting for the translations to be fully loaded.
If you're not using suspense:
useSuspense: false
you need to make sure you check for the ready flag instead.https://react.i18next.com/latest/usetranslation-hook#not-using-suspense
https://react.i18next.com/latest/withtranslation-hoc#not-using-suspense
这是因为下划线不能以关键名称为单位。不可能有任何特殊角色。该名称需要是骆驼才能正常工作。
It's because of the underscore cannot be in the key name. There can't be any special characters. The name needs to be camelcase for it to work.