comp.lang.ada
 help / color / mirror / Atom feed
* I18N gettext style
@ 2000-03-04  0:00 David Starner
  2000-03-04  0:00 ` tmoran
  2000-03-06  0:00 ` Nick Roberts
  0 siblings, 2 replies; 8+ messages in thread
From: David Starner @ 2000-03-04  0:00 UTC (permalink / raw)


gettext is a C library that does message translation - i.e.

	puts (N("Hi!"));
	
will replace Hi with whatever's appropriate for the locale, provided the 
message catalog has it. That's simple enough to interface/rewrite for Ada. 
But it's also used in stuff like

	printf (N("Hi! There are %d widgets!"), I);
	
where in the %d will get moved to where ever the number needs to be in the 
translated message. 

Unfortunetly,
	Ada.Text_IO.Put (N("Hi! There are ") && To_String(I) && N("widgets!"));
won't put I in the proper position in the translated message for some
languages. What's the easiest way to do this type of thing for Ada?

-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




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

* Re: I18N gettext style
  2000-03-04  0:00 I18N gettext style David Starner
@ 2000-03-04  0:00 ` tmoran
  2000-03-04  0:00   ` David Starner
  2000-03-05  0:00   ` tmoran
  2000-03-06  0:00 ` Nick Roberts
  1 sibling, 2 replies; 8+ messages in thread
From: tmoran @ 2000-03-04  0:00 UTC (permalink / raw)


>  Ada.Text_IO.Put (N("Hi! There are ") && To_String(I) && N("widgets!"));
>won't put I in the proper position in the translated message for some
  Certainly an Ada version of printf in the form of a set like
    procedure print0(s : in string);
    procedure print1(s : in string; a : in string);
    procedure print2(s : in string; a : in string; b : in string);
is easy enough to write.  So then you could call
    print1( N("Hi! There are %s widgets!"), To_String(I));
By always passing in string arguments (using 'image in the simplest
case) your Ada routines need only handle %s, not %d or any of
the other codes, which is simple and avoids combinatorial explosion.
  Better yet, instead of %s, use %a in print1, %a and %b in print2,
etc, and then N can even change the order, which it can't in the
C paradigm.




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

* Re: I18N gettext style
  2000-03-04  0:00 ` tmoran
@ 2000-03-04  0:00   ` David Starner
  2000-03-05  0:00     ` Jeff Carter
  2000-03-05  0:00   ` tmoran
  1 sibling, 1 reply; 8+ messages in thread
From: David Starner @ 2000-03-04  0:00 UTC (permalink / raw)


On Sat, 04 Mar 2000 08:28:01 GMT, tmoran@bix.com <tmoran@bix.com> wrote:
>>  Ada.Text_IO.Put (N("Hi! There are ") && To_String(I) && N("widgets!"));
>>won't put I in the proper position in the translated message for some
>  Certainly an Ada version of printf in the form of a set like
>    procedure print0(s : in string);
>    procedure print1(s : in string; a : in string);
>    procedure print2(s : in string; a : in string; b : in string);

Is there any reason you used print0, print1, print2, instead of
print, print, print? My instinct is to overload them.

>  Better yet, instead of %s, use %a in print1, %a and %b in print2,
>etc, and then N can even change the order, which it can't in the
>C paradigm.

Or %1 and %2, for compatibility with current systems.

Thanks.

-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




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

* Re: I18N gettext style
  2000-03-04  0:00 ` tmoran
  2000-03-04  0:00   ` David Starner
