Extract and merge i18n xliff translation files for angular projects.

Overview

npm Coverage Status Language grade: JavaScript

Angular extract i18n and merge

This extends Angular CLI to improve the i18n extraction and merge workflow. New/removed translations are added/removed from the target translation files. Additionally, translation files are normalized (pretty print, sorted by id) so that diffs are easy to read (and translations in PRs might actually get reviewd ;-) ).

Install

Prerequisites: i18n setup with defined target locales in angular.json - as documented here.

ng add ng-extract-i18n-merge

Usage

ng run [PROJECT_ID]:extract-i18n-merge
# or (if you confirmed to adding an npm command):
npm run extract-i18n-merge 

Configuration

In your angular.json you'll find a new target extract-i18n-merge that can be configured with the following options:

Name Default Description
format Inferred from current setup by ng add Any of xlf, xlif, xliff, xlf2, xliff2
outputPath Inferred from current setup by ng add Path to folder containing all (source and target) translation files.
targetFiles Inferred from current setup by ng add Filenames (relative to outputPath of all target translation files (e.g. ["messages.fr.xlf", "messages.de.xlf"]).
sourceLanguageTargetFile Unused If this is set (to one of the targetFiles), new translations in that target file will be set to state="final" (instead of default state="new").
sourceFile messages.xlf. ng add tries to infer non default setups. Filename (relative to outputPath of source translation file (e.g. "translations-source.xlf").
removeIdsWithPrefix [] List of prefix strings. All translation units with matching id attribute are removed. Useful for excluding duplicate library translations.
fuzzyMatch true Whether translation units without matching IDs are fuzzy matched by source text.
resetTranslationState true Reset the translation state to new/initial for new/changed units.
collapseWhitespace true Collapsing of multiple whitespaces and trimming when comparing translations sources.
includeContext false Whether to include the context information (like notes) in the translation files. This is useful for sending the target translation files to translation agencies/services.
newTranslationTargetsBlank false When false (default) the "target" of new translation units is set to the "source" value. When true an empty string is used.

Contribute

Feedback and PRs always welcome :-)

Comments
  • Unexpected results / modification of existing xlf files

    Unexpected results / modification of existing xlf files

    Hey so I have been trying ng-extract-i18n-merge to see wether it can replace the old @ngx-i18nsupport/tooling (using 9 locales), but I ran into some problems.

    Installation & Configuration went fine, but when I first executed it I got the following results:

    angular.json image

    package.json "i18n-extract-merge": "ng build && ng run xxx:extract-i18n-merge",

    1)Already translated texts in state=translated were overritten 2)Order / Structure of .xlf files was completely modified

    Example: As you can see the english word "Sender" was already translated to the german word "Absender" and it went from line 1388 to line 11

    image

    Is there any way to keep the existing translations by modifying the state attribute or via configuration?

    3)FuzzySearch = true resulted in many mismatches mixing source & target of multiple texts

    bug 
    opened by Giusti 10
  • Context doesn't get added/updated

    Context doesn't get added/updated

    Hey there,

    first of all thanks for making this script, it really helped me to migrate from xliffmerge.

    I've discovered a little bug that I'd like to report when using "includeContext": true,. If you change the location of a "i18n" tag or add a new one with the same value than an existing one it doesn't seem to merge the updated to the <note category="location"> tags correctly.

    Here's a scenario to describe the issue better:

    1. Move a row with "i18n" tag in an html file
    2. Run the ng-extract-18n-merge script
    3. Changes in messages.xlf: - <note category="location">src/app/app.component.html:31</note> + <note category="location">src/app/app.component.html:32</note>
    4. Changes in messages.de.xlf: none

    It should also reflect the changes in messages.de.xlf, right?

    I've looked at the source code but wasn't able to fix it with a pull request yet.

    bug enhancement 
    opened by madmurl0c 8
  • Additional logging //

    Additional logging // "Merge and normalize" step hangs

    Is there a way to show additional logging during the merge? I'm running this program on my existing translation base (+/- 3500 translations; merged before with xliffmerge, moved to this due to the console error) and it takes >10 min and is still not finished. I'd like to know if it crashed on something or if it is still trying its best.

    bug question 
    opened by TTvanWillegen 7
  • angular i18n config without baseHref is not recognized correctly

    angular i18n config without baseHref is not recognized correctly

    Hi, thank you for providing a new package!

    I am still using this to translate my strings. However, it seems that this tool does not pickup new or changed translations since I switched to ng-extract-i18n-merge.

    What do you use for actual translating?

    regards,

    Philipp

    bug 
    opened by Hafnernuss 7
  • Space trimming

    Space trimming

    Looks like extract-i18n-merge command trims spaces, but extract-i18n don't. I have cases when i don't need to trim them. Screenshot 2022-05-09 at 21 14 51

    <span
      class="link-ghost"
      i18n="Phone Verification"
    > Change</span>
    

    I have a space before Change. But as a result i have:

    <trans-unit id="ba3ab8408e0985aaa20a3c83f77a8bc336a96ae4" datatype="html">
      <source>Change</source>
      <context-group purpose="location">
        ...
      </context-group>
      <note priority="1" from="description">Phone Verification</note>
    </trans-unit>
    

    May be there is any extra config except collapseWhitespace? "ng-extract-i18n-merge": "^1.4.0",

    bug 
    opened by YehorLitsov 6
  • newTranslationTargetsBlank omit does not work

    newTranslationTargetsBlank omit does not work

    Describe the bug When adding new strings for translations with the setting "newTranslationTargetsBlank": "omit", I get the following error Cannot read property 'attr' of undefined

    Setup/Configuration

    "extract-i18n-merge": {
              "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",
              "options": {
                "browserTarget": "digital-intake:build",
                "format": "xlf",
                "includeContext": false,
                "newTranslationTargetsBlank": "omit",
                "outputPath": "apps/digital-intake/src/locale",
                "sourceLanguageTargetFile": "messages.en.xlf",
                "targetFiles": ["messages.en.xlf", "messages.es.xlf"]
              }
            },
    

    If a translate unit doesn't exist this fails

    Expected behavior I expect the new translations to merge without the target element

    Screenshots If applicable, add screenshots to help explain your problem.

    Version (please complete the following information):

    • Angular: 13.0.4
    • OS: Mac
    • nodejs: 14.17.0
    • ng-extract-i18n-merge version: 2.0.0 - 2.1.2

    Additional context My translator has requested that I proved the new strings without the target

    bug 
    opened by davidyoung77 4
  • Setting includeContext to false removes the context from the angular generated messages file

    Setting includeContext to false removes the context from the angular generated messages file

    Is your feature request related to a problem? Please describe. Setting "includeContext": false, to false removes the context from the Angular generated file

    Describe the solution you'd like Merge should not touch the Angular generated file

    Describe alternatives you've considered

    Additional context I want to remove the location context from the merged files but leave it in the angular generated file

    enhancement 
    opened by davidyoung77 4
  • Whitespaces not trimmed properly?

    Whitespaces not trimmed properly?

    Describe the bug I am not sure if it's a bug as I am not sure I fully know if this is intended behaviour or not. I get a lot of warnings like this: image

    Where some of the lines look like that:

    <button class="col-4 btn w-100 btn-primary block" type="submit" (click)="onLogin()" i18n="Login|Auth@@Login">
        Login
    </button>
    

    This causes the translator to pick the string up as " Login " rather than "Login". Funny enough, the translation units seem to look "as expected": <source>Login</source>

    Setup/Configuration

    "extract-i18n": {
              "builder": "ng-extract-i18n-merge:ng-extract-i18n-merge",
              "options": {
                "browserTarget": "sportsense-tms:build",
                "format": "xlf",
                "collapseWhitespace": true,
                "trim": true,
                "includeContext": true,
                "outputPath": "src/locale",
                "targetFiles": [
                  "messages.en.xlf",
                  "messages.de.xlf"
                ]
              }
            }
    

    and some translations like:

      <button class="col-4 btn w-100 btn-primary block" type="submit" (click)="onLogin()" i18n="Login|Auth@@Login">
        Login
      </button>
    

    and

    <button class="btn btn-primary" (click)="onLogin()" id="login" i18n="Login|ResetPassword@@Login">Login</button>
    

    Expected behavior No warnings

    Version (please complete the following information):

    • Angular: 13
    • ng-extract-i18n-merge version: 2.1.2

    Additional context angular issue

    bug 
    opened by Hafnernuss 4
  • Cannot read properties of undefined (reading 'attr')

    Cannot read properties of undefined (reading 'attr')

    Hi, I faced issue if destination file is not empty. "@angular/core": "14.0.2", "ng-extract-i18n-merge": "^2.0.1",

    https://www.screencast.com/t/Wn8dB1QxvVP2

    bug 
    opened by Khokhlachov 4
  • Give a hint if the same ID occurs more than once

    Give a hint if the same ID occurs more than once

    During a faulty merge in our source versioning system, duplicate ID's occurred in the messages files for one language. This condition was not detected for a long time and led to a long search for causes on different levels before the problem was found in duplicate message IDs.

    I know the angular property "i18nDuplicateTranslation" but this doesn't seem to give a warning or error message here either.

    Would it be possible to integrate a check for duplicate ID's?

    opened by ftaffelt 3
  • includeContext removes multiple context-group

    includeContext removes multiple context-group

    First. Thank you for this plugin!!!

    I think I found a lil bug. I had the same text to translate in multiple components and noticed that it was only translated in one of the components. It seems angular uses context-groups to translate multiple components. I used "includeContext": true to fix this but found the following even without it.

    For example this is the original messages.xlf:

    <trans-unit id="1547876271716599756" datatype="html">
            <source>Impressum</source>
            <context-group purpose="location">
              <context context-type="sourcefile">src/app/app-routing.module.ts</context>
              <context context-type="linenumber">12</context>
            </context-group>
            <context-group purpose="location">
              <context context-type="sourcefile">src/app/app.component.html</context>
              <context context-type="linenumber">4</context>
            </context-group>
          </trans-unit>
    

    and this is what the plugin generates:

    <trans-unit id="1547876271716599756" datatype="html">
            <context-group purpose="location">
              <context context-type="sourcefile">src/app/app-routing.module.ts</context>
              <context context-type="linenumber">12</context>
            </context-group>
            <source>Impressum</source>
            <target state="translated">Imprint</target>
          </trans-unit>
    

    I would also recommend to set "includeContext": true as default in the plugin if I did not miss anything here.

    Thank you!

    bug question 
    opened by brokolja 3
  • Additional collaborators wanted

    Additional collaborators wanted

    I intend to maintain this library over the coming years.

    Since I have other things to do as well, this can only be done on a "best effort" basis. This is probably enough to keep everything up to date. To shorten response times and consistently provide fixes/updates in a timely manner, I'd like to invite other contributors. This should sustain the development.

    I'm not totally sure about a meaningful "process", but I'd like to have some contributions before adding a contributor to readme and giving repository rights.

    Please comment if you are interested or have other/further ideas! :)

    help wanted 
    opened by daniel-sc 0
  • Usage with Nx

    Usage with Nx

    Hello,

    Could it be possible to support Nx by at least be able to handle both angular.json and workspace.json ? I'm using a workspace.json file instead of angular.json and target extract-i18n-merge is not added when installing ng-extract-i18n-merge package, so I can't use that command.

    yarn ng add ng-extract-i18n-merge
    

    produces

     NX   Cannot find project 'ng-extract-i18n-merge'
    

    and

    yarn run [PROJECT_ID]:extract-i18n-merge
    yarn nx run [PROJECT_ID]:extract-i18n-merge
    

    produces

    NX   Cannot find target 'extract-i18n-merge' for project [PROJECT_ID]
    

    Thanks

    enhancement help wanted 
    opened by danjor 3
