如何解决i18next::languageUtils:拒绝在 supportedLngs 中找不到语言代码:en
我开发了一个 React 应用程序,我使用 i18next、react-i18next、i18next-http-backend 进行本地化。 >
在我的应用程序中,我现在只想支持 en-us 语言代码,将来可能会添加更多语言,因此我为 i18n 配置添加了以下设置。
import i18n from "i18next";
import backend from "i18next-http-backend";
import { initReactI18next } from "react-i18next";
i18n
.use(backend)
.use(initReactI18next)
.init({
lng: "en-us",fallbackLng: "en-us",debug: true,supportedLngs: ["en-us"],lowerCaseLng: true,interpolation: {
escapeValue: false,formatSeparator: ","
}
});
export default i18n;
并将本地化翻译文件放在public/locales/en-us/translation.json。我添加了 supportedLngs,因为我希望我的 i18next-http-backend 应该只加载支持的语言。
当我运行应用程序时,我收到以下警告
i18next::languageUtils: rejecting language code not found in supportedLngs: en
根据此处的文档:https://www.i18next.com/overview/configuration-options
我也尝试设置 nonExplicitSupportedLngs: true 但我的翻译文件没有加载,我收到另一个奇怪的警告,如下所示:
i18next::languageUtils: rejecting language code not found in supportedLngs: en-us
i18next::languageUtils: rejecting language code not found in supportedLngs: en
我怎样才能摆脱警告?我错过了什么吗?
提前致谢
解决方法
尝试将加载选项设置为“currentOnly” https://www.i18next.com/overview/configuration-options#languages-namespaces-resources
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。