简体   繁体   English

Angular:如何从 i18n 属性和 $localize function 生成一个跨单元?

[英]Angular: How to generate one trans-unit from i18n attribute and $localize function?

Code in component:组件中的代码:

title = $localize`Monday`;

Code in template:模板中的代码:

<div i18n>Monday</div>

"ng extract-i18n" command extract two separate trans-units to messages.xlf. “ng extract-i18n”命令将两个独立的反式单元提取到messages.xlf。

Yes, because you have two separate translations: title in the ts-file and the <div> in the template.是的,因为您有两个单独的翻译:ts 文件中的title和模板中的<div> If you wish to use title you can use in the template with interpolation with the i18n attribute.如果您想使用title ,您可以在模板中使用带有i18n属性的插值。 If you use the i18n attribute it's translated to another $localize in the compilation process before the translations happen:如果您使用i18n属性,它会在翻译发生之前在编译过程中翻译成另一个$localize

<div>{{title}}</div>

The other option is to omit the title and only use i18n in the template, which I find easier.另一种选择是省略title ,只在模板中使用i18n ,我觉得这更容易。

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

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