i18next を開始したばかりで、プロジェクトの各モジュールの翻訳ファイルを作成したいと考えています。これを行うには、名前空間を使用するのが正しい方法のようです。このプロジェクトでは、複数のビューを使用してページ レイアウトを作成できるため、複数の名前空間から文字列を同時に翻訳できる必要があります。
2 つの名前空間を持つ単純な例を作成しましたが、i18next を取得して 1 つの名前空間の文字列を変換することしかできません。使用するdefaultNs: namespaces[0]
と、数字が翻訳されdefaultNs: namespaces[1]
、色が翻訳され、defaultNs: namespaces
何も翻訳されません。しかし、両方の名前空間を翻訳する方法がわかりません。
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="i18next.js"></script>
<script>
$(document).ready(function(){
var language = "en";
var namespaces = [ "numbers", "colors" ];
var config = {
lng: language,
fallbackLng: "en",
resGetPath: "namespaces/__ns__/__ns__-__lng__.json",
ns: {
namespaces: namespaces,
defaultNs: namespaces[0]
},
debug: true
};
i18n.init( config, function onInitComplete() {
$(".xl8").i18n();
});
});
</script>
</head>
<body>
<h1>hello, i18n!</h1>
<ol>
<li class="xl8" data-i18n="numbers.one">1</li>
<li class="xl8" data-i18n="numbers.two">2</li>
<li class="xl8" data-i18n="numbers.three">3</li>
</ol>
<ul>
<li class="xl8" data-i18n="colors.red">r</li>
<li class="xl8" data-i18n="colors.green">g</li>
<li class="xl8" data-i18n="colors.blue">b</li>
</ul>
</body>
</html>