Localization: Message translation service

League includes message translation service for application localization. Translation data is read from XLIFF files. Translation data in XLIFF format can be edited by large number of tools, one of them is Qt Linguist from Qt by Nokia.

Application API

Package League.Translator provides API to load translation data and to translate messages.

package League.Translator is

   function Translate
    (Compilation_Unit : League.Strings.Universal_String;
     Source_Text      : League.Strings.Universal_String;
     Disambiguation   : League.Strings.Universal_String
       := League.Strings.Empty_Universal_String)
       return League.Strings.Universal_String;
   --  Translates message.

   procedure Initialize (File : String);
   --  Loads translations from the specified file.

   procedure Finalize;
   --  Release resources.

end League.Translator;

Procedure Initialize loads translation data from the specified file and must be called before and messages are translated.

Procedure Finalize clear translation data and release all resource, it must be called once before application exit.

Function Translate translates message specified by parameter Source_Text. It returns translated message if translation data for it was loaded; otherwise it returns the same text.


Complete example is present in examples/translator directory.

with League.Strings;
with League.Translator;
with Put_Line;

procedure Hello is

   function "-"
    (Item : Wide_Wide_String) return League.Strings.Universal_String is
         (League.Strings.To_Universal_String ("HELLO"),
          League.Strings.To_Universal_String (Item));
   end "-";

   League.Translator.Initialize ("hello.xlf");
   Put_Line (-"Hello, world!");
end Hello;

Application loads translation data from the hello.xlf file, then translates 'Hello, world!' and output translated string.

Minimal content for translation data file:

<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
  <file original="hello.adb" datatype="plaintext" source-language="en" target-language="ru"><body>
    <group restype="x-trolltech-linguist-context" resname="HELLO">
      <trans-unit id="_msg1">
        <source xml:space="preserve">Hello, world!</source>
        <target xml:space="preserve">Здравствуй, мир!</target>
Last modified 10 years ago Last modified on Aug 13, 2010, 6:00:55 PM
Note: See TracWiki for help on using the wiki.