这是我第一次使用 i18next,我不知道如何让它发挥作用。(对我来说文档似乎不完整)这是我使用 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>
Run Code Online (Sandbox Code Playgroud)
这是我的 JSON:
{ "Hello" : "英语你好", "World" : "英语世界" }
我的页面中没有显示任何内容,在控制台中我得到了这个
i18next::translator: missingKey en translation Hello …Run Code Online (Sandbox Code Playgroud) i18next ×1