【问题标题】:Is there a way to declaratively translate interpolations in templates?有没有办法以声明方式翻译模板中的插值?
【发布时间】:2019-03-12 15:16:43
【问题描述】:

我有这个:

    <div class="container">

      <h2 i18n="@@prioritizedWordsToLearn">Prioritized Words To Learn</h2>
      <table class="table table-striped">
        <thead>
          <tr>
...
            <th i18n="@@previouslyMarkedLearnedColumn">Previously Marked Learned</th>
...
          </tr>
        </thead>
        <tbody>
          <tr *ngFor="let word of model">
...
            <td>{{word.wasMarkedLearned}}</td>
...
          </tr>
        </tbody>
      </table>
    </div>

wasMarkedLearned 是一个布尔值。应用程序中的所有其他字符串都经过 i18n 处理,并且应用程序在通过 AOT 运行时可以正常工作(见屏幕截图)。

但是,布尔值最终显示为“真”或“假”。

我可以在生成表格之前检查语言环境和硬编码翻译,但这似乎是一种反模式。

理想情况下会有这样的支持:

{{word.wasMarkedLearned |字符串 |翻译}}

“翻译”从开发者提供的地图中读取。

不过我没有看到类似的东西。

【问题讨论】:

    标签: angular internationalization


    【解决方案1】:

    我需要安装@ngx-translate。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-20
      • 1970-01-01
      • 1970-01-01
      • 2019-07-30
      • 1970-01-01
      • 1970-01-01
      • 2011-10-12
      • 2010-12-22
      相关资源
      最近更新 更多