comp.lang.ada
 help / color / mirror / Atom feed
From: Ray Blaak <blaak@infomatch.com>
Subject: Re: Programming for the World in Ada95
Date: 2000/02/15
Date: 2000-02-15T00:00:00+00:00	[thread overview]
Message-ID: <m3n1p13cmy.fsf@ns59.infomatch.bc.ca> (raw)
In-Reply-To: 38A99E37.F355452C@quadruscorp.com

"Marin D. Condic" <mcondic-nospam@quadruscorp.com> writes:
> While this will work, it does happen at compile time. A better method would
> be to do it at run time so that an "International" software product would
> differ only by a simple text file. [...] I'd build an error message package
> that loaded the text at startup [...]:
> 
> package Error_Messages is
> 
>     type Error_Type is (
>         Some_Error,
>         Another_Error,
>         Etc_Errors) ;
> 
>     procedure Display_Message (
>         Err    : in     Error_Type) ;
> 
>     -- The rest is an exercise for the student.
> 
> end Error_Messages ;

A much better idea. It still needs to allow parameterized messages, however, so
that you can say thing like: "there are 5 bad things here" or "yadda ko 5 cacca
dinca etho"

A common mistake in many systems is to follow C's printf conventions, so that
the string in the data file looks like: "there are %d bad things here".  The
problem comes when you have multiple parameters:

"there are %d bad things here, %d of which matter"

A sensible translation might need to reorder the parameters, i.e. maybe the
translated sentence needs to be in this order:

"%d critical things are in the %d bad things here"

But now the software won't match, since it is using positional notation.

The fix is, of course, named placement holders:

"there are ${total_count} bad things here, ${critical_count} of which matter"

Now a reordering will still work:

"${critical_count} critical things are in the ${total_count} bad things here"

The upshot is that the messages package now needs to allow the specification of
values for the placeholders, using name/value pairs:

  type Replacement is private:
  type Replacements is array (<>) of Replacement;
  
  function Subst(Name, Value : in String) return Replacement;

  function Translate
      (message : in Translatable_Message; parameters : in Replacements)
        return String;
  -- I prefer Translate or Lookup instead of Display_Message, since you might
  -- need the translated string for many purposes, e.g. logging, error
  -- messages, on a button, in a menu, etc.  I also suggest
  -- Translatable_Message or something similar, since the text is not
  -- necessarily for errors.

  ...

  Display(Translate (Message => Some_Error,
                     Parameters => 
                       (Subst("total_count", Integer'Image(total)),
                        Subst("critical_count", Integer'Image(critical)))));
          


-- 
Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
blaak@infomatch.com                            The Rhythm has my soul.




  reply	other threads:[~2000-02-15  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-14  0:00 Programming for the World in Ada95 John J Cupak Jr
2000-02-14  0:00 ` Ehud Lamm
2000-02-14  0:00 ` Larry Kilgallen
2000-02-16  0:00   ` Robert A Duff
2000-02-14  0:00 ` Gautier
2000-02-15  0:00 ` Jean-Pierre Rosen
2000-02-15  0:00   ` Marin D. Condic
2000-02-15  0:00     ` Ray Blaak [this message]
2000-02-16  0:00       ` Nick Roberts
2000-02-16  0:00       ` Pascal Obry
2000-02-16  0:00         ` Ray Blaak
2000-02-16  0:00       ` Larry Kilgallen
2000-02-16  0:00       ` Pascal Obry
replies disabled

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