11

We have recently decided to support multiple languages for our application (Angular 13.x). After researching, we decided to settle on using angular/localize package which seems great for our needs.

Everything seems to be working with the only problem of keeping the translation files upto date with subsequent builds and changes.

So following the guide here on Angular website https://angular.io/guide/i18n-common-translation-files we use ng extract-i18n cli tooling to generate a messages.xlf file

ng extract-i8n --format xlf --output-path src/locale/

The next step is copy the generate messages.xlf to different locales supported. For simplicity let's say we support french so we create a messages.fr.xlf in the same /locale subfolder. This gets translated by a third-pary service (yet to determine how to automate this - suggestions welcome). So far so good..

Now the question is around subsequent changes to the components and addition of new translations. The ng extract-18n would correctly generate the messages.xlf with the new and modified translations. But how do you update/merge the other locale files like messages.fr.xlf without overriding the existing changes? How can this be automated and the new changes be merged into this file? Am I missing something that the angular cli is already supporting?

I have come across this xliffmerge tool https://github.com/martinroob/ngx-i18nsupport/tree/master/projects/xliffmerge but this seems to be an old tool that does not seem to be supported for the newer versions of Angular past 9+.

I am assuming this is a fairly common problem for everyone and if Angular CLI is already supporting this.

Current version Angular 13.x

Thank you for your help.

jerry
  • 377
  • 3
  • 17
  • Did you find out a way to sovle this @jerry ? We are also facing this issue. – maac May 24 '22 at 11:22
  • hey @maac. Realised I was on the wrong path. We shouldn't really need to maintain the and update translation files once they are initially generated. The third party service you would be using should be able keep track of previous versions and once they return the updated file it is just a matter of updating/merging in your repo. Does that make sense? – jerry May 24 '22 at 23:41
  • Yeah we just ended up going with xliffmerge. Thank you Jerry! – maac May 25 '22 at 17:28
  • @maac how did you use `xliffmerge` with the latest version of angular? it didn't work for me.. – jerry May 25 '22 at 23:38
  • Does this answer your question? [Updates to i18n translation files in Angular](https://stackoverflow.com/questions/49675802/updates-to-i18n-translation-files-in-angular) – daniel-sc Jun 28 '22 at 07:12
  • @daniel-sc not really as i have mentioned `xliffmerge` doesn't really work for me with the latest version of angular – jerry Jul 03 '22 at 02:21
  • @jerry yes - I was referring not to the accepted (obsolete) answer but to the second answer: https://stackoverflow.com/a/70941403/2544163 – daniel-sc Jul 03 '22 at 11:05
  • @daniel-sc should work with `nx` as well right? we use `nx` for our monorepo – jerry Jul 04 '22 at 00:13
  • @jerry `nx` is not officially supported - but others reported success: https://github.com/daniel-sc/ng-extract-i18n-merge/issues/23#issuecomment-1114698586 – daniel-sc Jul 04 '22 at 09:46
  • thanks @daniel-sc did you want to post that answer here? not sure how it works.. I will accept that – jerry Jul 05 '22 at 00:40
  • The issue with "sending off the file to the translation service" is that not everyone has a translation service. Esp. smaller businesses might not have fully professional translators. For these businesses, this is a highly cumbersome step, where I do not understand, why Angular does not tackle that and offer the opportunity, to merge new and existing files. – seBaka28 Oct 14 '22 at 08:38

1 Answers1

7

An alternative/new solution (to the unmaintained ngx-i18nsupport) is https://github.com/daniel-sc/ng-extract-i18n-merge

After installing via

ng add ng-extract-i18n-merge

translations will be extracted and merged with the command:

ng extract-i18n
daniel-sc
  • 1,139
  • 11
  • 23