From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!xlned.com!feeder1.xlned.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Sat, 12 Dec 2009 13:17:57 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.5) Gecko/20091130 Thunderbird/3.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Internationalization for Ada References: <7cdd6689-077e-4438-a493-428823bb1ee2@k19g2000yqc.googlegroups.com> In-Reply-To: <7cdd6689-077e-4438-a493-428823bb1ee2@k19g2000yqc.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4b2389f9$0$7631$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 12 Dec 2009 13:18:01 CET NNTP-Posting-Host: 82556a85.newsspool1.arcor-online.net X-Trace: DXC=]hR 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.