Reactjs 如何向react网站添加多语言支持我已经使用过i18next,但现在如何更改语言
我有一个react应用程序,它有i18next库以支持多种语言,这些是我的文件 我的i18n.js文件如下所示,我还有两个翻译json文件,它们有英文字符串和中文字符串,但是我如何在之间切换,以及如何使用i18next,如果有任何帮助都会很有帮助Reactjs 如何向react网站添加多语言支持我已经使用过i18next,但现在如何更改语言,reactjs,i18next,Reactjs,I18next,我有一个react应用程序,它有i18next库以支持多种语言,这些是我的文件 我的i18n.js文件如下所示,我还有两个翻译json文件,它们有英文字符串和中文字符串,但是我如何在之间切换,以及如何使用i18next,如果有任何帮助都会很有帮助 import i18n from 'i18next'; import { initReactI18next } from 'react-i18next'; import translationEN from '../locales/en/transla
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import translationEN from '../locales/en/translation.json';
import Backend from 'i18next-http-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
const resources = {
en: {
translation: translationEN
}
};
i18n
// load translation using http -> see /public/locales (i.e. https://github.com/i18next/react-i18next/tree/master/example/react/public/locales)
// learn more: https://github.com/i18next/i18next-http-backend
// .use(Backend)
// detect user language
// learn more: https://github.com/i18next/i18next-browser-languageDetector
// .use(LanguageDetector)
// pass the i18n instance to react-i18next.
.use(initReactI18next)
.use(Backend)
.use(LanguageDetector)
// for all options read: https://www.i18next.com/overview/configuration-options
.init({
resources,
fallbackLng: 'en',
debug: true,
interpolation: {
escapeValue: false
},
react: {
useSuspense: false
}
});
export default i18n;
你需要使用这个函数