From: ing. L. Tur <luc...@pd...> - 2004-09-06 14:35:48
|
Hello Phil, sorry for my silence, but I had some troubles that kept me away from work. I've seen that you started to work on the gettext solution. I've spent some time last week to study the approach of gettext, and my opinion is that we the gettext solution is efficient but has the problem that the translations can be done without any control, i.e. you simply change a text file. Given thsi I have started thinking how I could get the best from the gettext approach and still keeping the db repository for the languages. I made some experiment and sorted out the following. In my "language.php" file I've defined a function translate(), which receives a parameter which can be a string or an identifier. The function uses the $lang array, which contains all the translations needed, and which is loaded at the beginning. function translate($idOfLabelToBeTranslated) { global $lang; if ($lang[$idOfLabelToBeTranslated]!=null) return $lang[$idOfLabelToBeTranslated]; else return $idOfLabelToBeTranslated; } As you can see translate simply returns the translated message, which has then to be echoed (so it is very similar to gettext_noop...) I also enlarged the db column containing the label identifier: now it's 100 chars and can be enlarged again. Since $idOfLabelToBeTranslated can be a string you can maintain code readability, as you can see in the following chunk of code from SelectCustomer.php .... if ($_POST['Search']==translate("Search Now")){ If ($_POST['Keywords'] AND $_POST['CustCode']) { $msg= translate("Customer name keywords have been used in preference to the customer code extract entered."); $_POST["Keywords"] = strtoupper($_POST["Keywords"]); } If ($_POST['Keywords']=="" AND $_POST['CustCode']=="") { $msg=translate("At least one customer name keyword OR an extract of a customer code must be entered for the search"); ..... As you can understand, using this approach I am addressing your main concern, which is maintaining the code easy to read. But also I am addressing my 2 concerns: having the application working at any time, even during translation, and having a simple way to translate without the danger of destroying the application. These issues are very important to me; since I believe that a translator have to be free to see exactly where a certain sentence appears, in order to deeply understand the meaning and give a proper translation. A translation with the gettext approach is done without simultaneously looking at the application. Using my approach you can have one browser on the application and the other one in the application created for translation (i.e. some php pages that show the original and let you write the translation in a form) Now I am trying to solve the problem of parameters within a sentence, and in particular the fact that the position of parameters can change from one language to another (see the english-german example in the gettext documentation).. Finally: Phil, if you don't like this approach, i am going to bend down and conform to you decision. The use of "translate" function is exactly as gettext_noop, so it'll be easy to adapt. But please first try to consider the db solution. Luca |