Welcome to WebmasterWorld Guest from 54.221.87.97

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Multi Language Sites

Best way to do it.

     

ryan_b83

9:01 pm on Dec 10, 2007 (gmt 0)

5+ Year Member



Hello I am planning to build a PHP/MySQL based product/category site. It needs to be able to display both English and French. The way I would structure the database would be:

titleEnglish
titleFrench

descriptionEnglish
descriptionFrench

And so forth... which isn't too bad, however what about for the static content on all the pages? I was thinking just making it session based and every peice of content would need an if statment.... so for example....

if($_SESSION['lang'] == "english"){
?>
english content here...
<?
}
else{
?>
french content here...
<?
}

This seems like alot of work for just static content but it seems like the only way... or does anyone else have suggestions?

Thanks,
Ryan

LifeinAsia

10:02 pm on Dec 10, 2007 (gmt 0)

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



You can put the static text in text files and just read the appropriate file based on the language.

gergoe

11:22 pm on Dec 10, 2007 (gmt 0)

10+ Year Member



What I have used to do is to store every piece of text in database (even if only two languages are needed), and there's an another table, which maps the texts to pages, and each time a page is loaded the mapped texts are automatically loaded into a variable (well, I used the oop approach, so it is not a simple variable), and when a text has to be displayed, a function is called, which returns the the text (using the selected language) by using a codename (defined for each text). Although not sure my description is clear, that's the way I found for myself.

Quite some other products chosen to make include files which are defining hundreds of constants (for each language), and then it uses these constants for displaying texts.

Whatever you choose, don't forget to check out the printf() [php.net] series of functions as they come very handy when dealing with multilingual content.