View Single Post
poppa's Avatar poppa poppa is offline Moderator 2007-01-30 #6 Old  
Last edited by poppa : 2007-01-30 at 14:34.
Okey, here we go:

The code is popped out of a project I'm working on but I think I got it pretty generic.

You'll see that there are some <langcode>.lang.php files in there and these are the files with the actual translations. Note, that you can very well populate the array in these files with content from a DB. They are just regular PHP files with a single array and how you populate these arrays is up to you.

At the moment the code decides what language to use based on the primary language set in the user's browser. But there would be no problem implementing the ability to swap language manually.

Last in the Locale.php you'll see a function called getLocale which returns the Locale object. The function assume you name your locale object $LOCALE but if you name it something else just change that function accordingly.

You'll find the code here, and there's an example implementation. If you use Firefox you can add "Swedish" to languages and set it as default to see the example live.

[EDIT]
Here are two screen dumps, one where I have Swedish as default language and one where I have English:

http://www.poppa.se/us/locale-sv.png
http://www.poppa.se/us/locale-en.png
[/EDIT]

If you have any questions just ask.
And BTW: This is PHP5 code.
Reply With Quote