Releases(v2.4.0)
  • v2.4.0(Nov 2, 2022)

    • feat: adding 'verbose' debug output option - fixes #56 c06ec69
    • fix: acceptable performance for fuzzy matching/merging many elements - fixes #56 5c018dc

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v2.3.0...v2.4.0

    Source code(tar.gz)
    Source code(zip)
  • v2.3.0(Oct 24, 2022)

    • fix: updating/adding changes in notes - fixes #50 963c3b2
    • feat: support angular 15 48134a1 fixes #52

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v2.2.0...v2.3.0

    Source code(tar.gz)
    Source code(zip)
  • v2.2.0(Sep 7, 2022)

    • feat: adding option "sourceFileOnly" to config "includeContext" 9cb191a
    • chore: correct github repository link 55f2ed7

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v2.1.2...v2.2.0

    Source code(tar.gz)
    Source code(zip)
  • v2.1.2(Jul 20, 2022)

    • fix: gracefully handle non-existent target nodes b4df315
    • fix: do not change translation state for changes only in collapsible whitespace

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v2.1.1...v2.1.2

    Source code(tar.gz)
    Source code(zip)
  • v2.1.1(Jul 1, 2022)

  • v2.1.0(Jun 22, 2022)

    • feat: auto create missing target files #36
    • fix: support angular 14 #37

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v2.0.1...v2.1.0

    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(Jun 16, 2022)

    • Fix: handle missing messages.xlf (Big thanks to @strout! See #34 #35)

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v2.0.0...v2.0.1

    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(May 31, 2022)

    Breaking changes:

    • Now this plugin uses the default angular "extract-i18n" target - so you can (must) simply run ng extract-i18n! (#30)
    • Default sort is now "stableAppendNew" (was: "idAsc") (#26).
    • Leading/trailing whitespaces are normalized (i.e. collapsed to one space) but not completely trimmed (#28).
    • Npm run script is removed (you can create a manual npm run script of course).

    Full Changelog: https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.4.0...v2.0.0

    Source code(tar.gz)
    Source code(zip)
  • v2.0.0-0(May 16, 2022)

    • feat: change default sort behaviour to "stableAppendNew", as this keeps the order for units with implicit ID. eff3cad
    • fix: retain leading/trailing whitespaces of translation sources/targets 14edd03

    BREAKING CHANGES:

    • To retain the previous sort behavior set option sort: "idAsc".
    • Leading/Trailing whitespaces can lead to visible changes. If in doubt, check and remove whitespaces in your template files.

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.4.0...v2.0.0-0

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(May 9, 2022)

  • v1.3.0(Apr 26, 2022)

    • feat: sync source to target for untranslated units 47a6ed1
    • feat: new configuration to skip target element creation for new translation units bac779e

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.2.3...v1.3.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.3(Apr 11, 2022)

  • v1.2.2(Mar 24, 2022)

    • fix: option "sourceLanguageTargetFile" should auto update targets ced319d
    • fix: retain whitespace between consecutive interpolated statements 720eed2

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.2.1...v1.2.2

    Source code(tar.gz)
    Source code(zip)
  • v1.2.1(Mar 23, 2022)

    • fix: non-default "sourceFile" was not used for extraction 0bbe019

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.2.0...v1.2.1

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Mar 22, 2022)

    • feat: add option "sourceFile" to handle non-default messages.xlf filename 007502c
    • feat: add option "sourceLanguageTargetFile" to specify source language b03cfb7

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.1.0...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Mar 16, 2022)

    • chore: assure releases always contain up-to-date build cc45e47
    • feat: add option newTranslationTargetsBlank e0ac933

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.0.5...v1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.5(Mar 11, 2022)

    • chore: switch to .npmignore for granular package control a4086d5
    • fix: correct extraction of xliff version from translation file - relates #6 6944a9f
    • fix: handle all angular i18n config variants - fixes #6 4ca6591

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.0.4...v1.0.5

    Source code(tar.gz)
    Source code(zip)
  • v1.0.4(Mar 10, 2022)

    • fix: handle xml declaration without new line - fixes #4 2a63c4b

    Full Changelog: https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.0.3...v1.0.4

    Source code(tar.gz)
    Source code(zip)
  • v1.0.4-0(Mar 10, 2022)

    • fix: handle xml declaration without new line - fixes #4 2a63c4b

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.0.3...v1.0.4-0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.3(Mar 9, 2022)

    What's Changed

    • fix translation string config in https://github.com/daniel-sc/ng-extract-i18n-merge/pull/4 - see #3

    Full Changelog: https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.0.2...v1.0.3

    Source code(tar.gz)
    Source code(zip)
  • v1.0.3-0(Mar 9, 2022)

    • fix: ng add not possible if translation config is of type string (instead of array) - fixes #3 72b4078

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.0.2...v1.0.3-0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.2(Mar 2, 2022)

    • bump xliff-simple-merge version - fixes #2 (second try) 56e6862

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.0.1...v1.0.2

    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Feb 18, 2022)

    • bump xliff-simple-merge version - fixes #2 71b332d
    • more unit tests 8fa3469
    • update docs 9e3ae5d

    https://github.com/daniel-sc/ng-extract-i18n-merge/compare/v1.0.0...v1.0.1

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Jan 31, 2022)

