简体   繁体   English

内部化 Angular 10 @angular/localize,$localize 不起作用

[英]Internalization Angular 10 @angular/localize, $localize is not working

I upgraded from Angular 8 to 10th version, now implementing i18n with built in module @angular/localize , everything is great, except I can't translate source code, as per guides I have to use $localize function in order to translate code in 'controller', in guides saying that after I use this function it should show me a warning with ID , so I need to add it in translation file, but it's not showing.我从 Angular 8 升级到第 10 版,现在使用内置模块@angular/localize实现 i18n,一切都很好,除了我无法翻译源代码,根据指南,我必须使用$localize函数来翻译代码'controller',在指南中说,在我使用此功能后,它应该向我显示一个带有ID的警告,所以我需要将它添加到翻译文件中,但它没有显示。

Below is example I tried to add.下面是我尝试添加的示例。

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

I used several options, added custom ID, added to translation file manually information(info about line and file), but it's still not working.我使用了几个选项,添加了自定义 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> 

Does anyone know what can cause this problem, or maybe work around or alternatives ways, how I can add translation in code?有谁知道是什么导致了这个问题,或者可能解决或替代方法,我如何在代码中添加翻译?

If you simply use "ng build" you need to have proper angular.json configuration:如果你只是使用“ng build”,你需要有适当的 angular.json 配置:

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

and other settings from here: https://angular.io/guide/i18n#localize-config和这里的其他设置: https : //angular.io/guide/i18n#localize-config

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM