Page 1 of 1

How to develop multilingual website?

Posted: Sun Sep 20, 2009 10:48 am
by PHPycho
Hello forums!!

I would like to have the experts to share about developing multilingual websites.

AFAIK, Multilingual Websites generally consists of two parts:
1> Static (Form labels, Header titles, Messages etc., Generally file based)
2> Dynamic (Db Contents like Categories, news posts etc, Obviously db based)

Managing Static contents is easy which can be easily done as:

Code: Select all

en
- form_label.php
- messages.php
:
etc
nl
- form_lable.php
- messages.php
:
:
language files generally consists of associative arrays or defined as constants for the static content translation.

But the complexity part comes with the Dynamic contents translation.
I would like to know how you develop the multilingual website (esp for dynamic contents).

Thanks for the ideas/suggestions in advance.

Re: How to develop multilingual website?

Posted: Sun Sep 20, 2009 11:36 am
by cpetercarter
Multilingual static content is relatively straightforward. You simply put all the text on a web page into an associative array or arrays. So, for example, instead of putting "Click here for more information" in the script or template which produces your webpage, you do something like this:

Code: Select all

echo $trans['click_here'];
Then you have separate files for each language which contain the array $trans. The English file (english.php) might look like this for example:

Code: Select all

$trans = array ('welcome' => 'Welcome to my new website',
'click_here' => 'Click here for more information',
'gallery' => 'Photo gallery'
//etc etc
));
 
The German file deutsch.php would contain the same array, but the terms on the right hand side of the => would be in German, not English.
Finally, you need a bit of code to call the correct translation file depending on the language preference of the user.

Dynamic content is more difficult. An approach I used once (for a blogging/podcasting application) was was to include both the German and the English text in each posting, with a separator (eg ||344separator433||) in between. The software would then explode the blogtext at the separator and display only the required bit, like this:

Code: Select all

 
$blog_text = "blogtext auf deutsch||344separator433||blogtext in english";
$blog_text_bits = explode("||344separator433||", $blog_text);
if ($user_language = "deutsch") {
echo $blog_text_bits[0];
}  else  {
echo $blog_text_bits[1];
}
 
Or you could divide your blog text or other dynamic content into divs and use javascript to display the div you want and hide the others.

Re: How to develop multilingual website?

Posted: Sun Sep 20, 2009 12:26 pm
by PHPycho
Thats only for static content translation. I want some suggestion for dynmic contents ie db based contents.
Thanks

Re: How to develop multilingual website?

Posted: Sun Sep 20, 2009 1:14 pm
by Darhazer
Each table, that have text fields, which should be presented in different languages, should be separeted in 2 tables
The first contain only the general data, and the second land have reference to the first one (primaryID of the first one, language id and text fields.
There are already existing topics about creating ML tables
I'll only give a quick example:
Table News:
------------
NewsID
NewsAuthorID
NewsTimestamp
NewsCategoryID

Table NewsML:
----------------
NewsID
LanguageID
NewsTitle
NewsContent

Re: How to develop multilingual website?

Posted: Sun Sep 20, 2009 1:32 pm
by PHPycho
Thanks for the posts.Additionally,

For db design for multilingual website, i have come up with following solutions
and don't know which one is perfect also want to know if there is any other good options

Obviously firstly we need language table as:
----------------
|languages
----------------
|id
|code
|flag
|is_active
----------------
Possible solutions
1> using one table(suppose we have 'news' table for example)
------------
|news
-------------
|id
|language_id
|title
|body
|created_by
|created_date
|is_active
:
:
2> Using two tables
------------
|news
-------------
|id
|created_by
|created_date
|is_active
:
:
---------------
|news_contents
---------------
|id
|news_id
|language_id
|title
|body
----------------
3> Using one master table for all tables which needs translation
--------------
|news
--------------
|id
|title
|body
|created_by
|created_date
|is_active
---------------
------------
|categories
-------------
|id
|title
|description
|is_active
--------------
master table:
---------------
|translation
---------------
|id
|language_id
|table_name
|table_field
|translated_value
----------------
I have found all these structure so far, dont know which one is better as i havent used such in my multilingual website.
I would like to know the pros n cons for these structures, best db structure.

Note: Any no of languages can be added ranging from 1 -> N

Thanks for the help again in advance.

Re: How to develop multilingual website?

Posted: Sun Sep 20, 2009 2:05 pm
by Darhazer
2 is the right way

1 is breaking the rules of normalization - you will have repeated data for each language. Additionally you have no common id, which make it harder to connect the different versions... think about how you will build 'view in english' link when you are displaying in spanish? You have to know the id of the news in english, and just relying that it will be on fixed offset is not good idea

3 will be horrible for maintenance and will make your queries really hard.