【问题标题】:angular-i18n select syntax in attributeangular-i18n 在属性中选择语法
【发布时间】:2018-02-01 15:39:56
【问题描述】:

我试图使用 i18n SELECT 语法来翻译输入字段的占位符:

<input placeholder="{userRole, admin{you are an admin} other {you are a user}}" i18n-placeholder="MYAPP.PLACEHOLDER|my placeholder">

这将导致以下 xlf 文件条目:

<trans-unit id="85f60a0a03b3b4e189252fc0157dd403e806bbcc" datatype="html">
    <source>{userRole, admin{you are an admin} other {you are a user}}</source>
    <context-group purpose="location">
      <context context-type="sourcefile">path/to/my/file.component.ts</context>
      <context context-type="linenumber">4</context>
    </context-group>
    <note priority="1" from="description">my placeholder</note>
    <note priority="1" from="meaning">MYAPP.PLACEHOLDER</note>
  </trans-unit>

因此,SELECT 语法似乎无法识别。当我使用语法不是翻译属性而是元素的内容时,.xlf 标签看起来像这样:

<source>{VAR_SELECT, admin{you are an admin} other {you are a user}}</source>

【问题讨论】:

    标签: javascript angular internationalization angular-i18n


    【解决方案1】:

    这似乎是 Angular 的一个众所周知的问题

    允许属性中的 ICU 消息 [已阻止,需要更新 pars

    https://github.com/angular/angular/issues/16477

    解决方法是使用不同的标签来实现翻译:

    <span i18n='SOME_TITLE|Description Text' #translatedPlaceholder>{VAR_SELECT, admin{you are an admin} other {you are a user}}</span>    
    <input [placeholder]="translatedPlaceholder.textContent" />
    

    【讨论】:

      猜你喜欢
      • 2019-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 2018-03-01
      相关资源
      最近更新 更多