Owner
Daniel Schreiber
Daniel Schreiber
The alternative internationalization (i18n) library for Angular

NGX Locutus The alternative Angular Translation Library used for large scale microfrontend translations. No more worrying about shared translation ass

Stefan Haas 9 May 31, 2022
ICU MessageFormat for Javascript - i18n Plural and Gender Capable Messages

messageformat The experience and subtlety of your program's text can be important. Messageformat is a mechanism for handling both pluralization and ge

null 1.6k Dec 23, 2022
ICU MessageFormat for Javascript - i18n Plural and Gender Capable Messages

messageformat The experience and subtlety of your program's text can be important. Messageformat is a mechanism for handling both pluralization and ge

null 1.6k Dec 23, 2022
human friendly i18n for javascript (node.js + browser)

BabelFish - human friendly i18n for JS Internationalisation with easy syntax for node.js and browser. Classic solutions use multiple phrases for plura

Nodeca 246 Nov 20, 2022
Internationalization for react done right. Using the i18next i18n ecosystem.

react-i18next IMPORTANT: Master Branch is the new v10 using hooks. $ v10.0.0 npm i react-i18next react-native: To use hooks within react-native, you m

i18next 7.9k Dec 30, 2022
Gettext Style i18n for Modern JavaScript Apps

Jed Gettext Style i18n for Modern JavaScript Apps For more info

