1.0.33 • Public • Published

xlf-auto-translate (ex. xlf2xlf)

A command-line utility to automatically translate .xlf translation files v1.2 or v2 using Google Translate


This library was forked from https://github.com/nfriend/xlf-auto-translate

Some additions to package dependecies were made according to https://www.npmjs.com/package/xlf-auto-translate-updated

The main goal to fork and edit original tool was to preserve word and interpolation blocks order while translating original .xlf file, as base library copied this interpolation blocks to the end of target element.

While making this improvements, the original translate.js file eas fully rewritten starting from library we are using to read and build object model of .xlf to ending with how we are parsing object model tree itself and creating queue to translate.

Also most of redundant dependecies were removed, file and folder structure were redefined.


This is a command-line utility. To install this utility, run:

npm install -g xlf-auto-translate

This will install the utility globally so that it can be run from any location. The executable installed by this module is xlf-auto-translate.

You also could run library using npx utility.

npx xlf-auto-translate [options]


Before you begin, you will need an .xlf file to translate!

If you are using Angular 2+ and the Angular CLI, you will probably extract an .xlf file from your app by running ng xi18n inside your Angular project. This produces a file named messages.xlf inside your project folder.

Say we have an .xlf file named messages.xlf. Let's translate this file from English ("en") to Hindi ("hi") and save the translated file as messages.hi.xlf:

xlf-auto-translate --in messages.xlf --out messages.hi.xlf --from en --to hi

Or, if you don't like typing too much, you can use the abbreviated versions of the arguments:

xlf-auto-translate -i messages.xlf -o messages.hi.xlf -f en -t nl

For more usage help, run:

xlf-auto-translate help

If the utility not installed globally, just use it via npx, e.g. npx xlf-auto-translate --in messages.xlf --out messages.hi.xlf --from en --to hi


Tool adds 2 kind of extra messages to final xlf file according to certain criterias:

  1. If we are using skip option, there will be information messages inside target tags to ease spot of where translation should be placed.


[INFO] Add your translation here
  1. If there is any errors during quering the translation, there will be warning messages inside problematic target tags to ease spot where things went wrong.


[WARN] Failed to translate


Option Default Mandatory Description
i / in - true The input .xlf file to translate
o / out - true The name of the translated output file
f / from - true The language code of the input file
t / to - true The language code to translate to
r / rate 500 false How long to wait after launching a job before launching another one in ms. For more information see https://github.com/SGrondin/bottleneck#docs
c / concurrent 4 false How many jobs can be executing at the same time. For more information see https://github.com/SGrondin/bottleneck#docs
s / skip false false Skips translating and adds only target tag with boilerplate text [INFO] Add your translation here
p / proxy false false Use custom proxy
ap / autoProxy - false Use default proxy
cs / clearState false false Clear state once translated

🤒 Known issues

  • The speed of quering / getting response is depends on network quality.

  • Sometimes translation could end up with tons of errors like {"name":"HTTPError","statusCode":429,"statusMessage":"Too Many Requests"}, in this case better to wait for some time before next iteration.

In case you are starting to get {"name":"HTTPError","statusCode":429,"statusMessage":"Too Many Requests"} you could do the following:

  • Wait a bit before Google Translate will stop blocking your IP
  • Try to set bigger rate npx xlf-auto-translate --in messages.xlf --out messages.hi.xlf --from en --to hi --rate 5000, where rate is ms between queries. For more information on that property see https://github.com/SGrondin/bottleneck
  • Try to limit rate and amount of concurrent requests npx xlf-auto-translate --in messages.xlf --out messages.hi.xlf --from en --to hi --rate 10000 --concurrent 1


The easiest way to develop on this module is to use test-driven development.

Unit tests can be run with npm test. To automatically re-run the tests when you make changes to the files, run npm run test:watch.


This utility uses Google Translate's online API for its translations using this NPM package: https://www.npmjs.com/package/@k3rn31p4nic/google-translate-api

XLIF 1.2 Specification


Package Sidebar


Weekly Downloads






Unpacked Size

67.5 kB

Total Files


Last publish


  • danjor