A CLI tool to help manage Angular i18n configuration in your projects. This tool is designed to work in conjunction with Angular's built-in i18n mechanism, providing a simplified way to manage your internationalization configuration.
- Softwarity.io - API Gateway based on Spring Gateway
- XLIFF AI Translator - AI-powered translation tool for Angular applications
- Angular 19 or higher
- Node.js 18 or higher
# Install globally
npm install -g @softwarity/angular-i18n-cli
# Or install in your project
npm install --save-dev @softwarity/angular-i18n-cliBefore using the CLI, you need to install the required dependencies:
# Install @angular/localize
# See: https://angular.dev/guide/i18n
ng add @angular/localize
# Install ng-extract-i18n-merge
# See: https://github.com/daniel-sc/ng-extract-i18n-merge#readme
ng add ng-extract-i18n-mergeThis CLI tool is specifically designed to work with Angular's built-in i18n mechanism. It helps you:
- Configure the i18n settings in your
angular.json - Manage locale configurations
- Set up the correct format for XLF files
- Configure the build process for multiple locales
The tool assumes you are using Angular's standard i18n workflow with XLF files and the @angular/localize package.
Initializes the i18n configuration in your Angular project.
angular-i18n init- If your workspace has only one project, it will be automatically selected
- If your workspace has multiple projects, you'll be prompted to select one
- Adds i18n configuration:
{
"projects": {
"your-project": {
"i18n": {
"sourceLocale": {
"code": "en",
"subPath": "en"
},
"locales": {}
}
}
}
}- Adds build configuration for the source locale:
{
"projects": {
"your-project": {
"architect": {
"build": {
"configurations": {
"en": {
"localize": ["en"],
"deleteOutputPath": false
}
}
}
}
}
}
}- Configures extract-i18n format:
{
"projects": {
"your-project": {
"architect": {
"extract-i18n": {
"options": {
"format": "xlf"
}
}
}
}
}
}Adds a new locale to your project.
angular-i18n add- If your workspace has only one project, it will be automatically selected
- If your workspace has multiple projects, you'll be prompted to select one
- You'll be prompted to enter a locale code (e.g., 'fr', 'es', 'de')
- The code will be validated using the Intl API
- Adds the locale to i18n configuration:
{
"projects": {
"your-project": {
"i18n": {
"locales": {
"fr": {
"translation": "src/locale/messages.fr.xlf",
"subPath": "fr"
}
}
}
}
}
}- Adds build configuration for the new locale:
{
"projects": {
"your-project": {
"architect": {
"build": {
"configurations": {
"fr": {
"localize": ["fr"],
"deleteOutputPath": false
}
}
}
}
}
}
}- Adds the locale file to extract-i18n target files:
{
"projects": {
"your-project": {
"architect": {
"extract-i18n": {
"options": {
"targetFiles": ["messages.fr.xlf"]
}
}
}
}
}
}Removes a locale from your project.
angular-i18n remove- If your workspace has only one project, it will be automatically selected
- If your workspace has multiple projects, you'll be prompted to select one
- You'll be prompted to select a locale from the list of configured locales
- Removes the locale from i18n configuration
- Removes the build configuration for the locale
- Removes the locale file from extract-i18n target files
The CLI includes several error checks:
- Verifies that @angular/localize is installed
- Verifies that ng-extract-i18n-merge is installed
- Validates locale codes using the Intl API
- Ensures i18n is initialized before adding or removing locales
- Ensures extract-i18n is configured before adding locales