null 879 Dec 14, 2022
Type-safe internationalization (i18n) for Next.js

Type-safe internationalization (i18n) for Next.js Features Usage Examples Scoped translations Change current locale Use JSON files instead of TS for l

Tom Lienard 251 Dec 22, 2022
lightweight jQuery plugin for providing internationalization to javascript from ‘.properties’ files

jQuery.i18n.properties About jQuery.i18n.properties is a lightweight jQuery plugin for providing internationalization to javascript from ‘.properties’

null 408 Dec 25, 2022
🌍📖 A readable, automated, and optimized (5 kb) internationalization for JavaScript

Linguijs ?? ?? A readable, automated, and optimized (5 kb) internationalization for JavaScript Documentation · Documentation 2.x · Quickstart · Exampl

Lingui 3.5k Jan 2, 2023
Powerful, intelligent and easy to use Figma internationalisation scripts

Powerful, intelligent and easy to use Figma internationalisation scripts English | 中文 ?? Script Installation Before installing the Figma I18n script,

Afeyer 138 Dec 10, 2022
Merges XLIFF 1.2/2.0 files. Usable for Angular i18n automation.

XLIFF Simple Merge This program automates the merging of XLIFF files (version 1.2 and 2.0). New translations from the input file (e.g. "messages.xlf")

