Commit 4b99729
committed
feat(@angular/build): add support for customizing URL segments with i18n
Previously, the `baseHref` option under each locale allowed for generating a unique base href for specific locales. However, users were still required to handle file organization manually, and `baseHref` appeared to be primarily designed for this purpose.
This commit introduces a new `urlSegment` option, which simplifies the i18n process, particularly in static site generation (SSG) and server-side rendering (SSR). When the `urlSegment` option is used, the `baseHref` is ignored. Instead, the `urlSegment` serves as both the base href and the name of the directory containing the localized version of the app.
### Configuration Example
Below is an example configuration showcasing the use of `urlSegment`:
```json
"i18n": {
"sourceLocale": {
"code": "en-US",
"urlSegment": ""
},
"locales": {
"fr-BE": {
"urlSegment": "fr",
"translation": "src/i18n/messages.fr-BE.xlf"
},
"de-BE": {
"urlSegment": "de",
"translation": "src/i18n/messages.de-BE.xlf"
}
}
}
```
### Example Directory Structure
The following tree structure demonstrates how the `urlSegment` organizes localized build output:
```
dist/
├── app/
│ └── browser/ # Default locale, accessible at `/`
│ ├── fr/ # Locale for `fr-BE`, accessible at `/fr`
│ └── de/ # Locale for `de-BE`, accessible at `/de`
```
Closes #16997 and closes #289671 parent ca757c9 commit 4b99729
File tree
8 files changed
+287
-46
lines changed- packages/angular
- build/src
- builders/application
- utils
- server-rendering
- cli/lib/config
- ssr/src
- tests/legacy-cli/e2e/tests/build/server-rendering
8 files changed
+287
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | | - | |
| 44 | + | |
43 | 45 | | |
44 | | - | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
63 | | - | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | 75 | | |
77 | 76 | | |
78 | 77 | | |
| |||
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
85 | | - | |
| 84 | + | |
86 | 85 | | |
87 | 86 | | |
88 | 87 | | |
| |||
94 | 93 | | |
95 | 94 | | |
96 | 95 | | |
97 | | - | |
98 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| |||
Lines changed: 12 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
646 | | - | |
| 646 | + | |
647 | 647 | | |
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
651 | 651 | | |
652 | 652 | | |
653 | 653 | | |
654 | | - | |
655 | | - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
656 | 657 | | |
657 | 658 | | |
658 | | - | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
659 | 667 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
67 | 78 | | |
68 | 79 | | |
69 | 80 | | |
| |||
82 | 93 | | |
83 | 94 | | |
84 | 95 | | |
85 | | - | |
86 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
87 | 99 | | |
88 | 100 | | |
89 | 101 | | |
| |||
98 | 110 | | |
99 | 111 | | |
100 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
101 | 122 | | |
102 | 123 | | |
103 | 124 | | |
| |||
108 | 129 | | |
109 | 130 | | |
110 | 131 | | |
| 132 | + | |
111 | 133 | | |
112 | 134 | | |
113 | 135 | | |
114 | 136 | | |
115 | 137 | | |
116 | 138 | | |
117 | | - | |
118 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
119 | 143 | | |
120 | 144 | | |
121 | 145 | | |
122 | 146 | | |
123 | 147 | | |
124 | 148 | | |
125 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
126 | 161 | | |
127 | 162 | | |
128 | 163 | | |
| |||
136 | 171 | | |
137 | 172 | | |
138 | 173 | | |
| 174 | + | |
139 | 175 | | |
140 | 176 | | |
141 | 177 | | |
| |||
Lines changed: 11 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 9 | + | |
| 10 | + | |
14 | 11 | | |
15 | 12 | | |
16 | 13 | | |
| |||
57 | 54 | | |
58 | 55 | | |
59 | 56 | | |
60 | | - | |
| 57 | + | |
61 | 58 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 59 | + | |
66 | 60 | | |
| 61 | + | |
67 | 62 | | |
68 | | - | |
69 | | - | |
70 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
71 | 66 | | |
72 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
73 | 70 | | |
74 | 71 | | |
75 | 72 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
| 222 | + | |
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
278 | | - | |
| 278 | + | |
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | | - | |
| 282 | + | |
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
288 | 293 | | |
289 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
290 | 314 | | |
291 | 315 | | |
292 | 316 | | |
| |||
299 | 323 | | |
300 | 324 | | |
301 | 325 | | |
302 | | - | |
| 326 | + | |
303 | 327 | | |
304 | 328 | | |
305 | 329 | | |
306 | | - | |
| 330 | + | |
307 | 331 | | |
308 | 332 | | |
309 | 333 | | |
310 | 334 | | |
311 | 335 | | |
312 | 336 | | |
313 | 337 | | |
314 | | - | |
| 338 | + | |
315 | 339 | | |
316 | 340 | | |
317 | 341 | | |
318 | 342 | | |
319 | 343 | | |
320 | | - | |
| 344 | + | |
321 | 345 | | |
322 | 346 | | |
323 | 347 | | |
324 | | - | |
| 348 | + | |
325 | 349 | | |
326 | 350 | | |
327 | 351 | | |
| |||
331 | 355 | | |
332 | 356 | | |
333 | 357 | | |
334 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
335 | 364 | | |
336 | 365 | | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
337 | 385 | | |
338 | 386 | | |
339 | 387 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
0 commit comments