Multiple languages on a website. How?
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?
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.
Originally Posted by andx85
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>
It does get tedious both on the page development and the maintenance of the XML content, but the result is very nice.
Interesting. The XML, looks like a real good solution. Thanks
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.
Originally Posted by andx85
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.
hmm.. I see. I'm gonna have to think this through a bit before I start.
You've been very helpfull, thanks!
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.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)