@@ -21,50 +21,81 @@ For example to create a file in the `src/locale` folder you would use:
21
21
ng xi18n --output-path src/locale
22
22
```
23
23
24
- ### Serve
24
+ ### Building and serving
25
25
Now that you have generated a messages bundle source file, you can translate it.
26
26
Let's say that your file containing the french translations is named ` messages.fr.xlf `
27
27
and 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.
33
28
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
+ },
37
65
```
38
66
67
+ To build the application using the French i18n options, use `ng build --configuration=fr`.
68
+ To serve, use `ng serve --configuration=fr`.
69
+
39
70
Our application is exactly the same but the `LOCALE_ID` has been provided with "fr",
40
71
`TRANSLATIONS_FORMAT` with "xlf" and `TRANSLATIONS` with the content of `messages.fr.xlf`.
41
72
All the strings flagged for i18n have been replaced with their french translations.
42
73
43
74
Note: this only works for AOT, if you want to use i18n in JIT you will have to update
44
75
your bootstrap file yourself.
45
76
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
52
78
53
79
When 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.
59
81
60
82
If 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 .
62
84
63
85
For example if the french version of your application is served from https://myapp.com/fr/
64
86
then you would build the french version like this:
65
87
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
+ }
68
99
```
69
100
70
101
If you need more details about how to create scripts to generate the app in multiple
0 commit comments