首页 > 解决方案 > 如何更改默认值 react-i18next(在本地存储中)

问题描述

我正在使用后端和语言检测器,但是:

在 localstorage 中写入I18nextLng的值为en-US,如何使默认值为I18nextLng的值为En

初始化和其他设置 - 默认文档

.init({
    fallbackLng: 'en',
    debug: true,
    interpolation: {
        escapeValue: false,
    },
})

标签: reactjstypescriptreact-i18next

解决方案


我从来没有用过语言检测器,但是我设置默认语言的方式是设置lng键,并且有资源obj

const resources = {
  en: { translation: {...} },
  fr: { translation: {...} }
}

.init({
    resources,
    lng: 'fr' // this is the default language. Try to put this
    fallbackLng: 'en',
    debug: true,
    interpolation: {
        escapeValue: false,
    },
})

推荐阅读