Localization 将{select}格式(format.js)与应用程序本地化行为一起使用

Localization 将{select}格式(format.js)与应用程序本地化行为一起使用,localization,polymer,polymer-1.0,messageformat.js,Localization,Polymer,Polymer 1.0,Messageformat.js,我正在用Polymers应用程序本地化行为做一些试验,我很难找到一些关于如何使用format.js的{select}格式的清晰文档 应用程序本地化行为表明: “Polymer.AppLocalizeBehavior整体上支持format.js的相同消息语法;” 但例如,在聚合文档中,它们将参数作为字符串传递: {{localize('hello', 'Batman')}} 在format.js文档中,不包括: I have {numCats, number} cats. 现在我面临的问题

我正在用Polymers应用程序本地化行为做一些试验,我很难找到一些关于如何使用format.js的{select}格式的清晰文档

应用程序本地化行为表明:
“Polymer.AppLocalizeBehavior整体上支持format.js的相同消息语法;”
但例如,在聚合文档中,它们将参数作为字符串传递:

{{localize('hello', 'Batman')}}
在format.js文档中,不包括:

I have {numCats, number} cats.
现在我面临的问题是如何使用{select}格式

format.js这样使用它:

{gender, select,
male {He}
female {She}
other {They}
} will respond shortly.
所以我在我的模板中这样做:

{{localize(wir, select,
            wir {we}
            ich {i}
           )
}}
locales.json:

{
"en" : {
         "i" : "I",
         "we" : "we"        
       },
"fr" : { 

         "i" : "je",
         "we" : "nous"
       },
"de" : {
         "i" : "ich",
         "we" : "wir"
       }
}
默认情况下,该语言设置为法语
“fr”
,因此我希望得到“nous”作为输出,但屏幕上会显示完整的
{{localize(etc..}}}

上一次,我尝试将所有内容作为字符串或一些参数(所有组合)传递,但这一切都没有帮助

有没有人遇到过同样的问题,或者有人能解释一下我做错了什么


非常感谢您的帮助。

本地化
使用

  • 如果
    localize
    的参数是字符串文字,则必须引用这些参数,如下所示:

    {{localize('hello', 'Batman')}}
    
    否则,它们将被视为属性。例如,如果您有一个
    名称
    属性包含
    蝙蝠侠
    ,您将使用:

    {{localize('hello', name)}}
    
  • 第一个
    localize
    参数是语言词典中的一个键(在元素的
    resources
    属性中定义,或者在元素加载的外部文件中定义,例如
    locales.json

  • 第一个参数之后的所有
    本地化
    参数都直接传递给

此字符串:

{gender, select,
male {He}
female {She}
other {They}
} will respond shortly.
…是一种消息格式,必须在语言词典中定义为值。此示例显示了
资源
属性中定义的字典,其键为
响应

Polymer({
  ...
  properties: {
    resources: {
      value: function() {
        return {
          'en': { 'response': `{gender, select,
                                male {He}
                                female {She}
                                } will respond shortly.` },
          'fr': { 'response': `{gender, select,
                                male {Il}
                                female {Elle}
                                } répondra prochainement.` }
        }
      }
    }
  }
});
然后,在元素的模板中,您将使用
本地化
,如下所示:

<div>Message: {{localize('response', 'gender', 'female')}}</div>

本地化
使用

  • 如果
    localize
    的参数是字符串文字,则必须引用这些参数,如下所示:

    {{localize('hello', 'Batman')}}
    
    否则,它们将被视为属性。例如,如果您有一个
    名称
    属性包含
    蝙蝠侠
    ,您将使用:

    {{localize('hello', name)}}
    
  • 第一个
    localize
    参数是语言词典中的一个键(在元素的
    resources
    属性中定义,或者在元素加载的外部文件中定义,例如
    locales.json

  • 第一个参数之后的所有
    本地化
    参数都直接传递给

此字符串:

{gender, select,
male {He}
female {She}
other {They}
} will respond shortly.
…是一种消息格式,必须在语言词典中定义为值。此示例显示了
资源
属性中定义的字典,其键为
响应

Polymer({
  ...
  properties: {
    resources: {
      value: function() {
        return {
          'en': { 'response': `{gender, select,
                                male {He}
                                female {She}
                                } will respond shortly.` },
          'fr': { 'response': `{gender, select,
                                male {Il}
                                female {Elle}
                                } répondra prochainement.` }
        }
      }
    }
  }
});
然后,在元素的模板中,您将使用
本地化
,如下所示:

<div>Message: {{localize('response', 'gender', 'female')}}</div>

代码段创建了一个HTMLImport错误。“然而,当我在本地测试它时,它确实起作用。代码段创建了一个HTMLImport错误。”然而,当我在本地测试它时,它确实起作用