18

I am using a command line tool (ng-xi18n) to extract the i18n strings from an angular 2 app I wrote. The output of this command is a messages.xlf file. Coming from a .po background, and being not familiar with .xlf, I assumed that this file is the equivalent to the .pot file (correct me if I am wrong).

I then assumed that if I want to translate my app, I had to cp messages.xlf messages.de.xlf to have a copy (messages.de.xlf) of the template file (messages.xlf) where I can translate each message into German (hence the .de.xlf).

After translating some dummy texts and running the app, I saw that it worked as expected, so I quit translating and continued developing the app. After some time, I added more i18n strings, and eventually thought that I had to update my template. And this is where things got hardly maintainable. I updated the template messages.xlf file, and quickly was wondering how I could update the new strings to my already translated messages.de.xlf file without loosing my progress.

When I was developing using .po files, this was no problem thanks to good tools like poEdit, but I didn't find anything comparable for .xlf. After trying some tools, I thought that the best choice would be Lokalize, but I didn't find a possibility to merge the template file to already translated (but outdated) files either.


Up to now, this was rather an essay than a question, so here's a quick summary:

  • Is the workflow of dealing with .xlf files really comparable to .po as I initially thought (described above), or is it completely different?
  • How am I suppose to update my already translated files?
  • What are the best practices dealing with .xlf files?
  • What are proof of concept tools to work with .xlf?

Sidenotes:

  • The Lokalize handbook was not helpful at all. I see a lot of functions that sound promising, like:
    • "File" > "Update file from template". I did not find anything in the handbook to explain this function. If I click on this, nothing happens.
    • "Sync" > "Open file for sync/merge". This seems to be a function to merge two similar files (by multiple translators) rather than a tool to update the translation file from a template. Even though there is a tooltip in Lokalize's primary sync tab, notifying me about "x unmatched entries", I just couldn't find anything to append those unmatched entries to my .de.xlf file.
    • [Update] Turns out, I had similar issues as in this question. After downgrading my version of Lokalize to the suggested one, many issues (including the ones mentioned in the question) disappeared. However, now the "Update file from template" option is greyed out, and I don't know why.
  • I also tried OmegaT, which does not work at all on my platform (Ubuntu 16.04).
  • [Update] Virtaal works great for merging new strings from a template, but the UI in general is very poorly designed...
  • Googling did not help, as every hit seems to be related to XCode or something.

Thanks for any help in advance, I really appreciate it

Community
  • 1
  • 1
CharlyDelta
  • 938
  • 11
  • 31
  • 1
    Regarding `ng-xi18n`: This is neither an helpful addition to the question, nor an answer to this question, so I'll just add this into the comments. As it turns out, the `ng-xi18n` cli tool has a option (which is not correctly working as I am writing this) to generate `.xlf` files for any language. So there is no need for a template file. See [here](https://github.com/angular/angular/issues/9104#issuecomment-245337147) for more information. Just wanted to add this in case someone finds this answer and specifically needs a solution for `ng-xi18n` – CharlyDelta Sep 07 '16 at 18:59
  • Regarding `ng-xi18n` update: A MR for i18n documentation was opened earlier today: https://github.com/angular/angular.io/pull/2309 – CharlyDelta Sep 12 '16 at 08:54
  • Can you give any more info about what happened with OmegaT? It requires Java, but should be working on 16.04. – Chase T Oct 10 '16 at 17:43
  • The problem is, that I can't even make a new project. As soon as I click on the button to choose a folder, OmegaT completely freezes. I can't even force-quit OmegaT then. `java -version` output: `$ java -version java version "1.7.0_101" OpenJDK Runtime Environment (IcedTea 2.6.6) (7u101-2.6.6-0ubuntu0.15.10.1) OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode) ` – CharlyDelta Oct 11 '16 at 08:10
  • Btw, if I start OmegaT from command line using `omegat`, there will be no error in the console. It just freezes silently – CharlyDelta Oct 11 '16 at 08:16
  • I've got exactly the same question as you. Have you been able to find a proper workflow to automate this? – Boland Oct 12 '16 at 08:28
  • Well, not really, to be honest... There are no good tools to translate xlf, and `ng-xi18n` does not have the features I expect. (even one dev claimed that `ng-xi18n` has an option for generating multiple translation files, I have not found anything related to that.) it seems that you can only generate the `messages.xlf` file, and you need to merge __everything__ manually to your existing translation files (due to lack of working tools). – CharlyDelta Oct 12 '16 at 10:05

3 Answers3

18

I wrote a small npm command line tool called xliffmerge. In principle it does the same, that Roland Oldengarm does with his gulp tasks described in his blog article. It is free and you can have a look at it at https://github.com/martinroob/ngx-i18nsupport#readme

Martin Roob
  • 266
  • 3
  • 4
  • 1
    If you could provide installation & short usage information here in addition to the link, it would be easier for the users as they don't need to click the link for the most trivial information. – kabirbaidhya Feb 27 '17 at 18:53
  • xliffmerge is a fantastic tool and provides a service missing from angular-ci! – luvaas Oct 18 '17 at 21:01
  • +1 for xliffmerge! I got "command not found" after installing via yarn. In case anyone else does, here's a workaround: https://github.com/martinroob/ngx-i18nsupport/issues/77 – Matt Rabe Apr 09 '18 at 20:29
1

The best workflow automation solution I have seen described so far is from Roland Oldengarm's blog entry "Angular 2: Automated i18n workflow using gulp". To summarize, in a few dozen lines of Gulp code he created the tooling to handle some of the challenges you faced. Specifically it runs ng-xi18n to extract the messages; creates an English translation with sources copied to targets; updates existing translations by adding new trans-units, keeping existing ones, and removing missing ones; and then exposes all xlf files as TypeScript string constants. These last strings can then be imported to supply the bootstrapModule with its translation provider options.

Caveat: I have not used this exact solution (and code) myself, but I was able to expose generated xlf as TypeScript strings and use them in an app in a manner similar to what he described. As for maintaining translations, I have leveraged IntelliJ IDEA (WebStorm) file comparison features and Counterparts Lite (for Mac) for that. My own efforts are still in early stages but are working end to end for an application that is in active development.

Will
  • 6,601
  • 3
  • 31
  • 42
  • First of all, thanks for your answer. Currently I don't have time to verify how well it works, but as soon as I will come to it, I will consider making this the accepted answer if it works as promised :) sounds really good in theory – CharlyDelta Dec 16 '16 at 17:42
  • Sure thing. I updated my answer to clarify which ideas from the blog I have leveraged successfully myself. – Will Dec 16 '16 at 18:18
  • Thank you very much and please excuse the delay – CharlyDelta Dec 17 '16 at 16:45
  • 1
    @Will 404 Web Site not found for the "Angular 2: Automated i18n workflow using gulp" link. – vvahans Mar 29 '18 at 19:35
  • Thanks @VahanVardanyan, just updated with link to archive – Will Mar 30 '18 at 18:09
-3

Official Angular docs are now updated for Internationalization (i18n) at https://angular.io/docs/ts/latest/cookbook/i18n.html including a section specifically for creating a translation source file with the ng-xi18n tool.