[thelist] Bilingual Website

Octavian Râsnita orasnita at gmail.com
Sat Apr 4 01:43:36 CDT 2009


From: "Peter Abramowicz" <pabramow at web.net>
> What I'm primarily interested in is recommendations on site structure,
> ie. is it a good idea to have an intro page where you choose your
> language or do we just default to one language and let user pick another
> or...

First, a good design is one that lets you to localize the site for more 
other languages if it is needed, and not make the site only bilingual, but 
multilingual, even at the beginning it will use only 2 locales.

For doing this, it is not good to test in the application's code or in the 
templates something like:

if (is english) {
print something in english;
} elsif (is french) {
print something in french;

because it would be very hard to maintain and it would mean changing the 
entire site if you would need to add support for a new locale.

In the templates and source code you shouldn't hard code anything that would 
appear on the web page, but use a tool for I18N/L10N 
(internationalization/localization) like gettext which I think that it is 
available for PHP also, and put all the strings that appear in a .po file 
for each language. If you'll need to add a new language, you can give a .po 
file to a translator and after she would translate to the new language, you 
will have your site in a new language automaticly.
In the source code and templates you should put only the keys which are 
translated in those .po files (that can be compiled to .mo files if PHP 
needs that).

What will be the first language that you should show to the first-time 
visitors, depend on more things.
If you target to the international users from more countries, it should 
probably be English. If you target mainly to the French speaking persons but 
know that most of them use the default Internet Explorer browser which is 
configured for English and that most of them don't know nor care about 
setting a new prefered language, you might set it to French.

I use to set the current language based on the following conditions in 
1. Check the "lang" variable from the URI or query string that was offered 
by the visitor and use the specified language. This happends if the user 
clicked the link for showing the page in a certain language. In that case, 
also set a cookie with that language.
2. Check if there is a cookie my site previously set that specifies a 
certain language, and if there is, use that language.
3. Get the prefered languages of the visitor's browser in order, and if my 
site offers a translation for the first one, use that language, if it offers 
for the second one, use that language and so on, and if it doesn't offer for 
the prefered languages at all, use English as default because it is more 
sure that the visitor will understand it.

Sometimes it is helpful to use the language based on the country of the 
visitors also.

These things are valid if you want to localize the interface of your site. 
If your site should have the main content in 2 or more languages - articles 
written in more languages, you can't use a tool like gettext, but need to 
create your own language management. For doing this, you can simply create a 
table with all the languages, with the name of the language and an ID, and 
another table with translations, with the ID of the language, the key for 
the current piece of text and the translated text.

Of course, you can mix these 2 ways, because if you'll add a few new pages 
to your site, it would be much easier to add new string translations in a 
.po file than adding new rows in a database table.

And, there other advantages of using gettext... for example perl has tools 
that allow you to automaticly extract the strings that should be translated 
from source code and template files, and create the .po files automaticly, 
so they just need to be translated, and PHP might also offer this kind of 


More information about the thelist mailing list