parent
f37cf52b4c
commit
41ac58ab7d
|
@ -19,7 +19,7 @@ Angular simplifies the following aspects of internationalization:
|
|||
* Handling plural forms of words.
|
||||
* Handling alternative text.
|
||||
|
||||
For localization, you can use the [**Angular CLI**](https://cli.angular.io/) to generate most of the boilerplate necessary to create files for translators, and to publish it in multiple languages.
|
||||
For localization, you can use the [**Angular CLI**](https://cli.angular.io/) to generate most of the boilerplate necessary to create files for translators, and to publish your app in multiple languages.
|
||||
After you have set up your app to use i18n, the CLI can help you with the following steps:
|
||||
* Extracting localizable text into a file that you can send out to be translated.
|
||||
* Building and serving the app for a given locale, using the translated text.
|
||||
|
@ -136,14 +136,17 @@ The i18n template translation process has four phases:
|
|||
|
||||
1. Mark static text messages in your component templates for translation.
|
||||
|
||||
2. Create translation files: use the Angular CLI `i18n` tool to extract the marked text into an industry-standard translation source file.
|
||||
2. Create a translation file: Use the Angular CLI `xi18n` command to extract the marked text into an industry-standard translation source file.
|
||||
|
||||
3. Edit the translation files to translate the extracted text into the target language.
|
||||
3. Edit the generated translation file: Translate the extracted text into the target language.
|
||||
|
||||
4. Merge the completed translation file into the app.
|
||||
Use the Angular CLI `build` tool to compile the app, choosing compiler options to import the completed translation files,
|
||||
replace the original messages with translated text, and generate a new version of the app
|
||||
in the target language.
|
||||
4. Merge the completed translation file into the app. To do this, use the Angular CLI `build` command to compile the app, choosing a [locale-specific configuration](#merge-aot), or specifying the following command options.
|
||||
|
||||
* `--i18nFile`=*path to the translation file*
|
||||
* `--i18nFormat`=*format of the translation file*
|
||||
* `--i18nLocale`= *locale id*
|
||||
|
||||
The command replaces the original messages with translated text, and generates a new version of the app in the target language.
|
||||
|
||||
You need to build and deploy a separate version of the app for each supported language.
|
||||
|
||||
|
@ -397,14 +400,14 @@ You can also nest different ICU expressions together, as shown in this example:
|
|||
|
||||
## Create a translation source file
|
||||
|
||||
When your app is ready, you can use the Angular CLI to extract the text messages marked with `i18n` into a translation source file.
|
||||
Open a terminal window at the root of the app project and enter the `ng xi18n` command:
|
||||
When your app is ready, you can use the Angular CLI to extract the text messages marked with `i18n` and attributes marked with `i18n-x` into a translation source file.
|
||||
Open a terminal window at the root of the app project and run the CLI command `xi18n`.
|
||||
|
||||
<code-example language="sh" class="code-shell">
|
||||
ng xi18n
|
||||
</code-example>
|
||||
|
||||
By default, the `ng xi18n` command creates a file named `messages.xlf` in your `src/` folder.
|
||||
By default, the command creates a file named `messages.xlf` in your `src/` folder.
|
||||
|
||||
<div class="alert is-helpful">
|
||||
|
||||
|
@ -421,23 +424,23 @@ For more information, see the [Angular Ahead-of-Time Webpack Plugin documentatio
|
|||
### Output options
|
||||
|
||||
You can supply command options to change the format, the name, the location, and the source locale of the extracted file.
|
||||
For example to create a file in the `src/locale` folder, specify the output path:
|
||||
For example, to create a file in the `src/locale` folder, specify the output path:
|
||||
|
||||
<code-example language="sh" class="code-shell">
|
||||
ng xi18n --output-path src/locale
|
||||
</code-example>
|
||||
|
||||
By default, the Angular i18n tool generates a translation file named `messages.xlf` in the
|
||||
By default, the `xi18n` command generates a translation file named `messages.xlf` in the
|
||||
<a href="https://en.wikipedia.org/wiki/XLIFF">XML Localization Interchange File Format
|
||||
(XLIFF, version 1.2)</a>.
|
||||
|
||||
The tool supports three translation formats:
|
||||
The command can read and write files in three translation formats:
|
||||
* XLIFF 1.2 (default)
|
||||
* XLIFF 2
|
||||
* <a href="http://cldr.unicode.org/development/development-process/design-proposals/xmb" >XML Message
|
||||
Bundle (XMB)</a>
|
||||
|
||||
You can specify the translation format explicitly with the `--i18nFormat` flag as illustrated in
|
||||
You can specify the translation format explicitly with the `--i18nFormat` command option, as illustrated in
|
||||
these example commands:
|
||||
|
||||
<code-example language="sh" class="code-shell">
|
||||
|
@ -683,12 +686,14 @@ When you internationalize with the AOT compiler, you must pre-build a separate a
|
|||
package for each language and serve the appropriate package based on either server-side language
|
||||
detection or url parameters.
|
||||
|
||||
You also need to instruct the AOT compiler to use your translation configuration. To do so, you configure the translation with three options in your `angular.json` file.
|
||||
To instruct the AOT compiler to use your translation configuration, set the three "i18n" build configuration options in your `angular.json` file.
|
||||
|
||||
* `i18nFile`: the path to the translation file.
|
||||
* `i18nFormat`: the format of the translation file.
|
||||
* `i18nLocale`: the locale id.
|
||||
|
||||
You should also direct the output to a locale-specific folder to keep it separate from other locale versions of your app, by setting the `outputPath` configuration option.
|
||||
|
||||
```
|
||||
"build": {
|
||||
...
|
||||
|
@ -715,7 +720,7 @@ You also need to instruct the AOT compiler to use your translation configuration
|
|||
}
|
||||
```
|
||||
|
||||
You then pass the configuration with the `ng serve` or `ng build` commands.
|
||||
You can then pass this configuration to the `ng serve` or `ng build` commands.
|
||||
The example below shows how to serve the French language file created in previous
|
||||
sections of this guide:
|
||||
|
||||
|
@ -826,10 +831,10 @@ error:
|
|||
|
||||
### Build for multiple locales
|
||||
|
||||
When you build your application for different locales, change the output path along with the i18n options using the `--outputPath` option, so that the translation files are saved to different locations.
|
||||
When you use the CLI `build` or `serve` command to build your application for different locales, change the output path using the `--outputPath` command option (along with the i18n-specific command options), so that the translation files are saved to different locations.
|
||||
When you are serving a locale-specific version from a subdirectory, you can also change the base URL used by your app by specifying the `--baseHref` option.
|
||||
|
||||
For example if the French version of your application is served from https://myapp.com/fr/, configure the build for the French version as follows.
|
||||
For example, if the French version of your application is served from https://myapp.com/fr/, configure the build for the French version as follows.
|
||||
|
||||
```
|
||||
"configurations": {
|
||||
|
|
Loading…
Reference in New Issue