gpt4 book ai didi

backbone.js - i18next 未加载翻译文件

转载 作者:行者123 更新时间:2023-12-04 00:58:40 27 4
gpt4 key购买 nike

我正在开发一些基于 Backbone 的项目,在该项目中我将 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;

});

当我通过 localhost 加载我的页面时,它会在控制台中显示以下消息:
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

不明白我错过了什么?或者为什么会显示这个错误?

最佳答案

您将翻译文件存储在哪个文件夹中? i18n 的默认行为是,它尝试在特定路径中查找本地化文件:/locales/{lang-code}/{namespace}.json

如果您将文件保存在 root 中,请尝试将初始化代码更改为以下内容:

    i18n.init({
lang: 'en',
debug: true,
fallbackLng: false,
load:'unspecific',
resGetPath: "__ns__-__lng__.json",
ns: {
namespaces: ['translation'],
defaultNs: 'translation'
}
});

这将尝试从以下网址加载文件: http://localhost:8000/translation-en.json
基本上,尝试检查翻译文件的位置,翻译文件的名称并相应地构建'regGenPath',更多信息可以在i18n文档 http://i18next.com/node/pages/doc_init.html中找到。

关于backbone.js - i18next 未加载翻译文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17787326/

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