Skip to content

Instantly share code, notes, and snippets.

@e1senh0rn
Created May 20, 2009 11:59
Show Gist options
  • Save e1senh0rn/114767 to your computer and use it in GitHub Desktop.
Save e1senh0rn/114767 to your computer and use it in GitHub Desktop.
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