views:

519

answers:

2

Complete C++ i18n gettext() “hello world” example shows a standard way to handle messages in a C++ program using gettext(). The message catalogs are stored in Portable Object files based upon a Portable Object Template file created directly from the C++ source code using xgettext, msginit and msgfmt. What is the corresponding method for handling messages by XSLT?

Specifically, to make C++ hello-world code support i18n one just adds two includes, calls some setup functions and wraps strings in calls to gettext():

#include <libintl.h>
#include <locale.h>
..
    setlocale(LC_ALL, "");
    bindtextdomain("hellogt", ".");
    textdomain( "hellogt");
    std::cout << gettext("hello, world!") << std::endl;
...

Then the English text is extracted from the source program and converted to a Portable Object Template for use by translators who create Machine Object message catalog files for use by the run-time program using utilities programs: xgettext, msginit and msgfmt. Finally, the Linux shell command for identifying the run-time language as Spanish is shown when the program is invoked.

The main purpose of doing a hello-world program is to connect all of the system parts to get a virtually useless example to function. So, as the C++ example shows for C++ in a Linux environment I am looking for the same thing but for XSLT instead.

  1. In the C++ example there is a set of include files and object files that are linked into hellogt. Is there code for XSLT that provides the functionality of setlocale, bindtextdomain and textdomain? How does the code connect to the user's runtime language?
  2. Is there XSLT code that provides run-time conversion from English text via message catalog files like gettext() does?
  3. Are there utility programs for extracting the Engish text from a source XML file for use by the translators along with programs to convert the results to run-time usable message catalog files like xgettext, msginit and msgfmt do?
  4. How is the identify of the user runtime language specified?

For example, I have a Javascript application, Emle, that processes XML using XSLT into HTML. The messages are defined in an application specific collection of language specific XML files. They are extracted using application specific XSLT code. Though this speaks to #2 the method does not appear to lend itself to being able to take advantage of translation services like those provided by LaunchPad. An example Emle English message file used by Emle XSLT file

+1  A: 

If non-XML tools are acceptable, then this Perl tool does the job of generating and keeping in sync a set of gettext PO files of an XML data file and its translations.

http://po4a.alioth.debian.org/man/man3pm/Locale%3A%3APo4a%3A%3AXml.3pm.php

This addresses part 3 of the question, the utility programs that provide the text for translators.
C.W.Holeman II
A: 

Please see my blog on Ektron's dev center: Localizing text in an XSLT

Doug D
Perhaps I don't quite understand the problem. Q 1. I thought you were looking to provide localization capability in XSLT. May be I'm not familiar enough with setlocale, bindtextdomain and textdomain functionality.Q 2.My blog provides an XSLT example of how to convert source language (English) to a target language where they are stored in an XML file (it doesn't have to be .resx)Q3. Is the XML file more than just the English text? If so something like the xliffRoundTrip Tool (sourceforge.net/projects/xliffroundtrip/) may help. It's written by the chair of the XLIFF cmte (xliff.org).
Doug D
The blog the answer references uses a "Microsoft .NET resource (.resx) file" convention to identify message text in an application specific manner. The question includes links to Emle code which also has such code. The question overall is about how to fit into an environment that needs to support translation efforts rather than just the XSLT code that is used in a narrow sample case. I modified the question, expanding on the hello-world nature of the question
C.W.Holeman II
When transforming using XSLT, the language must be passed as an argument. Example in .NET:System.Xml.Xsl.XsltArgumentList objXsltArgs = new System.Xml.Xsl.XsltArgumentList(); objXsltArgs.AddParam("lang", "", "fr-FR");
Doug D