ng extract-i18n配置以忽略重复消息



在Angular v10中,我们使用内置的i18n功能。现在,当我运行ngextract-i18n时,它会返回许多重复的消息警告。

举个简单的例子:

WARNINGS:
- Duplicate messages with id "lastName":
- "Last Name" : srcappcore...
- "Last Name" ...

然而,这是我有意为之。我正在尝试在整个应用程序中重用某些i18n ID。

即来自各种模板的一些HTML片段:

<label i18n="Label|Label for Last Name@@lastName">Last Name</label>
<mat-label i18n="Label|Label for Last Name@@lastName">Last Name</mat-label>
<mat-radio-button value="LastName" i18n="Button|Button for User Preferences@@lastName">
Last Name</mat-radio-button
>
<kendo-grid-column
i18n-title="Title|Title for Orders Grid@@firstName"
field="Student.FirstName"
title="First Name"
></kendo-grid-column>

换言之,文本标签如"姓氏";以及";名字">在我们的应用程序中重复了很多次,所以我为每个都有一个通用的i18n标记。

CLI随后在XLF输出文件中生成id属性:

<trans-unit id="lastName" datatype="html">
<source>Last Name</source>        
<context-group purpose="location">
<context context-type="sourcefile">src/app/core/modals/.../info-modal.html</context>
<context context-type="linenumber">33</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/.../student-list.component.html</context>
<context context-type="linenumber">26</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/.../another-list.component.html</context>
<context context-type="linenumber">101</context>
</context-group>        
</trans-unit>

这种做法有错吗?或者Angular CLI只是想提供帮助?

我也许可以忽略这些警告,但不清楚如何忽略。

我也在github上找到了一些信息,但不是很清楚。https://github.com/angular/angular-cli/issues/19207

我还发现了一条指向一些配置选项的评论:https://github.com/angular/angular/blob/79620f5139c80f1b3b38168744ca99a224c7e5cd/packages/localize/src/tools/src/extract/main.ts#L89-L95

您的方法是有效的。

问题(很可能(来自于空格/换行符的不一致使用:注意,在您的示例中,一个文本是nLast Name,另一个是Last Name

尽管在这种情况下可能没有什么不同,但保持具有相同id的文本相同是一个很好的做法,即使是在空白处也是如此。

最新更新