10
我正在開發一些基於Backbone的項目,其中我使用i18next作爲語言環境。i18next未加載翻譯文件
以下是我app.js代碼:
/*
This file is used to initialize your application.
*/
require(['i18n','application','handlebars_Helpers'], function(i18n, Application) {
i18n.init({
lng: 'en',
debug: true,
fallbackLng: false,
load:'unspecific',
resGetPath: "locales/__lng__/__ns__.json",
ns: {
namespaces: ['translation']
}
});
(new Application()).initialize();
});
翻譯文件:
{
"loginModule": {
"signin": "Sign In"
}
}
以下是我的幫助文件:
/**
* Set of generic handlebars helpers
*/
define(['i18n'], function(i18n) {
/**
* This helper provides i18Next in templates
*
*
* Usage: span {{t "my.key" }}
*/
Handlebars.registerHelper('t', function(i18n_key) {
var result = i18n.t(i18n_key);
return new Handlebars.SafeString(result);
});
return Handlebars;
});
當我加載通過本地主機我的網頁它在控制檯中顯示以下消息:
currentLng set to: en i18n.js:490
GET http://localhost:8000/locales/en/translation.json?_=1374495189376 404 (Not Found) i18n.js:376
failed loading: locales/en/translation.json
不明白我在想什麼?或爲什麼這個錯誤是顯示?
當我從螢火蟲複製網址並將其粘貼到瀏覽器的地址欄時,它向我展示了404;我刪除了「?_ = 1374495189376」它正確顯示了我的文件。爲什麼這個額外的數字正在增加? –
我加了resGetPath。但仍然不起作用 –
好的,「?_ = 1374495189376」是jQuery添加的,用於防止緩存問題。它只是一些隨機數,並且它會強制瀏覽器下載文件,即使它之前位於瀏覽器緩存中。你將不得不檢查應用程序的服務器端。如果有一些查詢字符串被傳遞,必須有一些防止靜態文件下載的設置。 – drax