Requirements
- Angular 19 or higher
- Node.js 18 or higher
@angular/localizeinstalledng-extract-i18n-mergeinstalled
A CLI tool to simplify Angular i18n configuration management.
Automates the setup and management of internationalization settings in angular.json
for Angular 19+ projects using XLF files and @angular/localize.
@angular/localize installedng-extract-i18n-merge installed# Install globally $ npm install -g @softwarity/angular-i18n-cli # Or install in your project $ npm install --save-dev @softwarity/angular-i18n-cli
Before using the CLI, install the required Angular dependencies:
$ ng add @angular/localize $ ng add ng-extract-i18n-merge
Initializes the i18n configuration in your Angular project. Sets up the source locale, build configurations, and extract-i18n format.
$ angular-i18n init ? Enter source locale code (default: en): en i18n configuration initialized successfully!
$ angular-i18n init --source-locale en # With explicit project (for monorepos) $ angular-i18n init --source-locale en --project my-app
| Option | Description | Default |
|---|---|---|
--source-locale <code> |
Source locale code (BCP 47) | en |
--project <name> |
Project name (for monorepo workspaces) | Auto-selected if single project |
{ "projects": { "your-project": { "i18n": { "sourceLocale": { "code": "en", "subPath": "en" }, "locales": {} }, "architect": { "build": { "configurations": { "en": { "localize": ["en"], "deleteOutputPath": false } } }, "extract-i18n": { "options": { "format": "xlf" } } } } } }
Adds a new locale to your project. Validates the locale code using the Intl.DisplayNames API (BCP 47 compliance).
$ angular-i18n add ? Enter locale code (BCP 47) (e.g., fr): fr Locale fr added successfully!
$ angular-i18n add --locale fr Locale fr added successfully! # Add multiple locales $ angular-i18n add --locale de $ angular-i18n add --locale es
| Option | Description | Default |
|---|---|---|
--locale <code> |
Locale code to add (BCP 47, e.g. fr, de, es) |
- |
--project <name> |
Project name (for monorepo workspaces) | Auto-selected if single project |
{ "i18n": { "locales": { "fr": { "translation": "src/locales/messages.fr.xlf", "subPath": "fr" } } }, "architect": { "build": { "configurations": { "fr": { "localize": ["fr"], "deleteOutputPath": false } } }, "extract-i18n": { "options": { "targetFiles": ["messages.fr.xlf"] } } } }
Removes a locale from your project. Cleans up the i18n config, build configuration, and extract-i18n target files.
$ angular-i18n remove ? Select locale to remove: fr de > es Locale es removed successfully!
$ angular-i18n remove --locale fr Locale fr removed successfully!
| Option | Description | Default |
|---|---|---|
--locale <code> |
Locale code to remove | - |
--project <name> |
Project name (for monorepo workspaces) | Auto-selected if single project |
$ ng add @angular/localize $ ng add ng-extract-i18n-merge
$ angular-i18n init ? Enter source locale code (default: en): en i18n configuration initialized successfully!
$ angular-i18n init --source-locale en i18n configuration initialized successfully!
$ angular-i18n add ? Enter locale code (BCP 47) (e.g., fr): fr Locale fr added successfully! $ angular-i18n add ? Enter locale code (BCP 47) (e.g., fr): de Locale de added successfully!
$ angular-i18n add --locale fr Locale fr added successfully! $ angular-i18n add --locale de Locale de added successfully!
$ ng extract-i18n # Translation files are generated in src/locales/ # Translate messages.fr.xlf, messages.de.xlf, etc.
$ ng build --configuration fr
The CLI performs validation checks and provides clear error messages:
# Missing @angular/localize $ angular-i18n init @angular/localize is not configured. Please run the following commands: ng add @angular/localize ng add ng-extract-i18n-merge # Invalid locale code $ angular-i18n add --locale xyz Error: Please enter a valid locale code. xyz is not a valid BCP 47 tag. # i18n not initialized $ angular-i18n add --locale fr Error: i18n not initialized. Run init-i18n first.
Intl.DisplayNames APIangular.json