Building a multilingual site using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Building a multilingual site using PHP

Post by kendall »

Hello,

I would lie to get some advice concerning in building multi-lingual sites dynamically using PHP

i have a website that i need to build with an english and a spanish version.

I am still novice in PHP but would like to attempt a plan that would bring up the appropriate version dependant on the users selection.

I also want to do it without doing the same thing twice if you understand what i mean.

IS there any tutorials or has anyone built a site in comparison

i want to know like

what is the best approach
what methods do i use
would this be easier with javascript?

i was thinking about using a code that switches the BASE URL from a english to a spanish folder
e.g.

BASE URL = http://www.thedomain.com/spanish
if english
echo BASE URL = http://www.thedomain.com/english

any other suggestion of how i can approach this

Kendall
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

this board for example uses language templates.
e.g. there is a file lang_main.php in language/lang_english and language/lang_german.
lang_english/lang_main.php sets $lang['Post_new_topic'] = 'Post new topic'; but lang_german/lang_main.php sets $lang['Post_new_topic'] = "Neuen Beitrag schreiben";.
Dependig on which file you include echo $lang['Post_new_topic'] will output the english or the german version.
Wether this is applicable for your website depends on the amount of text and the complexity to install the template(s).
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I would simply try to code some sort of automatic translation fetching device from Bablefish.

Or simply point your users to Bablefish or a similar translation site, but remember translators might not pick up slang or some "politically incorrect" sentences and the translation may not work properly.

What volka suggested is a very good way to do a multilingual site. It requires much more work and effort than the way i suggested but it gets the job done. And well might i add since you are defineing all the variables and not some strange translator some odd-named company owns. :)
Post Reply