99 * [Angular and i18n template translation](#angular-i18n)
1010 * [Mark text with the _i18n_ attribute](#i18n-attribute)
1111 * [Add _i18n-..._ translation attributes](#translate-attributes)
12+ * [Set translation ids explicitly](#explicit-id)
1213 * [Handle singular and plural](#cardinality)
1314 * [Select among alternative texts](#select)
1415 * [Create a translation source file with the **_ng-xi18n_ extraction tool**](#ng-xi18n)
@@ -81,7 +82,7 @@ a#i18n-attribute
8182+ makeExample('cb-i18n/ts/app/app.component.1.html' , 'i18n-attribute' , 'app/app.component.html' )( format ="." )
8283
8384:marked
84- ### Help the translator with a _description_ and _intent_
85+ ### Help the translator with a _description_ and _meaning_
8586
8687 In order to translate it accurately, the translator may
8788 need a description of the message.
@@ -91,19 +92,42 @@ a#i18n-attribute
9192
9293:marked
9394 In order to deliver a correct translation, the translator may need to
94- know your _intent_— the true _meaning_ of the text
95- within _this particular_ application context.
96- In front of the description, add some contextual meaning to the assigned string,
97- separating it from the description with the `|` character (`<meaning>|<description>`):
95+ know the _meaning_ or _intent_ of the text within _this particular_ application context.
96+
97+ You add context by beginning the string with the _meaning_ and
98+ separating it from the _description_ with the `|` character (`<meaning>|<description>`):
9899
99- + makeExample('cb-i18n/ts/app/app.component.html' , 'i18n-attribute-meaning' , 'app/app.component.html' )( format ="." )
100+ + makeExample('cb-i18n/ts/app/app.component.1. html' , 'i18n-attribute-meaning' , 'app/app.component.html' )( format ="." )
100101
101102:marked
102103 While all appearances of a message with the _same_ meaning have the _same_ translation,
103104 a message with *a variety of possible meanings* could have different translations.
104105 The Angular extraction tool preserves both the _meaning_ and the _description_ in the translation source file
105106 to facilitiate contextually-specific translations.
106107
108+ a#explicit-id
109+ :marked
110+ ### Consider setting a custom _id_ explicitly to improve search and maintenance
111+
112+ By default, the angular _i18n_ extractor tool generates a unique ID for each `i18n` attribute in a template.
113+ This _id_ is ugly, arbitrary, and unfit for humans.
114+
115+ Worse, when you change the translatable text, perhaps to fix a typo,
116+ the extractor tool generates a new _id_ for that translation.
117+ The new _id_ most likely breaks the application and it certainly [complicates maintenance](a#maintenance).
118+
119+ Consider specifying your own, meaninful _id_ in the `i18n` attribute, **prefixed with `@@`**.
120+ + makeExample('cb-i18n/ts/app/app.component.1.html' , 'i18n-attribute-solo-id' , 'app/app.component.html' )( format ="." )
121+ :marked
122+ The extractor tool and compiler will use your _id_ and never change it.
123+ Here is the attribute with a _definition_, followed by the explicit `id`:
124+ + makeExample('cb-i18n/ts/app/app.component.1.html' , 'i18n-attribute-id' , 'app/app.component.html' )( format ="." )
125+
126+ :marked
127+ Here is a _meaning_ and a _description_ and the _id_ at the end:
128+ + makeExample('cb-i18n/ts/app/app.component.1.html' , 'i18n-attribute-meaning-and-id' , 'app/app.component.html' )( format ="." )
129+
130+ :marked
107131 ### Translate text without creating an element
108132
109133 Suppose there is a stretch of text that you'd like to translate.
@@ -329,18 +353,20 @@ a#localization-folder
329353 replace the `<target/>` tag with the Spanish greeting:
330354+ makeExample('cb-i18n/ts/locale/messages.es.xlf.html' , 'translated-hello' , 'locale/messages.es.xlf (<trans-unit>, after translation)' )( format ="." )
331355
332- .alert.is-important
333- :marked
334- Note that the tool generates the `id`. **Don't touch it.**
335- Its value depends on the content of the message and its assigned meaning.
336- Change either factor and the `id` changes as well.
337- See the **[translation file maintenance discussion](#maintenance)**.
338-
339356:marked
340357 Translate the other text nodes the same way:
341358
342359+ makeExample('cb-i18n/ts/locale/messages.es.xlf.html' , 'translated-other-nodes' , 'locale/messages.es.xlf (<trans-unit>)' )( format ="." )
343360
361+ .callout.is-critical
362+ header.
363+ Beware of generated ids
364+ :marked
365+ **The tool generated the `id`s for these translation units. Don't touch them.**
366+ Each `id` depend upon the content of the message and its assigned meaning.
367+ Change either factor and the `id` changes as well.
368+ See the **[translation file maintenance discussion](#maintenance)**.
369+
344370a#translate-plural-select
345371:marked
346372 ## Translate _plural_ and _select_
@@ -561,16 +587,21 @@ a#maintenance
561587
562588 As the application evolves, you will change the _i18n_ markup
563589 and re-run the `ng-xi18n` extraction tool many times.
564- The _new_ markup that you add is not a problem;
565- but _most_ changes to _existing_ markup trigger
566- generation of _new_ `id`s for the affected translation units.
590+ The _new_ markup that you add is not a problem.
591+ But the `id` _can be a serious problem!_
592+
593+ If the `id` is generated by the tool, _most_ changes to _existing_ markup
594+ cause the tool to generate a _new_ `id` for the affected translation unit.
567595
568596 After an `id` changes, the translation files are no longer in-sync.
569597 **All translated versions of the application will fail** during re-compilation.
570598 The error messages identify the old `id`s that are no longer valid but
571599 they don't tell you what the new `id`s should be.
600+
601+ You can avoid this problem by supplying your own [custom id explicitly](#explicit-id "Set a custom id explicitly").
602+ The tooling preserves your `id` as you make changes to the corresponding translation unit.
572603
573- **Commit all translation message files to source control**,
604+ Whether you use generated or explicit `ids`, **always commit all translation message files to source control**,
574605 especially the English source `messages.xlf`.
575606 The difference between the old and the new `messages.xlf` file
576- help you find and update `id` changes across your translation files.
607+ help you find and update `id` and other changes across your translation files.
0 commit comments