Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

docs(compiler): add doc + examples for i18n explicit ID option #2941

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions public/docs/_examples/cb-i18n/ts/app/app.component.1.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ <h1 i18n>Hello i18n!</h1>
<h1 i18n="An introduction header for this sample">Hello i18n!</h1>
<!--#enddocregion i18n-attribute-desc-->

<!--#docregion i18n-attribute-id-->
<h1 i18n="An introduction header for this sample@@introductionHeader">Hello i18n!</h1>
<!--#enddocregion i18n-attribute-id-->

<!--#docregion i18n-attribute-meaning-and-id-->
<h1 i18n="site header|An introduction header for this sample@@introductionHeader">Hello i18n!</h1>
<!--#enddocregion i18n-attribute-meaning-and-id-->

<!--#docregion i18n-attribute-solo-id-->
<h1 i18n="@@introductionHeader">Hello i18n!</h1>
<!--#enddocregion i18n-attribute-solo-id-->

<!--#docregion i18n-title-->
<img [src]="logo" title="Angular 2 logo">
<!--#enddocregion i18n-title-->
17 changes: 17 additions & 0 deletions public/docs/ts/latest/cookbook/i18n.jade
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ a#i18n-attribute

+makeExample('cb-i18n/ts/app/app.component.html', 'i18n-attribute-meaning', 'app/app.component.html')(format=".")

:marked
### Strengthen translation messages consistancy with an explicit _id_

By default the angular _i18n_ extractor tool generates a unique ID for each `i18n` attributes in templates.
If you fix a typo in a translatable block of your template, the extractor tool will generate another new _id_ for your translation.
To avoid this behavior, you can specify an explicit _id_ in the `i18n` attribute that will be used by the extractor tool and compiler.
To specify an _id_, just prefix it with `@@` in the i18n attribute:

+makeExample('cb-i18n/ts/app/app.component.1.html', 'i18n-attribute-id', 'app/app.component.html')(format=".")
:marked
With a _meaning_ and a _description_ :

+makeExample('cb-i18n/ts/app/app.component.1.html', 'i18n-attribute-meaning-and-id', 'app/app.component.html')(format=".")
:marked
Moreover, you can just specify an _id_ in the `i18n` attribute :
+makeExample('cb-i18n/ts/app/app.component.1.html', 'i18n-attribute-solo-id', 'app/app.component.html')(format=".")

:marked
While all appearances of a message with the _same_ meaning have the _same_ translation,
a message with *different meanings* could have different translations.
Expand Down