@@ -21,50 +21,81 @@ For example to create a file in the `src/locale` folder you would use:
2121ng xi18n --output-path src/locale
2222```
2323
24- ### Serve
24+ ### Building and serving
2525Now that you have generated a messages bundle source file, you can translate it.
2626Let's say that your file containing the french translations is named ` messages.fr.xlf `
2727and is located in the ` src/locale ` folder.
28- If you want to use it when you serve your application you can use the 4 following commands:
29- - ` --i18n-file ` Localization file to use for i18n.
30- - ` --i18n-format ` Format of the localization file specified with --i18n-file.
31- - ` --locale ` Locale to use for i18n.
32- - ` --missing-translation ` Defines the strategy to use for missing i18n translations.
3328
34- In our case we can load the french translations with the following command:
35- ``` sh
36- ng serve --aot --locale fr --i18n-format xlf --i18n-file src/locale/messages.fr.xlf --missing-translation error
29+ If you want to use it when you serve your application you can use the 4 following options:
30+ - ` i18nFile ` Localization file to use for i18n.
31+ - ` i18nFormat ` Format of the localization file specified with --i18n-file.
32+ - ` i18nLocale ` Locale to use for i18n.
33+ - ` i18nMissingTranslation ` Defines the strategy to use for missing i18n translations.
34+
35+ In our case we can load the french translations with the following configuration:
36+ ``` json
37+ "architect" : {
38+ "build" : {
39+ "builder" : " @angular-devkit/build-angular:browser" ,
40+ "options" : { ... },
41+ "configurations" : {
42+ "fr" : {
43+ "aot" : true ,
44+ "outputPath" : " dist/my-project-fr/" ,
45+ "i18nFile" : " src/locale/messages.fr.xlf" ,
46+ "i18nFormat" : " xlf" ,
47+ "i18nLocale" : " fr" ,
48+ "i18nMissingTranslation" : " error" ,
49+ }
50+ // ...
51+ "serve" : {
52+ "builder" : " @angular-devkit/build-angular:dev-server" ,
53+ "options" : {
54+ "browserTarget" : " your-project-name:build"
55+ },
56+ "configurations" : {
57+ "production" : {
58+ "browserTarget" : " your-project-name:build:production"
59+ },
60+ "fr" : {
61+ "browserTarget" : " your-project-name:build:fr"
62+ }
63+ }
64+ },
3765```
3866
67+ To build the application using the French i18n options, use `ng build --configuration=fr`.
68+ To serve, use `ng serve --configuration=fr`.
69+
3970Our application is exactly the same but the `LOCALE_ID` has been provided with "fr",
4071`TRANSLATIONS_FORMAT` with "xlf" and `TRANSLATIONS` with the content of `messages.fr.xlf`.
4172All the strings flagged for i18n have been replaced with their french translations.
4273
4374Note: this only works for AOT, if you want to use i18n in JIT you will have to update
4475your bootstrap file yourself.
4576
46- ### Build
47- To build your application with a specific locale you can use the exact same commands
48- that you used for ` serve ` :
49- ``` sh
50- ng build --aot --locale fr --i18n-format xlf --i18n-file src/locale/messages.fr.xlf --missing-translation error
51- ```
77+ ### Using multiple languages
5278
5379When you build your application for a specific locale, it is probably a good idea to change
54- the output path with the command ` --output-path ` in order to save the files to a different location.
55-
56- ``` sh
57- ng build --aot --output-path dist/fr --locale fr --i18n-format xlf --i18n-file src/locale/messages.fr.xlf --missing-translation error
58- ```
80+ the output path with the `outputPath` options in order to save the files to a different location.
5981
6082If you end up serving this specific version from a subdirectory, you can also change
61- the base url used by your application with the command ` --base-href ` .
83+ the base url used by your application with the `baseHref` option .
6284
6385For example if the french version of your application is served from https://myapp.com/fr/
6486then you would build the french version like this:
6587
66- ``` sh
67- ng build --aot --output-path dist/fr --base-href /fr/ --locale fr --i18n-format xlf --i18n-file src/locale/messages.fr.xlf --missing-translation error
88+ ```json
89+ "configurations" : {
90+ "fr" : {
91+ "aot" : true ,
92+ "outputPath" : " dist/my-project-fr/" ,
93+ "baseHref" : " /fr/" ,
94+ "i18nFile" : " src/locale/messages.fr.xlf" ,
95+ "i18nFormat" : " xlf" ,
96+ "i18nLocale" : " fr" ,
97+ "i18nMissingTranslation" : " error" ,
98+ }
6899```
69100
70101If you need more details about how to create scripts to generate the app in multiple
0 commit comments