【发布时间】:2014-05-02 20:56:26
【问题描述】:
我终于让我的 PhoneGap / Backbone / Handlebars 使用 i18next.js 进行本地化——有点。
我目前想知道如何获取带有嵌入式车把表达式的 html 以同时本地化 和 用 Handlebars 编译。例如,我想要这样的东西:
Welcome, {{this.name}}. We've been expecting you.
变成:
Welcome, Bob. We've been expecting you.
无需本地化,这很容易。但是运行文档中描述的 i18next 模板(此处:http://i18next.com/pages/doc_templates.html)...
// handlebars helper from i18next
Handlebars.registerHelper('t', function(i18n_key) {
var result = i18n.t(i18n_key);
return new Handlebars.SafeString(result);
});
//Handlebars string:
{{t 'view.WelcomeMessage'}}
// translation.json file
{ "view":
{
"WelcomeMessage": "Welcome, {{this.name}}. We've been expecting you."
}
}
不幸的是,本地化后会变成以下内容:
Welcome, {{this.name}}. We've been expecting you.
如何使字符串本地化并编译嵌入式表达式?
【问题讨论】:
标签: handlebars.js i18next