用于自定义属性的 Angular 4 i18n [英] Angular 4 i18n for custom attributes
问题描述
有没有办法使用 Angular i18n AOT 转换子组件中的自定义属性值?
Is there a way to translate custom attributes values in child-components using Angular i18n AOT?
我知道我们可以按如下方式翻译 HTML 元素属性.
I know we can translate HTML element attributes as below.
<input i18n-placeholder="search criteria date @@criteriaDate"
placeholder="Date"
formControlName="date" required>
但我想为我的组件属性做同样的事情.在这个例子中,我想传递标题属性翻译值.
But I want to do the same thing for my component attributes. In this example I want to pass title attribute translated value.
<custom-spinner
formControlName="nights"
[title]="'Nights'"
i18n-title="search criteria nights@@criteriaNights">
</custom-spinner>
当我尝试此操作时,它不会在 messages.xlf 文件中生成条目.我找不到任何关于此的示例.
When I try this, it doesn't generate an entry on messages.xlf file. I couldn't find any examples on this.
推荐答案
已在 Angular 7 中测试.默认情况下它有效.您不能对 i18n 文本使用 [title] 表示法.应该是纯文本.
Tested in Angular 7. It works by default. You can't use [title] notation for i18n texts. It should be plain text.
<custom-spinner
formControlName="nights"
title="Nights"
i18n-title="search criteria nights@@criteriaNights">
</custom-spinner>
请注意,它也适用于任何属性.例如,my-attr
和 i18n-my-attr
将翻译 my-attr
中的文本.
Note it will also work for any attributes. For example, my-attr
and i18n-my-attr
will translate the text inside my-attr
.
这篇关于用于自定义属性的 Angular 4 i18n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!