這個工作對我來說,還是用你通常會傳入構造相同的JSON:
tranlations.js
var Localize = require('localize');
var myLocalize = new Localize('./translations/');
console.log(myLocalize.translate("Testing...")); // Testing...
console.log(myLocalize.translate("Substitution: $[1]", 5)); // Substitution: 5
myLocalize.setLocale("es");
console.log(myLocalize.translate("Testing...")); // Pruebas...
myLocalize.setLocale("sr");
console.log(myLocalize.translate("Substitution: $[1]", 5)); // замена: 5
./translations/translations.json
{
"Testing...": {
"es": "Pruebas...",
"sr": "тестирање..."
},
"Substitution: $[1]": {
"es": "Sustitución: $[1]",
"sr": "замена: $[1]"
}
}
然後執行:
node translations.js
謝謝:) 你會推薦任何其他npm模塊爲我的用例 - 節點(只有JSON輸出,不發送玉文件)和角? – Nitin
@Nitin這似乎工作得很好,但我沒有測試其他人。 – ctlacko