Is there anything in the HTTP header that I can use to pick languages for php for a multilingual website?
Cheers,
Darkzaelus
PHP Localisation
Moderator: General Moderators
Re: PHP Localisation
I use this:
Code: Select all
$languageFileMapping = Array(
'en' => 'english',
'bg' => 'bulgarian',
'ru' => 'russian',
);
$defaultLanguage = 'en';
if (empty($_SESSION['language']))
{
$parsedLanguages = explode(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
foreach ($parsedLanguages as $parsedLanguage)
{
$language = substr($parsedLanguage, 0, 2);
if (array_key_exists($language, $languageFileMapping))
{
$_SESSION['language'] = $language;
break;
}
}
}
if (empty($_SESSION['language']))
$_SESSION['language'] = $defaultLanguage;There are 10 types of people in this world, those who understand binary and those who don't
-
Darkzaelus
- Forum Commoner
- Posts: 94
- Joined: Tue Sep 09, 2008 7:02 am
Re: PHP Localisation
Wonderful! Will keep this in mind when i start localising my code.
Cheers! Darkzaelus
Cheers! Darkzaelus
Re: PHP Localisation
You're welcome 
A little fix to apply:
change the IF line to:
to avoid PHP warnings
A little fix to apply:
change the IF line to:
Code: Select all
if (!empty($language) && array_key_exists($language, $languageFileMapping))There are 10 types of people in this world, those who understand binary and those who don't
-
Darkzaelus
- Forum Commoner
- Posts: 94
- Joined: Tue Sep 09, 2008 7:02 am
Re: PHP Localisation
Thanks once again!