RE: [PEAR-DEV] New class in PEAR: Translation
| From: | Lukas Smith | Date: | Tue, 01 Oct 2002 11:18:20 +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-9739@lists.php.net to get a copy of this message | ||
> From: Markus Wolff [mailto:wolff@21st.de]
> Sent: Tuesday, October 01, 2002 1:12 PM
>
> Am Tue, 01 Oct 2002 12:30:35 +0200 schrieb Wojciech Zieliñski
> <voyteck@caffe.com.pl>:
>
> > Can I please have some votes (if someone thinks, it's bad idea -
then
> > also vote against :) I will at least know, that I am not going the
good
> > direction :) )
> > If someone wants to see this class - it is right now available on
> > http://voyteck3.free.komrel.net/translation/
>
> IMHO Wolfram´s I18N class and your new Translation class are very good
> examples why it´s a good thing to have more than one solution for a
> problem in PEAR - when this class will be added, there will be two
> different approaches to the same problem in PEAR, but still not the
one
> that I would need, so there´s still room for another :-)
>
> However, here´s my +1 for adding this class as I think it will be
useful
> for some people. You might consider choosing another License though as
I
> believe "Postcardware" is not one of the licenses that are listed as
> compatible to the PHP-License :-)
>
> In case you´re wondering what I have in mind when I think of a
> translation class, it´s basically this:
>
> 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
>
> To get a translated string, I´d simply do something like this:
> $trans = $t->get("Translation is good");
> Or this:
> printf($t->get("You have %s unread mails", $num);
>
> The "get" method will look up the string in a database table that
looks
> like this:
>
> BASE (Primary Key) | DE | FR
>
------------------------+-------------------------------+---------------
--
> --------
> Translation is good | Übersetzung ist gut | Je ne parle
pas
> Francais
> You have % unread mails | Sie haben %s ungelesene Mails |
>
> The field "BASE" will always contain the original strings in the base
> language. This is the language that I´m using in my PHP code and will
be
> English in most cases I guess. This way my code is very easy to read
and
> understand. Also, it doesn´t matter on which page I am which is
> especially important as I sometimes need to output stuff in scripts
when
> I can´t possibly know where I am at the moment.
>
> When a string is not yet in the database, it will be added for future
> reference. The other column names are identical to the language string
> that is passed to the translation class constructor.
>
> If no translation for a specific string is available (meaning the
target
> language´s column is empty or doesn´t exist), the string will always
be
> returned in the base language.
>
> This is a drop-dead-simple method of translation that is not only easy
> to use but also easy to maintain even with tools like phpMyAdmin. If
> someone here knows a class that already does this or something very
> similar, please drop me a line. If not, I´ll have to write this myself
> as I need something like this and have no use for page-oriented
> translation.
>
well i would not use a text string as your "base".
What if you decide to change the english text for one of your clients?
Maybe the client is addressing a younger audience so the text should be
less formal etc.
The base should be something more abstract like "mail_error" and also it
would make sense to group the texts into something like general and
modul specific. So you can say $t->get('mail_error', 'contact');
ommitting 'contact' would mean you want the general translation.
Regards,
Lukas