Re: New class in PEAR: Translation
| From: | Lux | Date: | Tue, 01 Oct 2002 14:41:07 +0000 |
| Subject: | Re: New class in PEAR: Translation | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-9749@lists.php.net to get a copy of this message | ||
On Tuesday, October 1, 2002, at 06:11 AM, Markus Wolff wrote:
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);Take a look at the package http://www.simian.ca/downloads/saf-3.0beta4.tar.gz The syntax is identical to what you describe in the I18n package. Sorry, the only difference is that it uses $t->getf if you're putting format characters in the string, and $t->get if you want to use template tag replacements in the string (from the template package in the same download). This doesn't use a database to store the translations though, it stores it in PHP files which are included and fill out an internal $t->lang_hash This doesn't make for the simplest editing, but we're all familiar with PHP files, aren't we? :) Plus, PHP files can be cached, which was the same benefit Smarty has over other template classes. In my software that is based on this, there is a "Translation Builder" module that creates a form to edit translations, create new ones, and rebuild the main key file, but unfortunately this part is not free software. It shows that something like that can be built easily enough on top of my I18n class though. Let me know what you think! Cheers, Lux
The "get" method will look up the string in a database table that looks like this:-- John Luxford Simian Systems _______________________ phone : 204.946.5955 email : lux@simian.ca web : www.simian.ca _______________________ web content management application development consulting and trainingBASE (Primary Key) | DE | FR ------------------------+-------------------------------+------------------------- Translation is good | Übersetzung ist gut | Je ne parle pas FrancaisYou 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. Regards, Markus --*21st Media* | Consulting, Konzeption, Produktion für die Bereiche: Markus Wolff | Internet, Intranet, eCommerce, Content Management,Hamburg,Germany | Softwareentwicklung, 3D-Animation, Videostreaming http://21st.de | Tel. [+49](0)40/6887949-0, Fax: [+49](0)40/6887949-1 -- PEAR Development Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php