@ 2000-03-05  0:00   ` tmoran
  1 sibling, 0 replies; 8+ messages in thread
From: tmoran @ 2000-03-05  0:00 UTC (permalink / raw)


>Is there any reason you used print0, print1, print2, instead of
>print, print, print? My instinct is to overload them.
  The only reason is that I was trying to code after midnight. #.#
>Or %1 and %2, for compatibility with current systems.
  How about producing:

Hi!
Hi! There are 3 widgets!
Hi! There are 3 parts, code 1234!
Hi! For $99.95 you can buy 3 parts, code 1234!

  using

with ada.text_io,
     ada.text_io.editing;
 use ada.text_io,
     ada.text_io.editing;
procedure test is

  procedure print(s : in string;
                  p1 : in string := "";
                  p2 : in string := "";
                  p3 : in string := "") is
    si : integer := s'first;
  begin
    while si <= s'last loop
      if si < s'last and then s(si) = '%' then
        case s(si+1) is
          when '1' => put(p1);
          when '2' => put(p2);
          when '3' => put(p3);
          when others => null;
        end case;
        si := si+2;
      else
        put(s(si));
        si := si+1;
      end if;
    end loop;
    new_line;
  end print;

  count : integer := 3;
  id : integer := 1234;

  type money is delta 0.01 digits 5;
  package print_money is new ada.text_io.editing.decimal_output(money);
  money_picture : constant picture := to_picture("-$$9.99");

  price : money := 99.95;

begin
  print("Hi!");
  print("Hi! There are%1 widgets!",
        integer'image(count));
  print("Hi! There are%1 parts, code%2!",
        integer'image(count),
        integer'image(id));
  print("Hi! For%3 you can buy%1 parts, code%2!",
        integer'image(count),
        integer'image(id),
        print_money.image(price, money_picture));
end test;




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

* Re: I18N gettext style
  2000-03-04  0:00   ` David Starner
@ 2000-03-05  0:00     ` Jeff Carter
  2000-03-05  0:00       ` Ehud Lamm
  0 siblings, 1 reply; 8+ messages in thread
From: Jeff Carter @ 2000-03-05  0:00 UTC (permalink / raw)


David Starner wrote:
> 
> On Sat, 04 Mar 2000 08:28:01 GMT, tmoran@bix.com <tmoran@bix.com> wrote:
> >>  Ada.Text_IO.Put (N("Hi! There are ") && To_String(I) && N("widgets!"));
> >>won't put I in the proper position in the translated message for some
> >  Certainly an Ada version of printf in the form of a set like
> >    procedure print0(s : in string);
> >    procedure print1(s : in string; a : in string);
> >    procedure print2(s : in string; a : in string; b : in string);
> 
> Is there any reason you used print0, print1, print2, instead of
> print, print, print? My instinct is to overload them.

My instinct is to only have one, which can handle an indeterminate
number of arguments:

with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
...
type String_Set is array (Positive range <>) of Unbounded_String;

