11include ../_util-fns
22
33:marked
4- Angular's _internationalization_ ("_i18n_") tools help make your app availble in multiple languages.
4+ Angular's _internationalization_ ("_i18n_") tools help make your app available in multiple languages.
55
66 <a id="top"></a>
77 ## Table of contents
88
99 * [Angular and i18n template translation](#angular-i18n)
1010 * [Mark text with the _i18n_ attribute](#i18n-attribute)
11- * [Extract text with ng-xi18n ](#ng-xi18n)
11+ * [Create a translation source file with the _ng-xi18n_ tool ](#ng-xi18n)
1212 * [Translate](#translate)
13- * [Merge the translation file into the app](#merge)
13+ * [Merge the completed translation file into the app](#merge)
1414 * [JiT configuration](#jit)
1515 * [AoT configuration](#aot)
1616
@@ -30,6 +30,7 @@ a#angular-i18n
3030 This page describes the _i18n_ tools to assist translation of component template text
3131 into multiple languages.
3232
33+
3334.l-sub-section
3435 :marked
3536 Practitioners of _internationalization_ refer to a translatable text as a "_message_".
@@ -61,7 +62,9 @@ a#i18n-attribute
6162
6263.alert.is-helpful
6364 :marked
64- `i18n` is not an Angular _directive_. It's a custom _attribute_, recognized by Angular tools and compilers.
65+ `i18n` is not an Angular _directive_.
66+ It's a custom _attribute_, recognized by Angular tools and compilers.
67+ It will be removed by the compiler _after_ translation.
6568
6669:marked
6770 In the accompanying sample, an `<h1>` tag displays a simple English language greeting which you will translate to French:
@@ -87,16 +90,17 @@ a#i18n-attribute
8790 While all appearance of a message with the _same_ meaning should have the _same_ translation,
8891 a message with *different meanings* could have different translations.
8992 The Angular extraction tool preserves both the _meaning_ and the _description_ in the translation source file
90- to facilitiate contextually-specific transations .
93+ to facilitiate contextually-specific translations .
9194
9295a#ng-xi18n
9396.l-main-section
9497:marked
95- ## Extract translatable text with the _ng-xi18n_ command
98+ ## Create a translation source file with the _ng-xi18n_ tool
9699
97- Use the `ng-xi18n` extraction tool to generate a translation source file in an industry standard format.
100+ Use the `ng-xi18n` extraction tool to extract the `i18n`-marked texts
101+ into a translation source file in an industry standard format.
98102
99- This is an Angular CLI tool based on the `ngc` compiler in the `@angular/compiler-cli` npm package.
103+ This is an Angular CLI tool in the `@angular/compiler-cli` npm package.
100104 If you haven't already installed the CLI and its `platform-server` peer dependency, do so now:
101105
102106code-example( language ="sh" class ="code-shell" ) .
@@ -151,18 +155,26 @@ a#translate
151155 The next step is to translate the English language template text into the specific language translation
152156 files. The cookbook sample creates a French translation file.
153157
154- a#i18n-file-structure
158+ a#localization-folder
155159:marked
156- ### Create an i18n project structure
160+ ### Create a localization folder
157161
158162 You will probably translate into more than one other language so it's a good idea
159163 for the project structure to reflect your entire internationalization effort.
160164
161- One approach is to create an `i18n` folder with subfolders for each language or locale, e.g. `i18n/fr` for French.
162- This sample puts `i18n/fr` under the project root.
165+ One approach is to dedicate a folder to localization and store related assets
166+ (e.g. internationalization files) there.
167+ .l-sub-section
168+ :marked
169+ Localization and internationalization are
170+ <a href =" " target =" _blank" >different but closely related terms</a >.
171+ :marked
172+ This sample follows that suggestion. It has `locale` folder immediately under the project root.
173+ Assets within the folder carry a filename extension that matches a language-culture code from a
174+ <a href="https://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx" target="_blank">well-known codeset</a>.
163175
164- Move the `messages.xlf` into the `i18n ` folder where it will become the source for all language-specific translations.
165- Then copy `messages.xlf` into `i18n/fr` and rename it as `messages.fr.xlf` .
176+ Move `messages.xlf` into the `locale ` folder where it will become the source for all language-specific translations.
177+ Then make a copy for the French language named `messages.fr.xlf` .
166178
167179 Follow the same convention for each target language.
168180
@@ -174,17 +186,17 @@ a#i18n-file-structure
174186 This sample file is easy to translate without a special editor or knowledge of French.
175187 Open `messages.fr.xlf` and find the `<trans-unit>` section:
176188
177- + makeExample('cb-i18n/ts/i18n /trans-unit.html' , '' , 'i18n /messages.fr.xlf (<trans-unit>)' )( format ="." )
189+ + makeExample('cb-i18n/ts/locale /trans-unit.html' , '' , 'locale /messages.fr.xlf (<trans-unit>)' )( format ="." )
178190:marked
179191 This XML element represents the translation of the `<h1>` greeting tag you marked with the `i18n` attribute.
180192
181193 Using the _source_, _description_, and _meaning_ elements to guide your translation,
182194 replace the `<target/>` tag with the French greeting:
183- + makeExample('cb-i18n/ts/i18n/fr/ messages.fr.xlf.html' , 'trans-unit' , 'i18n/fr /messages.fr.xlf (<trans-unit>, after translation)' )( format ="." )
195+ + makeExample('cb-i18n/ts/locale/ messages.fr.xlf.html' , 'trans-unit' , 'locale /messages.fr.xlf (<trans-unit>, after translation)' )( format ="." )
184196:marked
185197 Note that the `id` is generated by the tool. Don't touch it.
186- Its value depends on the content of the message, its meaning, and its description .
187- Change any of these factors and the `id` changes as well.
198+ Its value depends on the content of the message and its assigned meaning .
199+ Change either factor and the `id` changes as well.
188200.alert.is-helpful
189201 :marked
190202 Repeat the extraction process whenever you add new app messages or edit existing ones.
@@ -202,19 +214,19 @@ a#i18n-file-structure
202214 cb-i18n/ts/app/app.component.ts,
203215 cb-i18n/ts/app/app.module.ts,
204216 cb-i18n/ts/app/main.1.ts,
205- cb-i18n/ts/i18n/fr /messages.fr.xlf.html
217+ cb-i18n/ts/locale /messages.fr.xlf.html
206218` , '' , `
207219 app/app.component.html,
208220 app/app.component.ts,
209221 app/app.module.ts,
210222 app/main.ts,
211- i18n/fr /messages.fr.xlf
223+ locale /messages.fr.xlf
212224` )
213225
214226a#merge
215227.l-main-section
216228:marked
217- ## Merge the translation file
229+ ## Merge the completed translation file
218230
219231 To merge the translated text into component templates,
220232 you compile the application with the completed translation file.
@@ -224,7 +236,8 @@ a#merge
224236 You provide the Angular compiler with three new pieces of information:
225237 * the translation file
226238 * the translation file format
227- * the _Locale ID_ (`en-US` for instance)
239+ * the <a href="https://en.wikipedia.org/wiki/XLIFF" target="_blank">_Locale ID_</a>
240+ (`fr` or `en-US` for instance)
228241
229242 _How_ you provide this information depends upon whether you compile with
230243 the JiT (_Just-in-Time_) compiler or the AoT (_Ahead-of-Time_) compiler.
@@ -280,12 +293,12 @@ a#text-plugin
280293:marked
281294 * It gets the locale from the global `document.locale` variable that was set in `index.html`.
282295
283- * If there is no locale or the language is English, there is no need to translate.
296+ * If there is no locale or the language is U.S. English (`en-US`) , there is no need to translate.
284297 The function returns an empty `noProviders` array as a `Promise`.
285298 It must return a `Promise` because this function could read a translation file asynchronously from the server.
286299
287300 * It creates a transaction filename from the locale according to the name and location convention
288- [described earlier](#i18n-file-structure ).
301+ [described earlier](#localization-folder ).
289302
290303 * The `getTranslationsWithSystemJs` method reads the translation and returns the contents as a string.
291304 Notice that it appends `!text` to the filename, telling SystemJS to use the [text plugin](#text-plugin).
@@ -341,10 +354,10 @@ a#aot
341354
342355 For this sample, the French language command would be
343356code-example( language ="sh" class ="code-shell" ) .
344- ./node_modules/.bin/ngc --i18nFile=./i18n/fr /messages.fr.xlf --locale=fr --i18nFormat=xlf
357+ ./node_modules/.bin/ngc --i18nFile=./locale /messages.fr.xlf --locale=fr --i18nFormat=xlf
345358
346359.l-sub-section
347360 :marked
348361 Windows users may have to quote the command:
349362 code-example( language ="sh" class ="code-shell" ) .
350- "./node_modules/.bin/ngc" --i18nFile=./i18n/fr /messages.fr.xlf --locale=fr --i18nFormat=xlf
363+ "./node_modules/.bin/ngc" --i18nFile=./locale /messages.fr.xlf --locale=fr --i18nFormat=xlf
0 commit comments