[英]How to use i18next with namespace in pure javascript function?
我有 function
const myTranslation = async () => {
const translation = await i18n.loadNamespaces(['home']);
console.log(translation); //-> return undefinded
console.log(translation.t('title')); //-> return Uncaught (in promise) TypeError: Cannot read property 't' of undefined
};
如何獲得我的翻譯 home.title?
i18n.loadNamespaces
只是加載所需的命名空間,為了翻譯你需要使用i18n.t
。
const myTranslation = async () => {
await i18n.loadNamespaces(['home']);
console.log(i18n.t('title'));
// --------------^
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.