Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use xliff or po l10n file formats in .net (C#/ASP.Net) development

I've been researching about xliff and po i18n files formats and it seems they are widely used and supported. There are plenty of free tools to manage the translations in xliff/po files.

However, so far I could not find a good solution of how to use the xliff or po files in .net (C#/ASP.Net) projects. I would expect some sort of xliff/po => resx converter, but so far haven't found one yet.

However at the same time many tools do support the conversion of xliff/po files into java .properties format.

If you have an experience implementing l10n via xliff or po files in .Net projects - please provide advice and share the best practices on how it works.

PS: I would prefer using xliff format, since I find it cleaner and more feature-reach, but po is also an option.

like image 219
Paul Avatar asked Dec 09 '11 19:12

Paul


People also ask

How do I read an XLIFF file?

To open XLIFF files, you can use any text editor that supports the format (such as Notepad, Sublime Text, or Notepad++), use online services, or Localazy - the online translation management system explicitly made for working with translation file formats.

What is XLIFF used for?

XLIFF is an acronym that stands for XML Localization Interchange File Format. It's an XML-based format, designed in 2002, to help systematize the way localizable data is exchanged between different tools during a process known as localization.

Is XLIFF an XML?

XLIFF is an XML application, as such it begins with an XML declaration. After the XML declaration comes the XLIFF document itself, enclosed within the <xliff> element. An XLIFF document is composed of one or more sections, each enclosed within a <file> element.


3 Answers

You could also consider the i18n package by Daniel Crenna, available from nuGet. It uses PO files as its default store for localized text.

like image 95
mcw Avatar answered Oct 28 '22 11:10

mcw


PO and XLIFF files usually work differently:

  • PO files are resource files that get complied into a binary format and then accessed using gettext() libraries. Sometimes PO is used as an extraction format like XLIFF, but that is not its original purpose.

  • XLIFF are extraction files that get created by extracting your resource file (e.g. resx) into XLIFF, and then merged back into the original format.

so for XLIFF you should be looking for a tools doing resx -> xliff -> resx rather than xlif -> resx.

The tools that extract/merge XLIFF files are usually called filters. There are quite a few commercial translation tools that will accept XLIFF, and some that can also create XLIFF (Swordfish, Trados Studio, etc.).

There are also a few open-source tools that can extract/merge XLIFF: File2XLIFF4j for example (but I don't think it supports resx).

Rainbow, from the Okapi project, does support resx. The "old" .net version (Rainbow 5: Okapi on SourceForge) has a filter dedicated to resx file and can handle them very well; even with binary data. It may run into problem with third party controls though (See http://okapi.sourceforge.net/Release/Filters/Help/netres.htm for details).

The new java version (Rainbow 6: http://code.google.com/p/okapi/) support resx through its XML filter and works fine with simple resx, but if you have binary data in them the text in those entries will not be extracted.

-ys

like image 24
Yves Avatar answered Oct 28 '22 10:10

Yves


I've used PO to manage a .Net project after .resx files started getting out of hand. I used it "as an extraction format like XLIFF" (see Yves comment). Our existing .resx files were exported/merged once into one .po file per language, which then became our authoritative language files from which all the resx files would be automatically generated.

The projects I'm on aren't ASP so I don't know about the package mentioned by mcw0933, but Mono's implementation of resgen.exe has some simple po <=> resx conversion ability. However, in order to preserve existing comments and automatically add the original text as extra comments, I extended mono's conversion tool to the point where the one I use is basically rewritten.

I put the extended .po <=> .resx converter on github.

As for choosing .po to manage the translations of a C# project, .po is simple and friendly but there are some inconveniences from using it in a way that slightly differs from its original use in gettext, and I don't have the experience to say whether it was a better choice than xliff, but being able to manage translations and automate tasks was much better than dealing with the resx files, like we had been in the past.

Minor inconveniences from using PO a little differently to its intent:

  • Because gettext uses msgid to double as the field to store the original untranslated string in, I had to make resgenEx archive the original translation string into an attached comment instead of a field designed for that purpose.
  • Some tools assume the msgid will contain the original english translation (instead of just an ID string), which could mean the automatic error checking option of that tool isn't very useful, or it might mean something that makes you choose a different tool, etc. Most tools make no assumption though.
  • Some .po tools like \n instead of \r\n

The project I originally wrote resgenEx for had two .resx files and one .isl file for every supported language, but soon I'll need to manage all the translations for a .Net project that has multiple resx files for every class in the code. When this happens I'll decide whether I should keep using .po or whether I should use xliff or something else. If I keep using .po then I'll clean up resgenEx and probably need to add more features, like the ability to automatically add assembly name and class name prefixes to the msgids.

like image 38
Treer Avatar answered Oct 28 '22 09:10

Treer