这是我第一次使用 i18next,我不知道如何让它发挥作用。 (这似乎是文档 http://i18next.com/docs/对我来说是不完整的)
这是我使用 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:
{ "Hello" : "英语你好", "World" : "英语世界" }
我的页面中没有显示任何内容,在控制台中我得到了这个
i18next::translator: missingKey en translation Hello
i18next::translator: missingKey en translation World
我错过了什么吗?
如果您丢失了,则表明您的 json 文件中的翻译根本未加载。
应该有关于后端无法加载控制台中的警告。
确保:locales/en/translation.json
可以访问 - 或相应地修复路径
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)