Angular CLI - ng extract-i18n Command



The ng extract-i18n is a built-in Angular CLI command. In Angular, it is used to extract internationalization (i18n) messages from the source code. To use this command, run it in the terminal by specifying an optional project name or other options that we will learn in the coming section of this tutorial.

On running the ng extract-i18n command, it generates a file containing extracted i18n messages. The format of the file will be XLIFF or JSON. This file is used for translating the application into different languages.

What is i18n in Angular?

The i18n, also known as internationalization, is a feature of Angular that enables the application to target any language in the world. Localization is a part of Internationalization and it enables the application to render in a targeted local language.

Syntax

The syntax of ng extract-i18n command is given below −

ng extract-i18n [project][options]

Options

The optional parameters of ng extract-i18n command are given in the following table:

Sr.No. Option & Syntax Description
1 --configuration Alias c A comma-separated list of one or more named builder configurations.
2 --help When this option is used along with the command, it shows a short description of ng extract-i18n command in the console.
3 --build-target The target where i18n messages will be extracted.
4 --format This option is used in the form of String. It specifies the format of the generated file. By default, it is xlf.
5 --out-file Output file name.
6 --output-path Location of the output file.
7 --progress Use this option with the command to show the progress in the console. By default, its value is "true" which means on running the ng extract-i18n command, you will the progress in the console.

Example

Before using the ng extract-i18n command, it is important to add the @angular/localize package to the project. Then, you can run the command to extract the i18n message. Let's see a practical example −

PS D:\Angular\flex-app> ng add @angular/localize
✔ Determining Package Manager
  › Using package manager: npm
✔ Searching for compatible package version
  › Found compatible package version: @angular/localize@18.2.13.
✔ Loading package information from registry
✔ Confirming installation
✔ Installing package
UPDATE src/main.ts (301 bytes)
UPDATE tsconfig.app.json (472 bytes)
UPDATE tsconfig.spec.json (477 bytes)
UPDATE angular.json (2949 bytes)
PS D:\Angular\flex-app> ng extract-i18n
Initial chunk files   | Names         | Raw size
main-LBD7KYCR.js      | main          |  1.21 MB | 
polyfills-PE7ERSA4.js | polyfills     | 92.49 kB | 
styles-536X67QD.css   | styles        | 56 bytes | 

                      | Initial total |  1.30 MB

Application bundle generation complete. [5.971 seconds]

Extraction Complete. (Messages: 0)
Advertisements