Reactjs 无法使用react中的i18next操作语言更改按钮
我想在使用i18next单击按钮时更改语言。 下面是我的源代码,当点击按钮时无法更改语言。 请告诉我需要修理什么。 我已导入导入“”/i18n';在index.js i18n.jsReactjs 无法使用react中的i18next操作语言更改按钮,reactjs,i18next,Reactjs,I18next,我想在使用i18next单击按钮时更改语言。 下面是我的源代码,当点击按钮时无法更改语言。 请告诉我需要修理什么。 我已导入导入“”/i18n';在index.js i18n.js import i18n from 'i18next' import Backend from 'i18next-http-backend' import LanguageDetector from 'i18next-browser-languagedetector' import { initReactI18next
import i18n from 'i18next'
import Backend from 'i18next-http-backend'
import LanguageDetector from 'i18next-browser-languagedetector'
import { initReactI18next } from 'react-i18next'
i18n
.use(Backend)
.use(LanguageDetector)
.use (initReactI18next)
.init({
// default/fallback language
fallbackLng: 'ja',
ns: ["default"],
defaultNS: "default",
useSuspense: false,
//detects and caches a cookie from the language provided
react: {
useSuspense: false,
wait: false,
},
detection: {
order: ['queryString', 'cookie'],
cache: ['cookie']
},
interpolation: {
escapeValue: false
},
})
export default i18n;
Nav.js
import i18n from "i18next";
import { useTranslation } from 'react-i18next';
const Nav = () => {
const [t, i18n] = useTranslation();
const currentRoute = useHistory().location.pathname.toLowerCase();
return (
<div className="tab-bar">
<label className="logo">{t("FPF Support Tool")}</label>
</label>
</div>
<div>
<button onClick={() => i18n.changeLanguage("ja")}>
日本
</button>
<button onClick={() => i18n.changeLanguage("en")}>
英語
</button>
</div>
)
}
从“i18next”导入i18n;
从“react-i18next”导入{useTranslation};
常量导航=()=>{
const[t,i18n]=usetransation();
const currentRoute=useHistory().location.pathname.toLowerCase();
返回(
{t(“FPF支持工具”)}
i18n.changeLanguage(“ja”)}>
日本
i18n.changeLanguage(“en”)}>
英語
)
}
如果将debug设置为true,控制台输出是什么?也许可以用这个例子来比较:@adrai非常感谢你。我需要i18n.js文件中的init资源