我的回答是基于开发者的。他的回答非常好,我将在消息键码中添加使用小胡子标签的可能性。如果您希望能够根据当前的胡须状态或循环获取消息,则确实需要
它基于简单的双重渲染
info.i18n = function(){
return function(text, render){
var code = render(text); //Render first to get all variable name codes set
var value = i18n.t(code)
return render(value); //then render the messages
}
}
因此,表演不会因为胡须在非常小的字符串上操作而受到影响。
这里有一个小例子:
json数据:
array :
[
{ name : "banana"},
{ name : "cucomber" }
]
胡子模板:
{{#array}}
{{#i18n}}description_{{name}}{{/i18n}}
{{/array}}
留言
description_banana = "{{name}} is yellow"
description_cucomber = "{{name}} is green"
结果是:
banana is yellow
cucomber is green
复数
[编辑]:正如评论中所问的那样,下面是一个示例,其中包含英语和法语复数处理的伪代码。这是一个非常简单且未经测试的示例,但它给了你一个提示。
description_banana = "{{#plurable}}a {{name}} is{{/plurable}} green" (Adjectives not getting "s" in plurals)
description_banana = "{{#plurable}}Une {{name}} est verte{{/plurable}}" (Adjectives getting an "s" in plural, so englobing the adjective as well)
info.plurable = function()
{
//Check if needs plural
//Parse each word with a space separation
//Add an s at the end of each word except ones from a map of common exceptions such as "a"=>"/*nothing*/", "is"=>"are" and for french "est"=>"sont", "une" => "des"
//This map/function is specific to each language and should be expanded at need.
}