Angular 6: i18n: How to update an existing .xlf file that has already been translated?
Asked Answered
S

2

14

In Angular 6, now that I think I comprehend how to make the i18n files and utilize them (e.g. https://angular.io/guide/i18n), I am wondering about maintenance of said files. If I go in and change the html, as I understand it, I would have to regenerate the messages.xml file using the ng xi18n command, which then implies that I would be required to retranslate the file into the other languages or, at the very least, do some kind of visual matching so I can move the content of some div tag to its new location into the new file from the old, already translated, file. This seems to be a lot of overhead to maintain changes and I hope I am missing something, but is this the intended workflow for maintaining the files? Is the following correct [I'm hoping not], or is there a better way that I am unaware of?

Creation:

  1. generate messages.xlf with ng xi18n command
  2. copy and rename messages.xlf => messages.fr.xlf
  3. open messages.fr.xlf, copy the content between the tags and paste it underneath, then rename source => target and then translate the content into a new language (e.g. French)

Maintenance:

  1. after making changes to the html and/or content, regenerate messages.xlf with ng xi18n command
  2. make a copy of messages.xlf and rename it (e.g. messages.fr2.xlf)
  3. open messages.fr.xlf and try to discern what can be copied over to messages.fr2.xlf and then delete messages.fr.xlf and rename messages.fr.xlf??? Repeat for all languages???

Is there a command or tool I am missing that will help me match up the persistent ids I put in the i18n tags (e.g. i18n="@@myUniqueTag") so I can move translated targets (e.g. <target>my translated content</target>) automatically to the new file? Or do I really have to manually move all of my targets to the new file and match them up with each source tag?

Strophe answered 14/6, 2018 at 17:17 Comment(1)
This is a duplicate question to #49676302Schultz
S
2

I ended up making a solution for myself until something better comes along: https://github.com/maplion/angular6-i18n-helpers

So far, it is working pretty well for me.

Strophe answered 27/6, 2018 at 15:23 Comment(2)
Hi, May I know which Angular version did you used when developing this tools? Is it compatible for Angular 14 project?Afghan
@Welly林經緯 This was done in Angular 6; it was made to be generic javascript, so it should work with Angular 14 because I don't think the xliffs have changed, but it is untested.Strophe
R
2

You can use ngx-i18nsupport. It uses xliffmerge to merge translation files automatically after running ng xi18n.

Rattoon answered 30/8, 2018 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.