Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 511
MapLion Avatar asked Jun 14 '18 17:06

MapLion


People also ask

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.

What is extract-i18n?

Angular CLI provides extract-i18n command to extract the marked text in the component into a source language file. 2. The extract-i18n command is run from project root directory as following. ng extract-i18n. This will generate messages.

What is i18next in Angular?

i18next goes beyond just providing the standard i18n features such as (plurals, context, interpolation, format). It provides you with a complete solution to localize your product from web to mobile and desktop.

What is the use of translate in Angular?

NGX-Translate is an internationalization library for Angular. Internationalization is the process of translating an application into multiple languages. Using this library, we can translate our application language into multiple languages. This will work with not only static data, but dynamic data as well.


1 Answers

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

like image 128
user108828 Avatar answered Sep 19 '22 14:09

user108828