From: <luc...@pd...> - 2004-09-08 08:32:19
|
Hello all. As stated in my previous message, I was trying to solve the p= roblem of sentences with one or more parameters. As an example just consi= der -"Display ". $ModuleName . " options:"- in www_users. Here's my prop= osed solution. I am using special tags in the tobetranslated and transla= ted sentence, i.e : ENGLISH: Display __Parameter1__ options ITALIAN: M= ostra opzioni per il modulo __Parameter1__ when I have to translate t= his sentence I make this call: translate('Display __Parameter1__ options= ',$ModuleName) Here's the definition of the function translate: funct= ion translate($idOfLabelToBeTranslated) { global $lang; if ($lan= g[$idOfLabelToBeTranslated]!=3Dnull){ $numargs =3D func_num_args()= ; if($numargs >1){ $arg_list =3D func_get_args(); = $returnString=3D$lang[$idOfLabelToBeTranslated]; for ($i =3D 0= ; $i < $numargs; $i++) { //echo "Argument $i is: " . $arg_list= [$i] . "<br />\n"; $returnString =3D str_replace('__Parameter'= .$i.'__',$arg_list[$i],$returnString); } return $return= String; } else //number of arguments is 1 return = $lang[$idOfLabelToBeTranslated]; } else //there is no translated = label in the array return $idOfLabelToBeTranslated; } As you ca= n see it takes a variable number of arguments. If we have more than 1 arg= umentes, i.e. some parameters have to be inserted in the sentence, it sim= ply gets the translated label, which contains the varios strings __Parame= ter1__ ... __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. |