Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re (tilly) 1: Perl Programs That Support Multiple (Human) Languages

by dws (Chancellor)
on Aug 27, 2001 at 09:32 UTC ( #108054=note: print w/replies, xml ) Need Help??


in reply to Re (tilly) 1: Perl Programs That Support Multiple (Human) Languages
in thread Perl Programs That Support Multiple (Human) Languages

Model-View-Controller helps generate and sychronize multiple views of an underlying data model, but even using MVC, you still run into internationalization and localization issues. Unless your friends have come up with some similar pattern that's lighter weight, I suspect they're generating a lot of code in the interest of supporting multiple languages.

I've worked inside of several internationalized applications. All have been able to get by with a combination of separate "externalized strings" files for each supported language, plus a few extras, such as the equivalent of a custom sprintf that knew how to dynamically alter the order (position) of substitutions.

  • Comment on Re: Re (tilly) 1: Perl Programs That Support Multiple (Human) Languages
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re (tilly) 1: Perl Programs That Support Multiple (Human) Languages
by John M. Dlugosz (Monsignor) on Aug 27, 2001 at 11:04 UTC
    In the early 90's, for an embedded PC that controlled a scanning densitometer, I came up with a C++ class that fit our needs.

    An associative array was indexed by a string value, which could have some nmenonic value to the code it's called from, and is easier to make unique and maintain in a large program than sequencial ID numbers as favored by MicroSoft.

    The "hash" was populated from a translation file at program startup. The format of the file was the key followed by each available translation.

    I liked the idea of having all translations of one string together, rather than a different file for each language like some schemes. I think Win32's language stuff (using FormatMessage, not the string table resource) works that way too, but is not nearly as powerful. FormatMessage has the dynamic positioning of strings like you mention; I don't remember how my old program handled that.

    In a modern Perl solution, I think we can address the dynamic ordering easily enough:

    If you pulled in the string with a function call, such as $x->format ($a,$b,$c); and the string contained markers $1, $2, and $3, you get the idea. But function calls don't interpolate in Perl 5, so using a tied hash for syntactic sugar might help.

    I'd also like to see the format function automatically take care of changes based on the actual paramters, such as number and gender. E.g. $x->format(17) would cough up "There were 17 files processed." but $x->format(1) would produce "There was 1 file processed". Changes in words due to singular/plural is so common that an escape code could specify that. E.g. the translation string holds 'There $?n1(were,was,were) $1 file$?n1(,,s) processed.'. $ followed by digit is a substitution. $? followed by code/flags/etc then digit is fancy stuff: ?n for "number", followed by forms for zero,singular,plural cases.

    —John

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://108054]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2022-08-11 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?