I'm trying to look for a solution for a multilanguage website. I have 4 domains:
- domain.com
- domain.be
- domain.nl
- domain.uk
According to the domain, the appropriate language has to be loaded.The language gets determined by ?lang=... I have tried modrewrite in .htaccess but it does not suit my needs. When a user visits domain.com/page the .htaccess does not process the rules. So I was thinking to do it with php. Currently, the language and the cookie gets set by this piece php:
<?php
session_start();
header('Cache-control: private'); // IE 6 FIX
if(isSet($_GET['lang']))
{
$lang = $_GET['lang'];
// register the session and set the cookie
$_SESSION['lang'] = $lang;
setcookie('lang', $lang, time() + (3600 * 24 * 30));
}
else if(isSet($_SESSION['lang']))
{
$lang = $_SESSION['lang'];
}
else if(isSet($_COOKIE['lang']))
{
$lang = $_COOKIE['lang'];
}
else
{
$lang = 'en_eu';
}
switch ($lang) {
case 'nl_be':
$lang_file = 'nl_be.php';
break;
case 'nl_nl':
$lang_file = 'nl_nl.php';
break;
case 'en_us':
$lang_file = 'en_us.php';
break;
case 'en_uk':
$lang_file = 'en_us.php';
break;
case 'en_eu':
$lang_file = 'en_eu.php';
break;
default:
$lang_file = 'en_eu.php';
}
include_once 'components/languages/'.$lang_file;
?>
I was thinking to add a some lines to determine the domain name and add some if statements to determine the language according to the domain. But I don't really know how and if this is the right way of doing it.
<?php
$url = "//{$_SERVER['HTTP_HOST']}";
if ($url == domain.be) {
$lang = 'nl_be';
}
elseif ($url == domain.uk) {
$lang = 'en_uk';
}
else ( ) {
$lang = 'en_us';
}
?>