Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updates to i18n translation files in Angular

I am currently in the process of adding en locale to an Angular App we are using at my company. After some thinking we decided to go with the Angular 5+ native i18n support.

From how I understand it however, everytime the translation file is generated with ng xi18n --outputPath src/locale/ --locale en a new file is created. This means, that every time a new i18n tag is added, the previous XLF file which already contains the old translations, needs to be merged with the new translations.

This seems highly bothersome, therefore my question: Is there a way such that the new trans-units are just appended to the already existing XLF file? Or is there already a tool which can merge these two together?

like image 422
seBaka28 Avatar asked Apr 05 '18 15:04

seBaka28


People also ask

What is extract i18n in Angular?

Angular Internationalizationlink Localization is the process of building versions of your project for different locales. The localization process includes the following actions. Extract text for translation into different languages. Format data for a specific locale.

Which one of the following Angular CLI commands will extract the marked text for translation in the application and create a translation source file?

After you prepare a component for translation, use the extract-i18n Angular CLI command to extract the marked text in the component into a source language file.


1 Answers

Edited answer

You can use the xliffmerge tool. It can merge translation files after you've added new translations in your html

Here is a tutorial for angular

Basically after running your normal extract command you call xliffmerge and pass the language(s) for which you want to generate translation files

ng xi18n --outputPath src/locale/ --locale en && xliffmerge --profile xliffmerge.json en fr

You can specify a json config for the tool

{
  "xliffmergeOptions": {
  "srcDir": "src/locale",
  "genDir": "src/locale"
   }
}

Original answer

Try setting custom ids to your translations

https://angular.io/guide/i18n#set-a-custom-id-for-persistence-and-maintenance

<h1 i18n="@@introductionHeader">Hello i18n!</h1>

Nex time you run the extract command, it'll just add the new blocks but won't touch the existing ones

Btw I think going with the native option is a good choice, since the maintainer of the main alternative (ngx-translate) is actually working with the angular team on the native approach

like image 60
David Avatar answered Oct 05 '22 23:10

David