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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ec7fc30600a974ce X-Google-Attributes: gid103376,public From: Ray Blaak Subject: Re: Programming for the World in Ada95 Date: 2000/02/15 Message-ID: #1/1 X-Deja-AN: 586401496 Sender: blaak@ns59.infomatch.bc.ca References: <38A83838.44A43A7D@res.raytheon.com> <88b4oa$ljt$1@wanadoo.fr> <38A99E37.F355452C@quadruscorp.com> X-Trace: news.bctel.net 950681163 207.34.170.123 (Tue, 15 Feb 2000 22:06:03 PDT) NNTP-Posting-Date: Tue, 15 Feb 2000 22:06:03 PDT Newsgroups: comp.lang.ada X-Complaints-To: news@bctel.net Date: 2000-02-15T00:00:00+00:00 List-Id: "Marin D. Condic" 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.