* Re: Internationalization for Ada
2009-12-12 9:23 ` Ludovic Brenta
@ 2009-12-12 11:51 ` Dmitry A. Kazakov
2009-12-12 12:17 ` Georg Bauhaus
1 sibling, 0 replies; 9+ messages in thread
From: Dmitry A. Kazakov @ 2009-12-12 11:51 UTC (permalink / raw)
On Sat, 12 Dec 2009 01:23:07 -0800 (PST), Ludovic Brenta wrote:
> vlc wrote on comp.lang.ada:
>>
>> 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.
Yes, but there is also other way based on widget style properties, which I
prefer.
Each variable text is made a style property of its container widget. When
the widget is initialized, its class record is initialized as well. Here
the necessary style properties are added:
if <the class record was initialized> then
Class_Install_Style_Property
( Class_Record, -- Freshly initialized class record
Gnew_String
( Name => "fancy text",
Nick => "hey",
Default => "hey",
Blurb => "The text to appear in the label"
) );
In the widget's "style_set" event handler the texts are actually set. E.g.
procedure Style_Set (Widget : access Gtk_Fancy_Widget_Record'Class) is
begin
Set_Text (Widget.Label, Style_Get Widget, "fancy text");
...
The texts and other styles are then defined in the GTK resource file. That
need to be done only if necessary, because there is a default for any
property. Only in order to change the texts you provide and load another
resource file. This can be done several times, if you properly handle the
event "style_set".
The advantage of this method is that it does not require any tools or any
additional files to work. It does not depend on the OS and its settings.
(E.g. when I use German locale, I still don't want texts in German). Style
properties can be more than only texts. For example you can have images
there. The way properties are matched are very elaborated, you can define
quite complex rules (by class name, by widget name etc), instead of simple
equality in the case of locales.
A more detailed description how to deal with GTK style properties in
GtkAda:
http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#4
On GTK resource files see:
http://library.gnome.org/devel/gtk/unstable/gtk-Resource-Files.html
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Internationalization for Ada
2009-12-12 9:23 ` Ludovic Brenta
2009-12-12 11:51 ` Dmitry A. Kazakov
@ 2009-12-12 12:17 ` Georg Bauhaus
2009-12-12 12:24 ` Georg Bauhaus
1 sibling, 1 reply; 9+ messages in thread
From: Georg Bauhaus @ 2009-12-12 12:17 UTC (permalink / raw)
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.
^ permalink raw reply [flat|nested] 9+ messages in thread