So i have a angular 11 application where i just implemented localization with angulars default i18n middleware.
To create an initial file i just ran :
ng extract-i18n myprojectName --format xlf --output-path src/i18n --out-file messages.da.xlf --progress
all was good and i got an messages.da.xlf file with default language translations.
Now i wanted to translate the application to english.
I copied messages.da.xlf file and named it messages.en.xlf and translated everything.
Everything is great an working right now.
But now i have an issue, next time i add an additional text to be translated english translation is not updated.
So my question is when i need to extend translation because of new features in the application how do i know which additional "fields" i have to add to all translation files and if there is a way to do it automaticaly?
There is no built-in way of doing this in Angular so you need a 3rd party tool. The only free tool that I have found is the now unmaintained Xliffmerge. The documentation is targeting older versions of Angular but after some experimentation I found that it’s enough to install the
@ngx-i18nsupport/tooling
package:Then we can add new languages to the configurations in angular.json under
projects -> projectName -> architect -> xliffmerge
.After adding new translations we can extract them and migrate them to our translation files by running this script:
We get a couple of warnings running the script which tells us its working!
I have written more about this on my blog.