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!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|