multilingual website design

Associate
Joined
14 Apr 2003
Posts
1,101
Hi,

What is the best way to design a multilingual website?

Currently I have two directories:

en/ for english
esp/ for spanish

I dont have a /index.html page so i automatically redirect all users to /en/index.html.

They can change to and from Spanish by a link at the top of each page.

As this is my first multilingual webpage I didn't really design it too well. I am just wondering if this is the best way to go about it or are there fancier ways? (I know ASP.NET has some language stuff built in but this is with PHP). Also I am concerned about the effects that the redirect may have on SEO.
 
The multi-language web applications I have worked on (English and Japanese) have used translate tokens. All the information is stored in a database and you call the information using a token (i.e translate(product_line)) and its goes off to the database and depending on the locale specified in the user session it will bring back either the English or the Japanese (or whatever language). This is good as it provide complete data abstraction.

So the table would be like

Token (as Primary Key), English, Japanese, ....other languages, Comments, Description.

Someone may have a better way however.
 
The multi-language web applications I have worked on (English and Japanese) have used translate tokens. All the information is stored in a database and you call the information using a token (i.e translate(product_line)) and its goes off to the database and depending on the locale specified in the user session it will bring back either the English or the Japanese (or whatever language). This is good as it provide complete data abstraction.

So the table would be like

Token (as Primary Key), English, Japanese, ....other languages, Comments, Description.

Someone may have a better way however.


Thank-you. It sounds like a lot of work to convert it, however, I can clearly see the benefits when it comes to adding new pages etc...
 
The initial setup up isn't too bad, I can guide you on how to do it.

After that, maintenance is a doddle and you can add as many languages as possible.

Let me know if you come up with another way of doing.
 
I might have a bash at doing 1 page to see how easy it is, but I don't have much spare time - it doesn't need doing it was just something i found interesting.

How would I start off then? :p
 
Ok where to start, you are using PHP right? You will need a backend database, let's use MySQL. I am guessing you have a layout using XHTML/CSS. All data will be stored in the database. You will have to get to grips with MySQL, but I suggest you use PHPMyAdmin to set up you database. Create a database and set up a table called something like 'web_content'. Add the following columns (make make make sure its utf-8 or you will have all kinds of problem with special characters later on!).

token (as your primary key, has to be unique, set this as an index aswell)
english (this will be.....you guessed, your english content)
spanish (the spanish translation of the english)
comment (put something descriptive in here is you like)

You will need to open a user session in PHP and save the language the user selects. Then were you need to grab the content make a call to a function like Translate(sToken). Translate(sToken) can then go off and do something like

SELECT * FROM web_content WHERE token='$sToken'

And that should be it. There are a few things that also be done. You could store them in flat text files instead of a database, this may well be faster and easy to setup initially. If you go down the database your, consider putting the above SQL statement in a stored procedure and do an exec from the PHP.

Sorry if I have skimmed over it abit, any Q's ask away!
 
nah thats great thanks. I do have MySQL but they dont hve phpmyadmin, no worries I'll just do it by hand. Is there a way to select the language by the language they use on their machine?? Or do they have to select?
 
Yes I belive you can detect the browser locale ID and use that to set the language. IIRC 2057 = english, and you can use the HTTP_ACCEPT_LANGUAGE session variable to get the locale ID
 
Hi,

I've started designing my database for this site. I was wondering how you deal with paragraphs. Say I want two paragraphs on a page - are these two different tokens? What if you want a link? Is that a token? I think I'm going to have to have more fields...
 
Yes I think the two paragraphs would be 2 different tokens. If you want a link just embed the <a> tags in the token.

"The is a paragraph and it has a <a href="page.php">link</a>".

The PHP will render the link when it outputs it to the page. There might be better way of doing it, but I did it this way.
 
ok, i realise now that it isn't as simple as I first thought..

I'm trying to kill two birds with one stone and allow them (the clients) to create and change pages without having to pester me. However, this is going to be slightly tricky as soon as they require anything other than text :p

I might just make a basic system that they can do limited stuff to i.e. edit what is already there... I suppose it will only be useful for a latest news page.
 
ok, i realise now that it isn't as simple as I first thought..

I'm trying to kill two birds with one stone and allow them (the clients) to create and change pages without having to pester me. However, this is going to be slightly tricky as soon as they require anything other than text :p

I might just make a basic system that they can do limited stuff to i.e. edit what is already there... I suppose it will only be useful for a latest news page.

Yes it gets tricky when they ask for something other than text, I had this problem when writing content management systems. Because you don't want they just inserting there own HTML tags because it presents a SQL injection/cross site scripting vulnerability. You can create a basic WYSIWYG edit that allows markup and links to be embedded.
 
yeah i have a feeling thats the way its heading.

While you're here... you mentioned i had to set my database to utf8, which i have done, but im still getting question marks all over the shop.

I have tried the following as well - which apparently helps:

SET NAMES 'utf8';

just after ive selected the database and before i run a query.
 
Ahh welcome to the world of globalisation and encoding. I suggest you make sure EVERYTHING is set to UTF-8. Are the ???? appearing on the HTML page or actually in the database?
 
the website. I have other accented characters rendering fine - its just the stuff coming back from the database.

In phpMyAdmin the characters are displaying fine... its frustrating but im getting on with other things as well.
 
the website. I have other accented characters rendering fine - its just the stuff coming back from the database.

In phpMyAdmin the characters are displaying fine... its frustrating but im getting on with other things as well.

So you have set the charset="utf-8" in the <meta> tags on the HTML page? I think it maybe the PHP encoding needs setting. I haven't coded in PHP for over a year, but I think it might have to be set in the php.ini or using iconv_get_encoding and iconv_set_encoding. Check out the PHP manual.
 
Keep googling, someone will have had the same problem. I don't know of the top of my head, I am a ASP.NET man these days (not for much longer hopefully! I hate it!).
 
Back
Top Bottom