Page 1 of 1

Multilingual Content

Posted: Thu Sep 15, 2005 2:53 pm
by Ree
I am trying to find an easy way to make my PHP 'software' (if I can call it like that) usable in different languages. I am thinking of having a separate file for each language to contain strings, and then using sessions to switch languages in user interface. Now a little problem is, that almost all of my 'worker' classes record any errors within themselves which then are retrieved as strings by whoever needs them by using $object->getError and displayed to the user. So basically you can imagine I have one language (English) scattered throughout my classes (errors, various messages etc) :). I guess that's not that great. I wonder does that mean it's not a good idea to store errors in worker objects themselves? How can I avoid any messages that would be displayed to end user in the classes that basically just do things like updating db, connecting etc? For example, my DB class sets error 'Unable to connect to DB' in itself, and this is retrieved FROM the db object and then passed to the user. Should I try to make the return values of actions performed as basic as possible (true/false, integers) and only then form end user messages according to the returned values? If following the above same example, the DB object could have a FALSE instead of the 'Unable to connect' message, and the message would be formed somewhere else (that is, not in the DB object). This kind of approach would allow me to use the same classes in all languages, as end user messages would come from different language-only files instead of classes themselves.

Maybe for you it seems no big deal, but actually I'd like to find out if storing messages in objects as I mentioned is fine, or should these message strings be formed (according to very basic return values) in some other, 'closer to the user' object(s)/script(s).

How do you handle different languages? Maybe you have some fine ideas on how to do it quickly and efficiently.

Re: Multilingual Content

Posted: Thu Sep 15, 2005 4:36 pm
by Roja
Ree wrote:Should I try to make the return values of actions performed as basic as possible (true/false, integers) and only then form end user messages according to the returned values? If following the above same example, the DB object could have a FALSE instead of the 'Unable to connect' message, and the message would be formed somewhere else (that is, not in the DB object). This kind of approach would allow me to use the same classes in all languages, as end user messages would come from different language-only files instead of classes themselves.
The way we tackled that issue in Blacknova Traders was to have error messages become error *codes*. Then we use the error code to bring up the translated "string".

So for example, if your session language was set to english, then the english variable for $lang_error[2] = 'Unable to connect', while the spanish variable would be $lang_error[2] = 'se habla no espanol'.. hehe..

Granted, I don't know how well that would work with the system you describe having, but it does make it easy to translate.. we simply don't store output text in the game - its all in the language variables.