comp.lang.ada
 help / color / mirror / Atom feed
* Internationalization for Ada
@ 2009-12-11 23:15 vlc
  2009-12-12  9:23 ` Ludovic Brenta
  2009-12-13 14:35 ` Christophe Chaumet
  0 siblings, 2 replies; 9+ messages in thread
From: vlc @ 2009-12-11 23:15 UTC (permalink / raw)


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!



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Internationalization for Ada
  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
  2009-12-13 14:35 ` Christophe Chaumet
  1 sibling, 2 replies; 9+ messages in thread
From: Ludovic Brenta @ 2009-12-12  9:23 UTC (permalink / raw)


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.

--
Ludovic Brenta.



^ 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
  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

* Re: Internationalization for Ada
  2009-12-12 12:17   ` Georg Bauhaus
@ 2009-12-12 12:24     ` Georg Bauhaus
  2009-12-12 17:01       ` vlc
  0 siblings, 1 reply; 9+ messages in thread
From: Georg Bauhaus @ 2009-12-12 12:24 UTC (permalink / raw)


On 12/12/09 1:17 PM, Georg Bauhaus wrote:

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

     Text => Known_Message (...)));

it should be.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Internationalization for Ada
  2009-12-12 12:24     ` Georg Bauhaus
@ 2009-12-12 17:01       ` vlc
  2009-12-12 17:18         ` Ludovic Brenta
  0 siblings, 1 reply; 9+ messages in thread
From: vlc @ 2009-12-12 17:01 UTC (permalink / raw)


Thanks a lot for your help! Your answers are by far more detailed than
I expected :-)

And I just noticed that I need new glasses - I didn't find GtkAda.Intl
in GtkAda's reference manual ...

But also your other proposals sound interesting. I'll check them out
in detail to find the best solution for me.

Again, thanks a lot!



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Internationalization for Ada
  2009-12-12 17:01       ` vlc
@ 2009-12-12 17:18         ` Ludovic Brenta
  0 siblings, 0 replies; 9+ messages in thread
From: Ludovic Brenta @ 2009-12-12 17:18 UTC (permalink / raw)


vlc wrote on comp.lang.ada:
> Thanks a lot for your help! Your answers are by far more detailed than
> I expected :-)
>
> And I just noticed that I need new glasses - I didn't find GtkAda.Intl
> in GtkAda's reference manual ...

You can also look at the source file gtkada-intl.ads, it contains
detailed documentation.

> But also your other proposals sound interesting. I'll check them out
> in detail to find the best solution for me.

I too am surprised, I was not aware of these.

--
Ludovic Brenta.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Internationalization for Ada
  2009-12-11 23:15 Internationalization for Ada vlc
  2009-12-12  9:23 ` Ludovic Brenta
@ 2009-12-13 14:35 ` Christophe Chaumet
  2009-12-14 15:18   ` Jacob Sparre Andersen
  1 sibling, 1 reply; 9+ messages in thread
From: Christophe Chaumet @ 2009-12-13 14:35 UTC (permalink / raw)


vlc a �crit :
> 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!
>   
Hello,

For my own usage I have a package "intl" which contains all the string 
literals and there is an instance of this package for each language 
(intl-fr.ads, intl-en.ads,...)  and I have defined a variable in GPS 
called 'language'. In the project file there is something like:

   package Naming is
      case language is
         when "french" =>    for Specification ("intl") use "intl_fr.ads";
         when "english" =>   for Specification ("intl") use "intl-en.ads";
      end case;
   end Naming;


When I want to generate an executable in a language I just select the 
proper value and the build do all the job. This works only with GPS, but 
its is independent of any other package like Gtk.

Regards

Christophe Chaumet



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Internationalization for Ada
  2009-12-13 14:35 ` Christophe Chaumet
@ 2009-12-14 15:18   ` Jacob Sparre Andersen
  0 siblings, 0 replies; 9+ messages in thread
From: Jacob Sparre Andersen @ 2009-12-14 15:18 UTC (permalink / raw)


Christophe Chaumet wrote:

> For my own usage I have a package "intl" which contains all the string
> literals and there is an instance of this package for each language
> [...]

But this means that translation has to be done _before_ compilation.

One of the benefits of using the GNU Gettext system is that translators
can translate and distribute translations independent of the compiled
program.

Greetings,

Jacob
-- 
"It is a syntax error to write FORTRAN while not wearing a blue tie."



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-12-14 15:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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