[geeklog-devel] Re: Translation class (IRC)

Tony Bibbs tony at tonybibbs.com
Wed Apr 9 19:39:51 EDT 2003


Dirk Haun wrote:
>     $translator = new Translator('de-at');
> 
> (de-at = Austrian German) and there is no de-at translation, it should be
> looking for 'de' first and only if that does not exist fall back to 'en'.

I think how all this works will be much clearer once I get a beta 
release wrapped up.  However, your point above is great as I didn't 
understand the basic workings of stuff like this (hence the great series 
of checks-and-balances you and other non-us folks provide).

> In the end, that language code will come from some user configurable
> setting (the GL2 equivalent of config.php or the user's preferences), so
> that's something the class itself should handle, not the code using the class.

Incorrect, that setting is *not* user configurable.  To be clear:

$translator = new Translator('en');

This line tells the instanstiated translator that this application was 
developed with English strings.  That means that every call to 
$translator->translate('<some string>') requires the value for <some 
string> to be in english.

There is another method (I failed to post to IRC) which is setLanguage():

$translator->setLanguage('de-at');

This sets the user language (I will change the method name to be more 
descriptive.

Requiring both is important.  The translate() method will check to see 
if the *native* language in the code (english) matches that the user 
wants (de-at).  In that case they don't match which would cause some the 
de-at.xml file to be loaded to use for translations.  Now if you passed 
'en' to setLanguage(), the translator would notice this and instead of 
loading the en.xml file, it knows the strings passed to translate() are 
english so it would just return the passed string saving any file I/O.

The clear benefit is that the native language will yield the greatest 
performance benefits which is what you want.

The beta code will make this clearer.

--Tony

> 
> bye, Dirk
> 
> P.S. Tony, the geeklog-devel digest postings to geeklog-devtalk are also
> held back for approval now. Can you look into that, please?
> 
> 


-- 
+-------------------+--------------------------------------------------+
|Tony Bibbs         |[R]egardless of what you may think of our penal   |
|tony at tonybibbs.com |system, the fact is that every man in jail is one |
|                   |less potential fisherman to clutter up your       |
|                   |favorite pool or pond. --Ed Zern                  | 

+-------------------+--------------------------------------------------+




More information about the geeklog-devel mailing list