Daniel Schreiber 9 Dec 15, 2022
i18n-language.js is Simple i18n language with Vanilla Javascript

i18n-language.js i18n-language.js is Simple i18n language with Vanilla Javascript Write by Hyun SHIN Demo Page: http://i18n-language.s3-website.ap-nor

Shin Hyun 21 Jul 12, 2022
Tool for GitHub/GitLab to keep Repositories/Projects you are interested in and their Pull/Merge Requests in desktop Tray Menu

Tool for GitHub/GitLab to keep Repositories/Projects you are interested in and their Pull/Merge Requests in desktop Tray Menu. More info in User Guide.

Oleksii Bilyk 5 Jul 31, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Bys is an npm/yarn library to merge your js and ts files into one file.

Bundle your scripts (bys) Bys is an npm/yarn library to merge your js and ts files into one file. Installation Use the npm or yarn package manager to

FlamesX128 3 Dec 8, 2022
Merge multiple JSON files - Vanilla JavaScript and HTML (graphic mode: browser+explorer)

JSON Merger Usage First, git clone project git clone https://github.com/mtacnet/json-merger.git Move to cloned repository and open generate.html with

Tac 1 Sep 18, 2022
Merge multiple Prisma schema files, model inheritance, resolving name conflicts and timings reports, all in a simple tool.

Prisma Util What is Prisma Util? • How to use? • The configuration file • Support What is Prisma Util? Prisma Util is an easy to use tool that merges

David Hancu 21 Dec 28, 2022
Tool made to easily merge multiple GTA 5 vehicle meta files.

mmVehiclesMetaMerger Tool made to easily merge multiple GTA5 vehicle meta files. Showcase Go to Youtube video. Download Click here to go to the releas

Mateusz Mleczek 11 Jan 2, 2023