| Ultrashock Forums
• [PHP] Multi language |
|||
![]() |
||||
| Search this Thread | Thread Tools | Display Modes |
|
|
|||||||||||||||||||||||||
![]() |
Ultrashock Member Comments:
|
|
2007-01-30
#2 |
||
|
I'm pretty sure there's someone here knowing more than me on this topic. Anyone to share his/her knowledge?
|
|
|
2007-01-30
#3 |
||
|
If you're running a Linux server you can checkout gettext (I don't think it works on Windows, but I'm not sure). I've done a more simple solution that's platform independent and I can give you an example later when I get back from work. Cheers |
|
|
|
2007-01-30
#4 |
||
|
I'd really dig that, poppa. You're the man
|
|
|
2007-01-30
#5 |
||
|
I use to create a .php file where i define all my string variables and use these within my pages instead of text. If text is stored in a database i create multiple table and access them accordingly by a table prefix i.e. gr_news, eng_news, de_news etc. Cheers 'A' |
|
|
2007-01-30
#6 |
||
|
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. |
|
|
|
2007-02-01
#7 |
||
|
I have been looking into gettext since your last post. Seems like neat stuff. I'm not really for the idea of using arrays of strings and of the kind. I'll have a look at your solution before deciding. Thanks poppa! |
|
|
|
2007-02-03
#8 |
||
|
I've been thinking on this subject for two days now. I've decided, I'm going with a mixed solution. On one side, my static content is going to be stored in arrays. It's a fairly low amount of strings, so it should be fairly maintainable. If the amount ever increases I can always switch over to gettext, which I have been unable to get to work with CakePHP. On the other side, a big part of the site's content is editable through a hand crafted cms, and the client needs to enter most of this information in several languages. This leads me to store these strings in a translations table in my database. However, I'm still unsure about the exact structure of my data. Consider this a rant. This site is getting interesting. I'll be writing a little guide for my upcoming weblog. |
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|



7 comments
| 237 views


Linear Mode