Re: Translation class proposal
| From: | Wojciech Zielin'ski | Date: | Mon, 23 Sep 2002 11:25:42 +0000 |
| Subject: | Re: Translation class proposal | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-9348@lists.php.net to get a copy of this message | ||
On 2002-09-23 00:54, while getting another beer from the fridge I saw a
little yellow card, on which Wolfram Kriesing wrote:
btw to see a simple example using IT[X] see I18N/examples/I18N_Message_Translate.php I will have to look at it :) Maybe today afternoon...
have fun making translations easy :-) wolfram Wolfram Kriesing wrote:not the X/HTML ones :) But such approach you took makes this engine template-oriented - so much larger and more complicated....fyi here a short info about what the *current I18N class(es)* as far as what i have done concerning translation (i am not very deep into the stuff that Naoki Shima did) is capable of and what it was meant for the translation (now in the Message-dir) as i created it was intended mainly to work with X/HTML, it can surely be extended to work with gtk-stuff, which i think is necessary to have the right to call itself I18N :-) My intetion was to create the class that works mostly with PHP files -
you're translating. I use the &&x&& strings - where x can be a incrementing numbers - which lets me to not only make many "untraslated" string inside my string, but also lets me change their order - e.g.: You've got 2 languages and you call $tr->gstr("STRING", array("Ala","cat")); for each of them: 1. en: &&1&& has a &&2&& : Ala has a cat 2. de: &&1&& hat ein &&2&& : Ala hat ein cat 3. pl: &&2&& jest posiadany przez &&1&& " cat jest posiadany przez Ala As you can see - the class was designed knowing that in several languages the inversions can occure. Your solution does not provide (as far as I understood) changing the order of untranslated strings.my actual intention was to give it a X/HTML-string (which might be the entire file) and translate stuff that is meant to be translated by - getting the source-language strings from a db (should be abstracted to work on other sources too, such as gettext, file, webservice, etc.) - looking for it in the ML-string and replace it by the destination- language string, which it gets from the db too I simply dont want to maintain a template/HTML file for each language, i want a translator-class to translate that for me (that's why SimpleTemplate also has a locale-option!). how does it detect what is meant to be translated? first it has pieces of regular expressions given which tell where to search for translatable string. such as inside > and < and in the "value" of an input-tag. that's how it does it now. so the following will be done:<b class="dontTranslateThis">translate me</b> <input value="translate me too" name="but DONT translate me">so you can see that it tries to sort out what is really translatable, in a reasonable way (may be the XML-Transformer would be perfect to use here, some guru got a hint for me? i would be interested) furthermore it does also replace strings with dynamic strings inside, like<b>Hello user {$username}, how are you today?</b>in the source language (english in this case) you have in your db-table the following string:Hello user .*, how are you today?where .* is simply what the regular expression translates and the destination language has the following string in its tableHallo User $1, wie gehts dir heute?(german). There you see that any part inside a string can be replaced But this approach lets you use only 1 "untraslated" string inside string
furthermore the class can: - convert translated strings into proper HTML - do simple translation via a method call, such as $obj->translate('string to translate') This is exactly what my class does :)
Summarizing - I still think your solution is much more complex and it is designed for much complex usage. I created the class only for translating specific, given strings. My proposal is maybe you would use my class inside the I18N class while doing the translation - and also my class would be available separatelly - so simply I18N would be dependend on Translation - and if someone would want to use only the translation thing - he would get my class, and if someone would like your aproach - he would get your class. What do you think ? Regards Voyteck- it should be easily useable with any template engine such as smarty, Flexy, etc. though i never tried it Wojciech, another thing i would like to suggest is that the translation-tool that enables you to manage the table with the translated strings should be a seperate application, i.e. in a tool-directory, since it is only needed/used seldomly and the code only takes up space in the actual working class. what do you think? That's a good idea - will have to make such separation :)