为什么I18Next可以使用某些语言​而不是与其他语言一起使用?
我正在使用i18next,当我用语言调用changelguage函数'es'或'en'' 'de' 'fr' 'it''或其他任何东西,它不起作用,而是退缩。 这很奇怪,因为有两种语言的工作完美,但是其他三种语言不起作用,
这是我的 i18n.ts 文件
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
const frenchTranslatorObject = require('../assets/locales/fr.json');
const spanishTranslatorObject = require('../assets/locales/es.json');
const englishTranslationObject = require('../assets/locales/en.json');
const germanTranslationObject = require('../assets/locales/gr.json');
const portugeseTranslationObject = require('../assets/locales/pt.json');
const italianishTranslationObject = require('../assets/locales/it.json');
export default i18n.use(initReactI18next).init({
resources: {
es: {
translation: {
'landing.main.title': 'en SPANISH',
},
},
en: {
translation: {
'landing.main.title': 'EN ENGLISH',
},
},
fr: {
translations: {
'landing.main.title': 'en FRANCES',
},
},
de: {
translations: {
'landing.main.title': 'EN ALEMANNNN',
},
},
it: {
translations: {
'landing.main.title': 'EN ITALIANO',
},
},
pt: {
translations: {
'landing.main.title': 'EN PORTUGUES',
},
},
},
lng: 'es',
fallbackLng: ['en', 'es', 'fr'],
compatibilityJSON: 'v3',
interpolation: {
escapeValue: false,
format: function (value, format, lng) {
if (value && format === 'uppercase') {
return value.toUpperCase();
} else if (value && format === 'lowercase') {
return value.toLowerCase();
} else if (value && format === 'capitalize') {
return value.charAt(0).toUpperCase() + value.slice(1);
}
return value;
},
},
});
i18n.on('languageChanged', (lng) => {
console.info('callback log that triggers when language change', lng);
});
,我将其称为函数:i18n.changelanguage('de') ;
调试信息
在我以调试模式触发changelanguage('de')时,它似乎会改变它:
i18next:langualagechanged de
i18n.language //这打印' de'i18n.getDatabolanguage
('es')//,这返回de translation对象
:拒绝在supportedlngs中找不到的语言代码:dev:dev”
,并说“ i18next :: Legurchutils 感激
I'm using i18next and when i call the changeLanguage function with the languages 'es' or 'en' it seems to work perfectly, but when i call it when another language 'de' 'fr' 'it' or whatever, it doesn't works and it goes to the fallbackLng.
It's kind of weird because with two languages works perfect, but the other three languages doesn't works
This is my i18n.ts file
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
const frenchTranslatorObject = require('../assets/locales/fr.json');
const spanishTranslatorObject = require('../assets/locales/es.json');
const englishTranslationObject = require('../assets/locales/en.json');
const germanTranslationObject = require('../assets/locales/gr.json');
const portugeseTranslationObject = require('../assets/locales/pt.json');
const italianishTranslationObject = require('../assets/locales/it.json');
export default i18n.use(initReactI18next).init({
resources: {
es: {
translation: {
'landing.main.title': 'en SPANISH',
},
},
en: {
translation: {
'landing.main.title': 'EN ENGLISH',
},
},
fr: {
translations: {
'landing.main.title': 'en FRANCES',
},
},
de: {
translations: {
'landing.main.title': 'EN ALEMANNNN',
},
},
it: {
translations: {
'landing.main.title': 'EN ITALIANO',
},
},
pt: {
translations: {
'landing.main.title': 'EN PORTUGUES',
},
},
},
lng: 'es',
fallbackLng: ['en', 'es', 'fr'],
compatibilityJSON: 'v3',
interpolation: {
escapeValue: false,
format: function (value, format, lng) {
if (value && format === 'uppercase') {
return value.toUpperCase();
} else if (value && format === 'lowercase') {
return value.toLowerCase();
} else if (value && format === 'capitalize') {
return value.charAt(0).toUpperCase() + value.slice(1);
}
return value;
},
},
});
i18n.on('languageChanged', (lng) => {
console.info('callback log that triggers when language change', lng);
});
and I call the function like this: i18n.changeLanguage('de');
Debug info
In the console when i trigger the changeLanguage('de') in debug mode it seem to change it:
i18next: languageChanged de
i18n.language // this prints 'de'
i18n.getDataByLanguage('es') // and this returns the DE translation object
and it says "i18next::languageUtils: rejecting language code not found in supportedLngs: dev"
If anyone sees any errors that can tell me, I will be grateful
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论