Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How to manage multilanguage website?



6:08 pm on Aug 23, 2010 (gmt 0)

5+ Year Member

Hello guys,

considering this situation:

there is 1 server,
there are many domains like this:

all of them point to the server.

Now how would u manage the html lanague output?

Consider when ever a user opens a domain always the same index.php is called, i was thinking to put a function that checks $_SERVER['HTTP_HOST'] to set the right template language

The problem with this solution is the eventual customization that i will need for a paritcular domain...

Do u know how the php framework like CakePHP etc manage the multilanague website?


10:22 am on Aug 25, 2010 (gmt 0)

5+ Year Member

I wouldn't use a script based on initial domain called, but would suggest that based on the browser language preference is far better.

The call would then be to PHP $_SERVER["HTTP_ACCEPT_LANGUAGE"]
with redirects mirrored to the various language versions each in their own folder (eg to en/index.php, fr/index.php)

There are plenty of scripts avilable in bath php and javascript for this purpose.


10:43 am on Aug 25, 2010 (gmt 0)

5+ Year Member

No i can't use this solution..

the web site on .de must be in Deutsch
.fr in french



12:55 pm on Aug 25, 2010 (gmt 0)

5+ Year Member

This code will get the top level domain for you, so a domain name change shouldn't affect it too much, if at all. It doesn't give the full extension, but it's a start. So you'll find when echo'ing that you are not given 'co.uk' if you domain ends with that; you'll be given 'uk'. It essentially picks up the characters after the final dot in the domain name.


$activedomain = $_SERVER['HTTP_HOST'];

$tld = substr(strrchr($activedomain,'.'),1);

// Echo it to check

echo $tld;

// Statements to require the language files depending on the top level domain

switch ($tld)

case 'uk':
require ('en-uk.php');

case 'de':
require ('de.php');

require ('en-us.php');



1:10 pm on Aug 25, 2010 (gmt 0)

5+ Year Member

yea that is a solution


1:28 pm on Aug 25, 2010 (gmt 0)

5+ Year Member

problem is I use a template engine...

so every phrase on the template must be wrote in the right language...

i was thinking to do like CakePHP: every phrase is passed to a function like:

func('Contact US');

the func checks the lanaguage and puts the right translation..

problem with is the dynamic contnent like a ttitle of a article:

func('Read the $article_name');

$article_name would not be converted to the article title


1:36 pm on Aug 25, 2010 (gmt 0)

5+ Year Member

do u think using a func to auto-translate the phrase is a good solution?

the func code would look like this:

function func($text) {
$lang = get_language_from_domain();
if ($lang != default) {
return $TableOfTranslation[$text];
} else
return $text;

looks ugly to me


4:24 am on Oct 10, 2010 (gmt 0)

If I understand you correctly you are trying to use a single set of php files to deliver different content on different pages in different languages?

How important are these sites to you?

Why wouldn't you translate each of them and have them served separately where you could control the delivery?

It would seem to me that the management of the php and code would far outweigh in difficulty and cost the trouble of setting up individual translated sites. Dunno, but that would be my guess.

If using .php translate scripts, I have a great resource below. I hope that you can find some answers here or there


Best of luck


5:52 am on Oct 10, 2010 (gmt 0)

5+ Year Member

Write a language files for each domains and set the appropriate language for each domains as default but let user change language if in case they prefer to use english.

domain.fr the default language would be french and so on.

If you use function to translate sometimes it's better to use define.


For dynamic contents, I guess google can do this or write a function to translate it.


5:58 am on Oct 10, 2010 (gmt 0)

5+ Year Member

My mistake, I included the define in a function. Use define() like this:

define('LANG_CONTACT_US', 'Contact Us');

define('LANG_CONTACT_US', 'Contactez-nous');



Featured Threads

Hot Threads This Week

Hot Threads This Month