-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Description
Command
extract-i18n
Description
ng extract-i18n
only considers the description of the first occurrence of a duplicated message.
The relevant code part I found is this, which tells me, that for description the first element of the duplicatedMessages array is used, whichever it may be.
angular/packages/localize/tools/src/extract/translation_files/xliff1_translation_serializer.ts
Lines 54 to 80 in 8e1946e
for (const duplicateMessages of messageGroups) { | |
const message = duplicateMessages[0]; | |
const id = this.getMessageId(message); | |
xml.startTag('trans-unit', {id, datatype: 'html'}); | |
xml.startTag('source', {}, {preserveWhitespace: true}); | |
this.serializeMessage(xml, message); | |
xml.endTag('source', {preserveWhitespace: false}); | |
// Write all the locations | |
for (const {location} of duplicateMessages.filter(hasLocation)) { | |
this.serializeLocation(xml, location); | |
} | |
if (message.description) { | |
this.serializeNote(xml, 'description', message.description); | |
} | |
if (message.meaning) { | |
this.serializeNote(xml, 'meaning', message.meaning); | |
} | |
xml.endTag('trans-unit'); | |
} | |
xml.endTag('body'); | |
xml.endTag('file'); | |
xml.endTag('xliff'); | |
return xml.toString(); | |
} |
E.g.: there are three different components that use the same text to display a label "Owner" that should be localised.
detail.component.html
...
<ng-container id="ownerLabel" i18n="Owner label in detail form">Owner</ng-container>
...
search.component.html
...
<ng-container id="ownerLabel" i18n="Owner label in search filter">Owner</ng-container>
...
search-result-table.component.ts
...
displayText: $localize`:Owner table column header in search result table:Owner`,
...
For this following trans-unit
is generated
<trans-unit id="3016960930275947563" datatype="html">
<source>Owner</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/detail/detail.component.html</context>
<context context-type="linenumber">81</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/search/search.component.html</context>
<context context-type="linenumber">54</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/detail/search-result-table.component.ts</context>
<context context-type="linenumber">111</context>
</context-group>
<note priority="1" from="description">Owner label in detail form</note>
</trans-unit>
Describe the solution you'd like
Motivation:
We have a use-case where we send UI texts to be translated to some tech-savvy business colleagues who know the application and needs to translate missing texts. To those users the different descriptions matter, since it is a clear overview which parts of the application are meant and sometimes certain labels in different positions need to have different translations. In our communication to be able to identify which label we are talking about this description would be really helpful.
Proposed solution:
Add an extra parameter to ng extract-18n
that would also generate the <context context-type="description">
tags for duplicated messages.
According to http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#context
I do not see any problem with adding one more XML tag to the <context-group purpose="location">
s, e.g.
<trans-unit id="3016960930275947563" datatype="html">
<source>Owner</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/detail/detail.component.html</context>
<context context-type="linenumber">81</context>
<context context-type="description">Owner label in detail form</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/search/search.component.html</context>
<context context-type="linenumber">54</context>
<context context-type="description">Owner label in search filter</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/detail/search-result-table.component.ts</context>
<context context-type="linenumber">111</context>
<context context-type="description">Owner table column header in search result table</context>
</context-group>
<note priority="1" from="description">Owner label in detail form</note>
</trans-unit>
Describe alternatives you've considered
No response