这是我第一次使用i18next,我不知道如何让它工作。 (似乎documentation对我来说不完整) 这是我的i18next HTML代码
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/4.0.0/i18next.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-i18next/1.1.0/jquery-i18next.min.js"></script>
<script src="/i18nextXHRBackend.min.js"></script>
</head>
<body>
<div id="test">
<a data-i18n="Hello"></a>
<div data-i18n="World"></div>
</div>
<script>
i18next
.init({
"debug": true,
"lng": "en",
"ns": [
"translation"
],
"fallbackLng": false,
"keySeparator": false,
"nsSeparator": false,
resources: {
"backend": {
"loadPath": "locales/{{lng}}/{{ns}}.json"
}
}
}, function(err, t) {
jqueryI18next.init(i18next, $);
$('#test').localize();
});
</script>
</body>
</html>
这是我的JSON:
{&#34;您好&#34; :&#34;您好英文&#34;,&#34; World&#34; :&#34;英语世界&#34; }
我的页面中没有显示任何内容,在控制台中我有这个
i18next::translator: missingKey en translation Hello
i18next::translator: missingKey en translation World
我错过了什么吗?
答案 0 :(得分:1)
如果你错过了,那么你的json文件中的翻译标志根本没有加载。
应该有关于后端无法加载控制台的警告。
确保:locales/en/translation.json
可访问 - 或相应修复路径