comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm-host.bauhaus@maps.futureapps.de>
Subject: Re: Internationalization for Ada
Date: Sat, 12 Dec 2009 13:17:57 +0100
Date: 2009-12-12T13:18:01+01:00	[thread overview]
Message-ID: <4b2389f9$0$7631$9b4e6d93@newsspool1.arcor-online.net> (raw)
In-Reply-To: <7cdd6689-077e-4438-a493-428823bb1ee2@k19g2000yqc.googlegroups.com>

On 12/12/09 10:23 AM, Ludovic Brenta wrote:
> vlc wrote on comp.lang.ada:
>> Hi *,
>>
>> Is there a preferred way for internationalization in Ada 2005 - like
>> GNU gettext for GNU/Linux? If anyone has experience with this topic, I
>> would be glad for a link which directs me into the right direction,
>> also if there is something special for GtkAda.
>>
>> Thanks a lot in advance!
>
> See the package GtkAda.Intl in GtkAda.

GtkAda's binding to libintl/GNU gettext seems the obvious choice
in this case.  There is, however, another mode of handling text
that benefits from the Ada type system.  The two can in fact
be combined to yield an enhancement.

One way to distinguish a message from a menu text from a button
text from a log entry template text or ... is to ignore their
difference and make them all string literals, then inspect
their context, and possibly follow some preprocessing
conventions so that tools outside the language can
hopefully set up a database---non-standard, though widespread
in its niche---of strings to be loaded.

You wouldn't be doing this to whole numbers in Ada,
would you?  The obvious choice is to define different types
of numbers for your different numbers.
Or to think even harder about what you can do to go
from one "measurements unit locale" to another, in case
the numbers represent quantities of a certain type.

The pieces of text just enumerated belong to different sets of
entities, part of different behavior of the program, serving
different functions (labels, help text, log entries).
Aren't they be worth a type?  The text types will then serve
two purposes:

1 - distinguish the different kinds of information that now
happen to be represented(!) as objects of type string.

2 - use standard Ada programming to produce translation files
guided by the text types.

Don't know, though, whether there isn't too big a blind spot
here.

The point is, you use plain Ada tools to

(1) search your program for just the instances of text you want,

(2) make the findings available in a format of some
translation tool, e.g. Gtk's or Qt's translation tools
(The latter does _not_ require your program to use Qt.)

(3) use any mechanism of choice to load the translations

Part 3, with whichever mechanism, requires some form of
unique identifier.  This text identifier could be the
variable's fully qualified name---unavailable at run time
in Ada, but available to ASIS base tools.
Or you choose yourself a unique enumeration literal, like
the codes of SQL diagnostic messages.
Or some numbering scheme such as the one that HTTP uses for
status codes and corresponding message text.

package Example is

    type Fillin_Slot_Count is range 0 .. Max_Fillin_Slots;
     --  "A % has been found on line %" -- has 2 slots

    type Label_Text is access String;
    type Label_ID is
       (Name_Field, Age_Field, Amount_Field, ...);

    Known_Message : array (Label_ID) of Label_Text;

    type Field_Label
           (Lang : Supported_Language;
            For_ID : Label_ID)
    is
       new Limited_Controlled with
       record
          Text : Known_Messages (For_ID);
          Insertions : Fillin_Slot_Count;
       end record;

    overriding
    procedure Initialize (Object : in out Field_Label);
    --  check consistency,
    --  e.g. is no of slot markers = Object.Insertions?

    procedure Finalize (Object : in out Field_Label);
    --  free storage used etc.

    Confirmation_Button := ...
       Field_Label'(Lang => en_UK,
                    For_ID => Confirmation_Button,
                    Text => new Label_Text'("Yes")));

end Example;

The important variable in Example is Known_Messages. With
it, it is now easy to write a simple Ada program that performs
part (2) above.  That is, the program writes out a representation
of all messages to be translated, in the format needed by
your preferred translation tool.  For example, GNU Gettext
or Qt Linguist.

Likewise, the definitions in package Example above provide
all information needed to load a specific message in a
specific language at run time.



  parent reply	other threads:[~2009-12-12 12:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-11 23:15 Internationalization for Ada vlc
2009-12-12  9:23 ` Ludovic Brenta
2009-12-12 11:51   ` Dmitry A. Kazakov
2009-12-12 12:17   ` Georg Bauhaus [this message]
2009-12-12 12:24     ` Georg Bauhaus
2009-12-12 17:01       ` vlc
2009-12-12 17:18         ` Ludovic Brenta
2009-12-13 14:35 ` Christophe Chaumet
2009-12-14 15:18   ` Jacob Sparre Andersen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox