From: Hani N. <ha...@na...> - 2004-09-08 10:06:00
|
Hi Phil, The class you mention below is the one I was talking about. It depends on PEAR but removing this dependency was really simple although I can't remember exactly what the dependency was, but it only took 30 mins to figure it out last time. In the end you end up with this extra class (one php file) and I also had another php file (language.php) in which I wrote some shortcut functions. This removes the need for having gettext compiled into php. Remember most translators will probably be working on their home pc, which probably does not have gettext. I seem to remember it was an involving process to get gettext into php. As for the variables issue I guess it will boil down to your preferrence, since it is not a very common thing, it should not affect 80% of the translations, but would mean someone translating into a new language may one day need to change the code. By the way there is also an even less common feature to keep in mind that has to do with the quantity of objects within translations. For example 'You have 2 ITEMS in your bag" is fine for numbers above 1, but 'You have 1 ITEMS in your bag" is incorrect. In Arabic it is even worse :) since there are three forms to consider, single, dual and plural. :) Hani Phil Daintree wrote: >*This message was transferred with a trial version of CommuniGate(tm) Pro* >This is a good example. > >Why couldn't the translation string in messages.po be as follows > >msgid = "Display" >msgstr = "Mostra opzioni per il modulo" > >msgid = "options" >msgstr =' ' > >the output for the English version is: > >Display $module options > >the output for the Italian version is: > >Mostra opzioni per il modulo $module > >Ok, I know this wouldn't work in some situations but the point is that >there are work arounds that might involve more imaginative use of >language rather than complex code and additional classes that would work >in a good proportion of cases. I would rather us explore these options >first. > >If we absolutely had to, >as a last resort, >after every other avenue had failed, >and there really is no other way ..... > >and AFTER we have all the scripts 'gettextified' using the absolute bare >minimum of "fancy stuff" and if then there is still dissatisfaction I >would prefer to use a gettext class: > >http://phptal.sourceforge.net/bagpack/GetText/doc/gettext.variableinterpolation.html > >this creates another dependence though and I really really only want to >depend on PHP and a DB - nothing else. If it comes to this then it would >be better if we could include the minimal additional files in the >distribution so there is nothing extra to worry about in terms of PEAR >classes to install. > >Phil > > >On Wed, 2004-09-08 at 20:31, luc...@pd... wrote: > > >>Hello all. >>As stated in my previous message, I was trying to solve the problem of sentences with one or more parameters. As an example just consider -"Display ". $ModuleName . " options:"- in www_users. >>Here's my proposed solution. >>I am using special tags in the tobetranslated and translated sentence, i.e : >>ENGLISH: Display __Parameter1__ options >>ITALIAN: Mostra opzioni per il modulo __Parameter1__ >> >>when I have to translate this sentence I make this call: >>translate('Display __Parameter1__ options',$ModuleName) >> >>Here's the definition of the function translate: >>function translate($idOfLabelToBeTranslated) >>{ >> global $lang; >> if ($lang[$idOfLabelToBeTranslated]!=null){ >> $numargs = func_num_args(); >> if($numargs >1){ >> $arg_list = func_get_args(); >> $returnString=$lang[$idOfLabelToBeTranslated]; >> for ($i = 0; $i < $numargs; $i++) { >> //echo "Argument $i is: " . $arg_list[$i] . "<br />\n"; >> $returnString = str_replace('__Parameter'.$i.'__',$arg_list[$i],$returnString); >> } >> return $returnString; >> } >> else //number of arguments is 1 >> return $lang[$idOfLabelToBeTranslated]; >> } >> else //there is no translated label in the array >> return $idOfLabelToBeTranslated; >>} >> >>As you can see it takes a variable number of arguments. If we have more than 1 argumentes, i.e. some parameters have to be inserted in the sentence, it simply gets the translated label, which contains the varios strings __Parameter1__ ... __ParameterN__. Then it substitutes the parameter string with the values passed as arguments. >> >>The main concern I still have on this solution is: >>"__ParameterN__" as the tobereplaced string is cabled, thus every translator has to keep in mind to strictly use this formalism. Of course any suggestion on how to choose a formalism wich can be surely not confused with any real life word, will be appreciated. >> >> >> >> > > > > >------------------------------------------------------- >This SF.Net email is sponsored by BEA Weblogic Workshop >FREE Java Enterprise J2EE developer tools! >Get your free copy of BEA WebLogic Workshop 8.1 today. >http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click >_______________________________________________ >Web-erp-developers mailing list >Web...@li... >https://lists.sourceforge.net/lists/listinfo/web-erp-developers > > > > |