From: Phil D. <we...@pa...> - 2004-09-08 09:14:18
|
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. > > |