[英]i18next 'resGetPath' not implementing in plugin initialization
我想在這個項目中存儲translation.json文件,並讓in18next訪問它們。 不幸的是,我似乎無法正確實現resGetPath
屬性。 當我使用resources
對象初始化插件時,它可以正常工作。 我猜json文件的路徑或結構有問題,但是我似乎在SO或i18next的任何論壇上都找不到類似的問題(大多數人的大型項目只是從服務器)。 我想根據用戶選擇的語言環境簡單地引用本地翻譯文件。 感謝您的時間=)。
這是translation.js的代碼,可以很好地加載到index.html中:
$(document).ready(function() {
i18next.init({
lng: 'en',
// resources: {
// en: {
// translation: {
// nav: {
// newInvoice: 'Hakuna Matata'
// }
// }
// }
// },
resGetPath:'../locales/{{lng}}/translation.json',
}, function (err, t) {
jqueryI18next.init(i18next, $, {
tName: 't', // --> appends $.t = i18next.t
i18nName: 'i18n', // --> appends $.i18n = i18next
handleName: 'localize', // --> appends $(selector).localize(opts);
selectorAttr: 'data-i18n', // selector for translating elements
targetAttr: 'i18n-target', // data-() attribute to grab target element to translate (if diffrent then itself)
optionsAttr: 'i18n-options', // data-() attribute that contains options, will load/set if useOptionsAttr = true
useOptionsAttr: false, // see optionsAttr
parseDefaultValueFromContent: true
});
$('#tempTarget').localize();
})
});
這是locales / en / translations.js:
{
"nav": {
"newInvoice": "somethaaaang"
}
}
這是我的目錄:
index.html
locales
en
translation.json
這是html中的行,該行已正確地與resources
對象相對,但沒有與reGetPath
屬性相對應:
<a href="/new-invoice/" data-i18n='nav.newInvoice' id='tempTarget' class="panel-close">New Invoice</a>
resGetPath
是來自1.xx的舊版本...現在看一下插件: https : resGetPath
在您的情況下https://github.com/i18next/i18next-xhr-backend ---> i18next.use(XHR)
您搜索的選項是backend.loadPath
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.