Language depending on cookie or browser
Posted: Wed Oct 08, 2008 12:40 am
I have a script which generates a langaugefile like this:
As you can see it generates the language depending on "lang_id".
I want it to choose which lang_id it should use depending on first, if a cookie is active with the preferred language like this:
If the cookie is not set it should look at what language browser is like this:
And if the browsers lang is unsupported it should go to the default language which is lang_id=1.
I have a db table (".$prefix."_lang_languages) with the installed language with these fields(id, lang_long, lang_short) where the lang_short field is the field that matches the browser lang id (en, de, da, se, etc...)
Can this be done and if yes... how? Hope somebody can help or guide me in the right direction
Code: Select all
$sql = $db->sql_query("SELECT * FROM ".$prefix."_lang_code WHERE lang_id=2");
while ($row = $db->sql_fetchrow($sql)) {
define("_".$row['tagname']."","".$row['string']."");
echo 'Tagname: _'.$row['tagname'].' | Text: '.$row['string'].'<br>';
}I want it to choose which lang_id it should use depending on first, if a cookie is active with the preferred language like this:
Code: Select all
$cookie_read = explode("|", base64_decode($user));
//define variables to hold cookie values.
$userid = $cookie_read[0];
$language = $cookie_read[6];Code: Select all
$browser_lang = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );I have a db table (".$prefix."_lang_languages) with the installed language with these fields(id, lang_long, lang_short) where the lang_short field is the field that matches the browser lang id (en, de, da, se, etc...)
Can this be done and if yes... how? Hope somebody can help or guide me in the right direction