RE: [PEAR-DEV] New class in PEAR: Translation
| From: | Lukas Smith | Date: | Tue, 01 Oct 2002 12:01:55 +0000 |
| Subject: | RE: [PEAR-DEV] New class in PEAR: Translation | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-9746@lists.php.net to get a copy of this message | ||
> From: Björn Schotte [mailto:bjoern@baer.main.de]
> Sent: Tuesday, October 01, 2002 1:57 PM
>
> > When I need to output strings in a script, I make an instance of a
> > translation class...
> > $t = new Translation("DE"); // For translating into german
>
> We've (to be honest, Johann-Peter Hartmann had the idea) made a
> similar approach:
>
> print "<p>".__("Please fix that")."</p>";
>
> is only a function that looks up if this string is the key
> in an associative array (i.e. $__lang). If not, it will simply
> return "Please fix that".
>
> $__lang is defined by a language specific include file that contains
sth
> like
>
> /* de-language file */
> $__lang = array(
> 'Please fix that' => 'Bitte beheben Sie das',
> .
> .
> .
> );
>
> A little helper script looks up (via preg_match) all source
> code files recursively for the __() function calls, puts the
> strings in the Database and it will display a HTML form where
> you can make the translations for each language you want to
> have. The helper script also generates the language files
> (lang_ISOCODE.php)
> on demand.
>
> Advantage:
>
> - you easily see where no translation has been made
> - you don't need to look up the DB every time you need
> the translated string
> - easy translation via normal HTML Form (i.e. give your
> translators a login to the application and let them enter
> i18n_admin.php to translate)
>
actually what we use today is just associative arrays that are stored in
a file. so we are doing pretty much that today as well (and it works
nicely and performant too).
We dont have such a helper script however (eventhough I have been
meaning to write one). The nice thing about having it in the db is that
you can modify it easier and/or distribute it across a cluster ...
Anyways when I have some spare brain cycles I will think about this.
Regards,
Lukas