I'm asked to do a multilingual script for a client who's hosted on a
server which does not offer gettext support in PHP. Is there an
attractive alternative?
The solution I thought up was to place all language strings in an array
and index it with a number, something like this:
en-strings.php:
$Str[0]="ad...@site.co.uk";
$Str[1]="You are logged out";
$Str[2]="Hello, World!";
de-strings.php:
$Str[0]="ad...@site.de";
$Str[1]="Du bist abgelogt";
$Str[2]="Gutentag, Welt!";
etc, for each language one file.
And then use it like this:
$langcode="es"; // español
include $langcode."-strings.php";
echo Str[2]; // Hello World! (outputs: !Ola, Mundo!)
$langcode="de"; // deutsch
include $langcode."-strings.php";
echo Str[2]; // Hello World! (outputs: Gutentag, Welt!)
--
Spam is spam no matter who's doing it or for what reason.
I've used that method some times too and it's working good... though
maybe you should make more includes if you get too many strings so you
dont include 100 strings for no use, but you only said "a multilingual
script" so it does not sound like thats a problem. Another was is to
make a string table in your database so easier update, but if the coder
is the only that has to update the strings, the file based version is fine.
--
Henrik Hansen
Even better, write a simple function:
function my_translate( $string ) {
...
}
and use it to do your translations, then you can change from file-based to
db based without changing the rest of your app.
--
----- stephan
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.
thats true, thats a good way of making sure you dont make your app
obsolete ;) just be sure only to include your array file one time per
script run when using the function so you dont "make" the array 100 time
per script run, if y'all know what I am blabbing about ;)
--
Henrik Hansen
hypothetical:
function my_translate($key) {
$lang = my_config_get( "lang" );
include_once( "translations.$lang.php" );
global $TRANSLATIONS;
return $TRANSLATIONS[$key] || $key;
}
(obviously needs more error checking)
"stephan" <ste...@wanderinghorse.net> wrote in message
news:ancbsn$99k$1...@ork.backup.noris.net...