Created
May 20, 2009 11:59
-
-
Save e1senh0rn/114767 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function localize($user) { | |
global $_CONF; | |
//detect from browser | |
$language = http_negotiate_language(array_keys($_CONF['locales'])); | |
//detect from cookie | |
if($_COOKIE['language'] && array_key_exists($_COOKIE['language'], $_CONF['locales'])) { | |
$language = $_COOKIE['language']; | |
} | |
if($user->id) { | |
if(!$user->language) { | |
$user->language = $language; | |
$user->save(); | |
} | |
$language = $user->language; | |
setcookie("language", $language, time()+86400*365, "/",".$_CONF[domain]"); | |
} | |
bindtextdomain('messages', './locale/'); | |
setlocale(LC_ALL, $_CONF['locales'][$language]); | |
textdomain('messages'); | |
return $language; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment