Re: New class in PEAR: Translation
| From: | Björn Schotte | Date: | Tue, 01 Oct 2002 11:57:29 +0000 |
| Subject: | Re: New class in PEAR: Translation | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-9745@lists.php.net to get a copy of this message | ||
Hi,
> 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)
--
ThinkPHP zeigt auf der Systems die Chairman Enterprise Application
Suite, einer Toolbox für Ihren Inter-, Intra- oder Extranet-Auftritt.
Mehr Infos zu Chairman? < http://www.thinkphp.de/
>
Halle A1 (Software Development Area), Stand 300-11