On 29-Mar-2000, D. Tweed <[EMAIL PROTECTED]> wrote:
> On Wed, 29 Mar 2000, Matthias Mann wrote:
> 
> > Has anybody some experience on what's the best way to write programs that
> > may interact in multiple languages?
> > 
> > My first thought was to extract all texts from the source and put them
> > into a big list or array. The program then accesses the list
> > corresponding to the selected language.
> > Any other (better) ideas? Should inputs, e.g. answers to yes-no-questions, be 
> > handled the same?
> 
> Not sure if this is a better idea, but the approach that, from what I can
> gather, a lot of the GNU programs use is equivalent to replacing every
> literal string in the text with roughly
> 
> (lookup language "the string")

One issue that you need to consider is that the word
ordering may be different in different languages.
So for a message like

        You have 3 apples.

which in Haskell you might format using code such as this

        msg :: Int -> Fruit -> String
        msg num fruit = "You have" ++ show num ++ " " ++
                        show (plural_name (fruit))

the correct translation in some other language might have
the number occurring after the fruit name.

In C, this is handled using position parameters in printf()
format strings (not standard C, but an X/open extension):

 | The printf() functions can handle a format string that enables the
 | system to process elements of the parameter list in variable order. In
 | such a case, the normal conversion character % (percent sign) is
 | replaced by %digit$, where digit is a decimal number in the range from
 | 1 to NL_ARGMAX. Conversion is then applied to the specified argument,
 | rather than to the next unused argument.  This feature provides for
 | the definition of format strings in an order appropriate to specific
 | languages.

For Haskell you would need to do something similar.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.

Reply via email to