homepage Welcome to WebmasterWorld Guest from 23.22.179.210
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How to manage multilanguage website?
xnavigator




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

Hello guys,

considering this situation:

there is 1 server,
there are many domains like this:
domain.co.uk
domain.fr
domain.de
etc

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?
thanks

 

stuartindigo




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

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.

xnavigator




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

No i can't use this solution..

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

etc

Sp4rkyM4rk




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

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.

<?php

$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');
break;

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

default:
require ('en-us.php');

}
?>

xnavigator




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

yea that is a solution

xnavigator




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

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

xnavigator




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

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

superfast502




msg:4214613
 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

[netbuilders.org...]

Best of luck

paperso




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

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.

func( LANG_CONTACT_US );

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

paperso




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

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

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

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

Index.php
<?PHP

echo LANG_CONTACT_US;
?>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved