Changes between Initial Version and Version 1 of League/Translator


Ignore:
Timestamp:
Aug 13, 2010, 5:59:04 PM (11 years ago)
Author:
vadim.godunko
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • League/Translator

    v1 v1  
     1[[PageOutline]]
     2
     3= Localization: Message translation service =
     4
     5League includes message translation service for application localization. Translation data is read from XLIFF files.
     6
     7== Application API ==
     8
     9Package League.Translator provides API to load translation data and to translate messages.
     10
     11{{{
     12package League.Translator is
     13
     14   function Translate
     15    (Compilation_Unit : League.Strings.Universal_String;
     16     Source_Text      : League.Strings.Universal_String;
     17     Disambiguation   : League.Strings.Universal_String
     18       := League.Strings.Empty_Universal_String)
     19       return League.Strings.Universal_String;
     20   --  Translates message.
     21
     22   procedure Initialize (File : String);
     23   --  Loads translations from the specified file.
     24
     25   procedure Finalize;
     26   --  Release resources.
     27
     28end League.Translator;
     29}}}
     30
     31Procedure Initialize loads translation data from the specified file and must be called before and messages are translated.
     32
     33Procedure Finalize clear translation data and release all resource, it must be called once before application exit.
     34
     35Function 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.
     36
     37== Example ==
     38
     39Complete example is present in [source:/trunk/matreshka/examples/translator examples/translator] directory.
     40
     41{{{
     42with League.Strings;
     43with League.Translator;
     44with Put_Line;
     45
     46procedure Hello is
     47
     48   function "-"
     49    (Item : Wide_Wide_String) return League.Strings.Universal_String is
     50   begin
     51      return
     52        League.Translator.Translate
     53         (League.Strings.To_Universal_String ("HELLO"),
     54          League.Strings.To_Universal_String (Item));
     55   end "-";
     56
     57begin
     58   League.Translator.Initialize ("hello.xlf");
     59   Put_Line (-"Hello, world!");
     60   League.Translator.Finalize;
     61end Hello;
     62}}}
     63
     64Application loads translation data from the [source:/trunk/matreshka/examples/translator/hello.xlf hello.xlf] file, then translates 'Hello, world!' and output translated string.
     65
     66Minimal content for translation data file:
     67
     68{{{
     69<?xml version="1.0" encoding="UTF-8"?>
     70<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
     71  <file original="hello.adb" datatype="plaintext" source-language="en" target-language="ru"><body>
     72    <group restype="x-trolltech-linguist-context" resname="HELLO">
     73      <trans-unit id="_msg1">
     74        <source xml:space="preserve">Hello, world!</source>
     75        <target xml:space="preserve">Здравствуй, мир!</target>
     76      </trans-unit>
     77    </group>
     78  </body></file>
     79</xliff>
     80}}}