gpt4 book ai didi

javascript - 无法读取未定义的属性 'toResolveHierarchy'

转载 作者:行者123 更新时间:2023-11-28 03:59:33 26 4
gpt4 key购买 nike

我通过传递语言代码(en-UK)来调用 i18next 更改语言函数:

var changeLng = function (varLng) {  
i18next.changeLanguage('en', (err, t) => {
if (err) return console.log('something went wrong loading', err);
t('applog'); // -> same as i18next.t
});
};

我遇到以下问题:

VM4081 i18next.js:1912 Uncaught TypeError: Cannot read property 'toResolveHierarchy' of undefined
at setLng (VM4081 i18next.js:1912)
at I18n.changeLanguage (VM4081 i18next.js:1927)
at changeLng (VM4079 langUK.js:23)
at HTMLImageElement.<anonymous> (VM4079 langUK.js:8)

我认为当 i18next 尝试执行该操作时出现问题:

_this4.languages = _this4.services.languageUtils.toResolveHierarchy(l);

但我看不出正确执行此操作需要什么。预先感谢您的支持, jack

最佳答案

您是否正确初始化了i18next?这段代码对我有用:

i18next.init({
lng: 'en',
debug: true,
resources: {
en: {
translation: {
"key": "hello world"
}
}
}
}, function(err, t) {
// initialized and ready to go!
console.log("Ready to go!");
});

var changeLng = function(varLng) {
i18next.changeLanguage('en', (err, t) => {
if (err) return console.log('something went wrong loading', err);
t('applog'); // -> same as i18next.t
});
};

changeLng()
<script src="https://unpkg.com/i18next/i18next.min.js"></script>

编辑: took this from the documentation

关于javascript - 无法读取未定义的属性 'toResolveHierarchy',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47250329/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com