如何使用mustache.js制作客户端I18n [英] How to make client side I18n with mustache.js
问题描述
我有一些静态html文件,并希望通过mustache.js进行客户端修改来更改内部的静态文本.
i have some static html files and want to change the static text inside with client side modification through mustache.js.
似乎这可能是Twitter在github上的髭须扩展名: https://github.com/bcherry/mustache.js
it seems that this was possible Twitter's mustache extension on github: https://github.com/bcherry/mustache.js
但是最近已删除或更改了特定的I18n扩展名.
But lately the specific I18n extension has been removed or changed.
我想像一个解决方案,其中http:/server/static.html?lang=en
加载mustache.js
和基于lang参数data_en.json
的语言JSON文件.
I imagine a solution where http:/server/static.html?lang=en
loads mustache.js
and a language JSON file based on the lang param data_en.json
.
然后,小胡子用发送的数据替换{{tags}}
.
Then mustache replaces the {{tags}}
with the data sent.
有人可以给我举个例子吗?
Can someone give me an example how to do this?
推荐答案
您可以将lambda与诸如i18next之类的某些库一起使用.
You can use lambdas along with some library like i18next or something else.
{{#i18n}}greeting{{/i18n}} {{name}}
传递的数据:
{
name: 'Mike',
i18n: function() {
return function(text, render) {
return render(i18n.t(text));
};
}
}
这为我解决了问题
这篇关于如何使用mustache.js制作客户端I18n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!