Angular CLI - ng xi18n Command

This chapter explains the syntax, arguments and options of ng xi18n command along with an example.


The syntax for ng xi18n command is as follows −

ng xi18n <project> [options]
ng i18n-extract <project> [options]

ng xi18n command extracts i18n messages from source code.


The argument for ng xi18n command is as follows −

Sr.No. Argument & Syntax Description
1 <project> The name of the project. It can be an application or library.


Options are optional parameters.

Sr.No. Option & Syntax Description
1 --browserTarget=browserTarget Target to extract from.
2 --configuration=configuration

A named build target, as specified in the "configurations" section of angular.json. Each named target is accompanied by a configuration of option defaults for that target. Setting this explicitly overrides the "--prod" flag.

Aliases: -c

3 --createCommits=true|false

Create source control commits for updates and migrations.

Default: false

Aliases: -C

4 --format=xmb|xlf|xlif|xliff|xlf2|xliff2

Output format for the generated file.

Default: xlf

5 --help=true|false|json|JSON

Shows a help message for this command in the console.

Default: false

6 --outFile=outFile Name of the file to output.
7 --outputPath=outputPath Path where output will be placed.
8 --prod=true|false Shorthand for "--configuration=production". When true, sets the build configuration to the production target. By default, the production target is set up in the workspace configuration such that all builds make use of bundling, limited tree-shaking, and also limited dead code elimination.
9 --progress=true|false

Log progress to the console.

Default: true

First move to an angular project updated using ng build command. The chapter is available at

Update the app.component.html as follows −


<div class="content" role="main">
   <span i18n>app is running!</span>

Now run the xi18n command.


An example for ng xi18n command is given below −

\>Node\>TutorialsPoint> ng xi18n

Add localization support.

\>Node\>TutorialsPoint> ng add @angular/localize
Installing packages for tooling via npm.
Installed packages for tooling via npm.
UPDATE src/polyfills.ts (3064 bytes)

Now ng will create a messages.xlf file in root folder which is a industry standard translation file.


<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
   <file source-language="en-US" datatype="plaintext" original="ng2.template">
         <trans-unit id="6226cbeebaffaec0342459915ef7d9b0e9e92977" datatype="html">
            <source>app is running!</source>
            <context-group purpose="location">
               <context context-type="sourcefile">src/app/app.component.html</context>
               <context context-type="linenumber">2</context>
Kickstart Your Career

Get certified by completing the course

Get Started