Giter Site home page Giter Site logo

xlf-merge's Introduction

xlf-merge

Command line tool that merges any number of XLF 1.2 files, JSON text dictionaries, and ARB text dictionaries. Input and output is tested and compatible with Angular compiler.

Designed for (but not limited to) Angular-based applications to simplify their i18n process. The NG compiler requires a single dictionay file per language. If your translations are organized into many small files, you can run this tool to merge them before invoking the Angular compilation.

Installation

# Install globally (run by xlf-merge <parameters>)
npm install xlf-merge -g

# Install locally as development tool (run by node ./node_modules/xlf-merge <parameters>)
npm install xlf-merge --save-dev

Usage

  • Accepts any number of input files (wildcards supported)
  • File format is detected by file extension
    • *.xlf, *.xml - file treated as XLF 1.2
    • *.json - file treated as JSON text dictionary
    • *.abr - file treated as ARB text dictionary
  • Requires single output file path (--output parameter) to merge translated texts
# Merges three input files into output.xlf
xlf-merge input1.xlf input2.xlf input3.xlf --output all-translations.xlf

# Merges all language-specific XLF files in directory i18n into a file containing all translations per language
xlf-merge i18n/*.en.xlf -o all.en.xlf
xlf-merge i18n/*.de.xlf -o all.de.xlf
xlf-merge i18n/*.fr.xlf -o all.fr.xlf

# Merges *.de.xlf files recursively in the current path
xlf-merge **/*.de.xlf -o all.de.xlf

# Merges all XLF and JSON files with patterns *.de.xlf and *.de.json. Merged file has JSON format.
xlf-merge i18n/**/*.de.xlf i18n/**/*.de.json --output all.de.json
  • Supply the --convert parameter to convert all found files
    • Each converted file is saved in the same path as its source file
    • Conversion is allowed with or without the --output parameter (which also merges all input files)
# Converts all XLF files in current directory into JSON format
xlf-merge *.xlf --convert json

# Recursively converts all XLF files into ARB format
xlf-merge **/*.xlf --convert arb

Example set-up

Supposing XLF files are in path src/i18n/**. German translations have pattern *.de.xlf, Swedish translations have pattern *.sv.xlf.

  • Install Xlf-merge locally by running "npm install --save-dev xlf-merge"
  • Run xlf-merge before production build of Angular application
  • Write npm scripts to automate the entire build task, for example:
"scripts": {
    "merge-de": "node ./node_modules/xlf-merge src/i18n/**/*.de.xlf",
    "merge-sv": "node ./node_modules/xlf-merge src/i18n/**/*.sv.xlf",
    "merge-all": "npm run merge-de && npm run merge-sv",
    "build": "npm run merge-all && ng build --prod"
}

Author

Jaroslav Svak, 2018 - 2021

License

MIT

xlf-merge's People

Contributors

darkein avatar headhunter45 avatar jaroslavsvak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xlf-merge's Issues

Empty trans-units since 2.0.0

Hello, thanks for your effort! Great library!

I figured out on my project that since version "2.0.0" it generates empty file with all <trans-unit></trans-unit> in it.

Error on convert properties to xlf

Using xlf-merge 1.0.6

Is it possible to convert from .properties to .xlf files? Currently it throws the following error.

 xlf-merge **/*.properties --convert xlf
[ERR] Couldn't parse file <path>/<filename>.properties
[ERR] xlf-merge failed
Error: Text data outside of root node.
Line: 112
Column: 89
Char: k

Preserve ARB annotations

Some platforms (Flutter) require each localization key to have a corresponding @key in the ARB file. If would be nice if those could be preserved.

bug: error while merging with empty target element

Hey!

I got an error when i'm trying to merge files with empty target element (because it's not translated yet)

Error: Cannot read property 'find' of undefined
    at getContent (C:\Users\pfior\Repos\visiotalent-v2\account\front\node_modules\xlf-merge\merge-xlf.js:32:13)
    at module.exports (C:\Users\pfior\Repos\visiotalent-v2\account\front\node_modules\xlf-merge\merge-xlf.js:61:21)
    at runMerge (C:\Users\pfior\Repos\visiotalent-v2\account\front\node_modules\xlf-merge\index.js:19:18)
    at Object.<anonymous> (C:\Users\pfior\Repos\visiotalent-v2\account\front\node_modules\xlf-merge\index.js:41:5)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)

I think you just have to return an empty string if your element doesn't have element (elements attribute is null).

thanks !

Allow merge files when an ID is duplicate

Feature request :)

I am using your tool with Angular to merge the translation from the templates generated from ng xi18n with the translation generated from the code with locl[1] and later run xliffmerge[2][3] to generate all the other languages translation file meanwhile doing a merge.

It happen that for few translation I have the ID defines in the code with $localize and in the template with the directive i18n, when I try to merge two files with this tool and the ID exists in both, we get this error message:

Initial file src/translations/messages-template.xlf
trans-unit sections/navbar.brand
already present content: 
differs in file src/translations/messages-code.xlf : BRAND-NAME
Error: Translations mismatch at trans-unit ID: sections/navbar.brand. File name: src/translations/messages-code.xlf.
    at fail (/var/www/node_modules/xlf-merge/merge-xlf.js:3:15)
    at module.exports (/var/www/node_modules/xlf-merge/merge-xlf.js:73:17)
    at runMerge (/var/www/node_modules/xlf-merge/index.js:19:18)
    at Object.<anonymous> (/var/www/node_modules/xlf-merge/index.js:41:5)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)

It would be great if is possible to set a precedence to override one ID with another, or only throw error or better a warning, if ID are equal but translation different.

Thanks

[1] https://github.com/loclapp/locl/tree/master/libs/cli
[2] https://github.com/martinroob/ngx-i18nsupport/tree/master/projects/xliffmerge
[3] https://github.com/martinroob/ngx-i18nsupport/wiki/Tutorial-for-using-xliffmerge-with-angular-cli

enhancement: merge source files

Hello,

I would like to merge 2 source files, but unfortunately I have an error because there is no inside a source file.
Do you think you could remove this verification?

Thanks!

Calling push on 'undefined' when XLIFF file contains empty body

Hello,

when I try to merge with a file which has an empty body tag I get the following error:
TypeError: Cannot read property 'push' of undefined.

It seems to happen here:
https://github.com/jaroslavsvak/xlf-merge/blob/master/merge-xlf.js#L76

According to the XLF 1.2 spec the body may contain "Zero, one or more , , elements, in any order." (http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#Specs_Elem_Struct).

This happens because we auto-generate files from a library which might produce empty XLIFF files. Those files we try to merge to one afterwards.

Thanks for looking into this ๐Ÿ‘

Merging multiple files from different locations

Hello,
I'm trying to merge multiple xlf files into one file. If all of the source xlf files are located in the same directory, the xlf-merge works fine. But let's say I have sub-directories under the location which I set as input parameter to xlf-merge command, the command only merges the files which are located under the input parameter. It doesn't make any actions to the files which are located under sub-directories.

I have a directory structure like below;
src/localization/app/first.en.xlf
src/localization/app/second.en.xlf
src/localization/app/login/third.en.xlf

and I run the command below:
xlf-merge src/localization/app/*.en.xlf -o src/localization/messages.en.xlf

All I want is; find all the *.en.xlf files under app directory (including sub-directories) and merge these files into one xlf file which is "messages.en.xlf" under "src/localization/" directory.

Now It only merges the files under app directory only, doesn't include the files which are located under sub-directories of "app" directory. (Doesn't include the xlf file under the "login" folder.)

Can you please help me about this issue?

King Regards,
Turgut

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.