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?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With