Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@angular/build): add support for customizing URL segments with i18n #29011

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alan-agius4
Copy link
Collaborator

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:

"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 #28967

@alan-agius4 alan-agius4 added the target: minor This PR is targeted for the next minor release label Dec 2, 2024
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: @angular/build labels Dec 2, 2024
@alan-agius4 alan-agius4 force-pushed the ssr-i18n-output-path branch 4 times, most recently from 048d91a to 8e596e9 Compare December 2, 2024 15:46
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 angular#16997 and closes angular#28967
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: @angular/build detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release
Projects
None yet
1 participant