npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xlf2xlf

v1.2.0

Published

A command-line utility to automatically translate .xlf translation files using Google Translate

Downloads

48

Readme

Xlf2Xlf NPM

XLF2XLF (ex. google-translate-xlf)

XLF2XLF

A command-line utility to automatically translate .xlf translation files using Google Translate

DISCLAIMER

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

Some additions to package dependecies were made according to https://www.npmjs.com/package/google-translate-xlf-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.

Installation

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

npm install -g xlf2xlf

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


You also could run library using npx utility.

npx xlf2xlf [options]

Usage

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:

xlf2xlf --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:

xlf2xlf -i messages.xlf -o messages.hi.xlf -f en -t nl

For more usage help, run:

xlf2xlf help

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

Messages

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.

Message:

[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.

Message:

[WARN] Failed to translate

Parameters

| 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 |

🤒 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 xlf2xlf --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 xlf2xlf --in messages.xlf --out messages.hi.xlf --from en --to hi --rate 10000 --concurrent 1

Developing

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.

Translation

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

XLIF 1.2 Specification

http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html