【问题标题】:Internalization Angular 10 @angular/localize, $localize is not working内部化 Angular 10 @angular/localize,$localize 不起作用
【发布时间】:2020-08-27 08:49:47
【问题描述】:

我从 Angular 8 升级到第 10 版,现在使用内置模块 @angular/localize 实现 i18n,一切都很好,除了我无法翻译源代码,根据指南我必须使用 $localize 函数才能翻译“控制器”中的代码,在指南中说,在我使用此功能后,它应该向我显示ID 的警告,因此我需要将其添加到翻译文件中,但它没有显示。

以下是我尝试添加的示例。

test = $localize`:meaning|description@@introductionHeader:text`;

我使用了几个选项,添加了自定义 ID,手动添加到翻译文件信息(有关行和文件的信息),但仍然无法正常工作。

<trans-unit id="introductionHeader" datatype="html">
    <source>text</source>
    <target>Translation here</target>
    <context-group purpose="location">
        <context context-type="sourcefile">*******.ts</context>
        <context context-type="linenumber">31</context>
    </context-group>
</trans-unit> 

有谁知道什么会导致这个问题,或者可以解决或替代方法,我如何在代码中添加翻译?

【问题讨论】:

  • 你的问题不是很清楚。什么不显示?您能否在使用该属性的地方添加 HTML 部分:test?您是否将其用作interpolation

标签: angular internationalization


【解决方案1】:

如果你只是使用“ng build”,你需要有正确的 angular.json 配置:

"architect": {
        "build": {
          "options": {
            "localize": true,
            "aot": true,
        }
}

和其他设置来自这里:https://angular.io/guide/i18n#localize-config

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-27
    • 2021-05-01
    • 2020-06-10
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    相关资源
    最近更新 更多