Click to See Complete Forum and Search --> : Multiple languages on a website. How?
andx85
12-22-2010, 03:20 AM
I was wondering how one best programs support for many different languages on a website.
I suppose every piece of text on the website has to be stored somewhere, variable or database and in the different languages and the right one will be displayed according to what setting has been chosen.
Is there any method which is considered the best?
tracknut
12-22-2010, 09:58 AM
I suppose every piece of text on the website has to be stored somewhere, variable or database and in the different languages and the right one will be displayed according to what setting has been chosen.
Yes, basically. There is another option I've seen, which is on the end of "cheap, easy, and not too good" which is to pass your entire site through Google's translation API on the fly. That lets you build a site that works in a whole bunch of languages very easily, but the translated results are pretty bad.
Personally I have a site I do in three languages by storing all the content in XML files with tags like:
<title lang="en">Good Morning</title>
<title lang="fr">Bonjour</title>
It does get tedious both on the page development and the maintenance of the XML content, but the result is very nice.
Dave
andx85
12-23-2010, 02:44 AM
Interesting. The XML, looks like a real good solution. Thanks
andx85
12-23-2010, 04:09 AM
Oh and also, you wouldn't happen to know any simple open source code/site that does this, that I could have a look at?
tracknut
12-23-2010, 09:36 AM
Oh and also, you wouldn't happen to know any simple open source code/site that does this, that I could have a look at?
I don't, sorry. There doesn't seem to be a lot of discussion on the topic, and when I went to do it I couldn't find much in the way of solid examples. It's not difficult from a coding perspective, it's just a bit nitty-gritty in terms of trying to make the end result manageable as you add content.
Basically you've got two (almost independent) components to address. Firstly how you will determine the language the user wants to see and how to make that language known in your code (e.g. little pictures of flags, cookie, session variable, browser query), and then secondly is building a set of useful routines to import the XML and display blocks of text in the appropriate language.
Dave
andx85
12-24-2010, 04:05 AM
hmm.. I see. I'm gonna have to think this through a bit before I start. :)
You've been very helpfull, thanks!
sohguanh
01-07-2011, 02:32 AM
One easy way I see websites does is upon login there are icons for you to choose which language you want. Then based on what you choose, it will direct you to the language-specific web-pages. I would presume they maintain multiple sets of web-pages for different languages ?!?!
The other way involve server side language help. In Java we have libraries called i18n or something similar. We store all translations into different language properties iles. E.g en_US store key=value for english, zh_CN store key=value for chinese. The key must be the SAME in both of them.
Then in our main program we will reference "key" and then depending on locale setting the i18n libraries will look up the corresponding language properties file and grep the "value" based on the "key".
This second approach sound complex and tedious but to me this is the most "correct" solution to handle web-pages with different language translations.