简体   繁体   English

i18n $localize 在 angular ts 文件中

[英]i18n $localize in angular ts file

Good morning,早上好,

I'm using Angular 10 and i18n package to translate my app.我正在使用 Angular 10 和 i18n package 来翻译我的应用程序。 I have already made all the localization for the template files and is working perfectly on the prod server.我已经对模板文件进行了所有本地化,并且在 prod 服务器上运行良好。

The problem is that I'm trying to localize as well strings on the ts file but I am not able to achieve this...问题是我正在尝试本地化 ts 文件上的字符串,但我无法实现这一点......

What I have now is this on my ts file:我现在拥有的是我的 ts 文件中的这个:

$localize`@@errorMessage:Error`;
$localize`@@startDate:The end date can not be before the start date`;

The problem is how can I include thisin the xlf file to translate it?问题是如何在 xlf 文件中包含这个来翻译它? I have seen that you can include manually into the xlf file and then you can translate it, but doesn't work我已经看到您可以手动将其包含到 xlf 文件中,然后您可以翻译它,但不起作用

Thanks!谢谢!

You forgot a : before @@ .你忘了一个:@@之前。 It should be:它应该是:

$localize`:@@errorMessage:Error`

For the xlf file, it would be something like that:对于xlf文件,它会是这样的:

      <trans-unit id="errorMessage" datatype="html">
        <source>Error</source>
        <target>Erreur</target>
      </trans-unit>

Angular should support this by simply using ng extract-i18n . Angular 应该通过简单地使用ng extract-i18n来支持这一点。 This will scan all files and generate an xlf-file that includes all translatable items, including those from your code.这将扫描所有文件并生成一个 xlf 文件,其中包含所有可翻译项目,包括来自您的代码的项目。

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

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