procedure Print (Format : in String; Arguments : in String_Set);
...
Print
  (Format    => "There are %s arguments.", -- is this correct?
   Arguments => (1 => Image (Num_Args) );

-- 
Jeff Carter
"Your mother was a hamster and your father smelt of elderberries."
Monty Python & the Holy Grail




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

* Re: I18N gettext style
  2000-03-05  0:00     ` Jeff Carter
@ 2000-03-05  0:00       ` Ehud Lamm
  0 siblings, 0 replies; 8+ messages in thread
From: Ehud Lamm @ 2000-03-05  0:00 UTC (permalink / raw)


This is the way I did it in one of the frameworks I wrote. 

One of the nice things Ada provides is the standard way of dealing with
unconstrained arrays...

Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== My home on the web 
Check it out and subscribe to the E-List- for interesting essays and more!


On Sun, 5 Mar 2000, Jeff Carter wrote:

|David Starner wrote:
|> 
|> On Sat, 04 Mar 2000 08:28:01 GMT, tmoran@bix.com <tmoran@bix.com> wrote:
|> >>  Ada.Text_IO.Put (N("Hi! There are ") && To_String(I) && N("widgets!"));
|> >>won't put I in the proper position in the translated message for some
|> >  Certainly an Ada version of printf in the form of a set like
|> >    procedure print0(s : in string);
|> >    procedure print1(s : in string; a : in string);
|> >    procedure print2(s : in string; a : in string; b : in string);
|> 
|> Is there any reason you used print0, print1, print2, instead of
|> print, print, print? My instinct is to overload them.
|
|My instinct is to only have one, which can handle an indeterminate
|number of arguments:
|
|with Ada.Strings.Unbounded;
|use Ada.Strings.Unbounded;
|...
|type String_Set is array (Positive range <>) of Unbounded_String;
|
|procedure Print (Format : in String; Arguments : in String_Set);
|...
|Print
|(Format    => "There are %s arguments.", -- is this correct?
| Arguments => (1 => Image (Num_Args) );
|
|-- 
|Jeff Carter
|"Your mother was a hamster and your father smelt of elderberries."
|Monty Python & the Holy Grail
|
|





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

* Re: I18N gettext style
  2000-03-04  0:00 I18N gettext style David Starner
  2000-03-04  0:00 ` tmoran
@ 2000-03-06  0:00 ` Nick Roberts
  2000-03-06  0:00   ` David Starner
  1 sibling, 1 reply; 8+ messages in thread
From: Nick Roberts @ 2000-03-06  0:00 UTC (permalink / raw)


I'm sure I posted quite a lengthy article on this very subject just a couple
of weeks ago. (Maybe it was too lengthy :-( ;-)

To precis it incredibly briefly, my advice is to: (a) use forms such as
"Number of widgets: " for each message, so that the problem of inserting
parameters goes away; (b) use a database to store the messages in different
languages, so that (one good reason for a start) you can use standard
database tools to enter, edit, browse, report, analyse, check, etc., the
text; (c) to be really fancy, build in a default set of messages, in case
the program is run in circumstances where the database isn't available.

--
Nick Roberts
http://www.adapower.com/lab/adaos

"David Starner" <dvdeug@x8b4e53cd.dhcp.okstate.edu> wrote in message
news:89q6pg$9ac1@news.cis.okstate.edu...
> gettext is a C library that does message translation - i.e.
>
> puts (N("Hi!"));
>
> will replace Hi with whatever's appropriate for the locale,
> [etc.]






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

* Re: I18N gettext style
  2000-03-06  0:00 ` Nick Roberts
@ 2000-03-06  0:00   ` David Starner
  0 siblings, 0 replies; 8+ messages in thread
From: David Starner @ 2000-03-06  0:00 UTC (permalink / raw)


On Mon, 6 Mar 2000 02:12:03 -0000, 
Nick Roberts <nickroberts@callnetuk.com> wrote:
>To precis it incredibly briefly, my advice is to: (a) use forms such as
>"Number of widgets: " for each message, so that the problem of inserting
>parameters goes away; 

Which is ugly, and won't always work. It's too much of a PITA to do that
when it's simple to fix.

>(b) use a database to store the messages in different
>languages, so that (one good reason for a start) you can use standard
>database tools to enter, edit, browse, report, analyse, check, etc., the
>text; (c) to be really fancy, build in a default set of messages, in case
>the program is run in circumstances where the database isn't available.

In other words, do it like gettext does, except replace the .po files - that
are plain text and have several specialized editors - with a database -
which is binary (big/little endian problems) and requires the translator 
use different tools that she's probably not familiar with.

Frankly, my current plan - if I don't quit using Ada for a more Unix friendly
language - is to rewrite/adapt/wrap gettext. It's the standard on Linux,
and I'm going to lose enough users due to Ada and libgtkada already. I
don't need to drive away anymore due to a non-standard translation system.

-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




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

end of thread, other threads:[~2000-03-06  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-04  0:00 I18N gettext style David Starner
2000-03-04  0:00 ` tmoran
2000-03-04  0:00   ` David Starner
2000-03-05  0:00     ` Jeff Carter
2000-03-05  0:00       ` Ehud Lamm
2000-03-05  0:00   ` tmoran
2000-03-06  0:00 ` Nick Roberts
2000-03-06  0:00   ` David Starner

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