9
9
* [Angular and i18n template translation](#angular-i18n)
10
10
* [Mark text with the _i18n_ attribute](#i18n-attribute)
11
11
* [Add _i18n-..._ translation attributes](#translate-attributes)
12
+ * [Set translation ids explicitly](#explicit-id)
12
13
* [Handle singular and plural](#cardinality)
13
14
* [Select among alternative texts](#select)
14
15
* [Create a translation source file with the **_ng-xi18n_ extraction tool**](#ng-xi18n)
@@ -81,7 +82,7 @@ a#i18n-attribute
81
82
+ makeExample('cb-i18n/ts/app/app.component.1.html' , 'i18n-attribute' , 'app/app.component.html' )( format ="." )
82
83
83
84
:marked
84
- ### Help the translator with a _description_ and _intent_
85
+ ### Help the translator with a _description_ and _meaning_
85
86
86
87
In order to translate it accurately, the translator may
87
88
need a description of the message.
@@ -91,19 +92,42 @@ a#i18n-attribute
91
92
92
93
:marked
93
94
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>`):
98
99
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 ="." )
100
101
101
102
:marked
102
103
While all appearances of a message with the _same_ meaning have the _same_ translation,
103
104
a message with *a variety of possible meanings* could have different translations.
104
105
The Angular extraction tool preserves both the _meaning_ and the _description_ in the translation source file
105
106
to facilitiate contextually-specific translations.
106
107
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
107
131
### Translate text without creating an element
108
132
109
133
Suppose there is a stretch of text that you'd like to translate.
@@ -329,18 +353,20 @@ a#localization-folder
329
353
replace the `<target/>` tag with the Spanish greeting:
330
354
+ makeExample('cb-i18n/ts/locale/messages.es.xlf.html' , 'translated-hello' , 'locale/messages.es.xlf (<trans-unit>, after translation)' )( format ="." )
331
355
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
-
339
356
:marked
340
357
Translate the other text nodes the same way:
341
358
342
359
+ makeExample('cb-i18n/ts/locale/messages.es.xlf.html' , 'translated-other-nodes' , 'locale/messages.es.xlf (<trans-unit>)' )( format ="." )
343
360
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
+
344
370
a#translate-plural-select
345
371
:marked
346
372
## Translate _plural_ and _select_
@@ -561,16 +587,21 @@ a#maintenance
561
587
562
588
As the application evolves, you will change the _i18n_ markup
563
589
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.
567
595
568
596
After an `id` changes, the translation files are no longer in-sync.
569
597
**All translated versions of the application will fail** during re-compilation.
570
598
The error messages identify the old `id`s that are no longer valid but
571
599
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.
572
603
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**,
574
605
especially the English source `messages.xlf`.
575
606
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