I'm developing a script (web cgi) for which I would like to offer multilanguage support. I would like some advise on how I might (better) approach this task. The script will be fairly small and usage (on a non-profit org website) will be fairly light, so efficiency concerns aren't terribly important.
What I'm presently thinking is that I won't hard-code any output in my script, but will populate (from a database or whatever) a hash which would look this:
$lang{'yes'} = 'sí';
$lang{'no'} = 'ningún';
$lang{'The answer is'} = 'La respuesta es';
Then, in my script, I would output something like:
print "$lang{'The answer is'} $lang{'yes'}.";
and it would print:
La respuesta es sí.
assuming I had populated the hash from a Spanish database. (In the English version, the hash values are simply the same as the hash keys.)
Does this seem a good approach? It seems a bit clumsy, but a better idea doesn't come to mind (though I can think of a couple of ideas that I think are much worse). A better suggestion would be most welcome!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.