You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 `subPath` option, which simplifies the i18n process, particularly in static site generation (SSG) and server-side rendering (SSR). When the `subPath` option is used, the `baseHref` is ignored. Instead, the `subPath` serves as both the base href and the name of the directory containing the localized version of the app.
Below is an example configuration showcasing the use of `subPath`:
```json
"i18n": {
"sourceLocale": {
"code": "en-US",
"subPath": ""
},
"locales": {
"fr-BE": {
"subPath": "fr",
"translation": "src/i18n/messages.fr-BE.xlf"
},
"de-BE": {
"subPath": "de",
"translation": "src/i18n/messages.de-BE.xlf"
}
}
}
```
The following tree structure demonstrates how the `subPath` 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`
```
DEPRECATED: The `baseHref` option under `i18n.locales` and `i18n.sourceLocale` in `angular.json` is deprecated in favor of `subPath`.
The `subPath` defines the URL segment for the locale, serving as both the HTML base HREF and the directory name for output. By default, if not specified, `subPath` will use the locale code.
Closes#16997 and closes#28967
"description": "HTML base HREF to use for the locale (defaults to the locale code)"
287
+
"deprecated": true,
288
+
"description": "Specifies the HTML base HREF for the locale. Defaults to the locale code if not provided."
289
+
},
290
+
"subPath": {
291
+
"type": "string",
292
+
"description": "Defines the subpath for accessing this locale. It serves as the HTML base HREF and the directory name for the output. Defaults to the locale code if not specified.",
293
+
"pattern": "^[\\w-]*$"
288
294
}
289
295
},
296
+
"anyOf": [
297
+
{
298
+
"required": ["subPath"],
299
+
"not": {
300
+
"required": ["baseHref"]
301
+
}
302
+
},
303
+
{
304
+
"required": ["baseHref"],
305
+
"not": {
306
+
"required": ["subPath"]
307
+
}
308
+
},
309
+
{
310
+
"not": {
311
+
"required": ["baseHref", "subPath"]
312
+
}
313
+
}
314
+
],
290
315
"additionalProperties": false
291
316
}
292
317
]
@@ -299,29 +324,29 @@
299
324
"oneOf": [
300
325
{
301
326
"type": "string",
302
-
"description": "Localization file to use for i18n"
327
+
"description": "Localization file to use for i18n."
303
328
},
304
329
{
305
330
"type": "array",
306
-
"description": "Localization files to use for i18n",
331
+
"description": "Localization files to use for i18n.",
307
332
"items": {
308
333
"type": "string",
309
334
"uniqueItems": true
310
335
}
311
336
},
312
337
{
313
338
"type": "object",
314
-
"description": "Localization options to use for the locale",
339
+
"description": "Localization options to use for the locale.",
315
340
"properties": {
316
341
"translation": {
317
342
"oneOf": [
318
343
{
319
344
"type": "string",
320
-
"description": "Localization file to use for i18n"
345
+
"description": "Localization file to use for i18n."
321
346
},
322
347
{
323
348
"type": "array",
324
-
"description": "Localization files to use for i18n",
349
+
"description": "Localization files to use for i18n.",
325
350
"items": {
326
351
"type": "string",
327
352
"uniqueItems": true
@@ -331,9 +356,34 @@
331
356
},
332
357
"baseHref": {
333
358
"type": "string",
334
-
"description": "HTML base HREF to use for the locale (defaults to the locale code)"
359
+
"deprecated": true,
360
+
"description": "Specifies the HTML base HREF for the locale. Defaults to the locale code if not provided."
361
+
},
362
+
"subPath": {
363
+
"type": "string",
364
+
"description": "Defines the URL segment for accessing this locale. It serves as the HTML base HREF and the directory name for the output. Defaults to the locale code if not specified.",
0 commit comments