我正在尝试一个理解i18next
js的例子。这是代码:
<!DOCTYPE html>
<html>
<head>
<title>Internationalization example</title>
<script type="text/javascript" src="i18next.amd-1.10.1/i18next.amd-1.10.1.js"></script>
<!-- <script type="text/javascript" src="i18next.amd-1.10.1/i18next.amd.withJQuery-1.10.1.min.js"></script> -->
<meta charset="utf-8">
<script type="text/javascript">
$(document).ready(function(){
i18n.init(function(err, t) {
// translate nav
$(".nav").i18n();
// programatical access
var appName = t("app.name");
});
});
</script>
</head>
<body>
<ul class="nav">
<li><a href="#" data-i18n="nav.home"></a></li>
<li><a href="#" data-i18n="nav.page1"></a></li>
<li><a href="#" data-i18n="nav.page2"></a></li>
</ul>
<div>
<p>There are so many countries in the world, and hence many languages exist. So translating the website to each country's official language is important</p>
</div>
</body>
</html>
locales/en/translation.json:
{
"app": {
"name": "i18next"
},
"nav": {
"home": "Home",
"page1": "Page One",
"page2": "Page Two"
}
}
但是我在浏览器上没有任何帮助。我没有使用npm来安装i18next js。我只是直接使用它,如html
代码所示。我怎样才能使它工作?