We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 3464203a authored by elleo's avatar elleo

If the language gets set explicitly by the user then store it in a cookie for future usage

Otherwise attempt to magically work out the locale from HTTP_ACCEPT_LANGUAGE
parent 4dd8bd4c
......@@ -25,9 +25,23 @@ require_once('smarty/Smarty.class.php');
if($_GET['lang']) {
$languages = array($_GET['lang'] . ".UTF-8");
setcookie('lang', $_GET['lang'] . ".UTF-8", time() + 31536000);
} elseif (isset($_COOKIE['lang'])) {
$languages = array($_COOKIE['lang']);
} else {
//TODO: Convert HTTP_ACCEPT_LANGUAGE to a gettext locale
// Attempt to mangle browser language strings in to valid gettext locales (needs a big lookup table to be 100% accurate)
$languages = preg_split("/,/", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
for($i = 0; $i < count($languages); $i++) {
$languages[$i] = preg_replace('/;q=\d\.\d/', '', $languages[$i]);
if(strlen($languages[$i]) == 2) {
$languages[$i] = $languages[$i] . '_' . strtoupper($languages[$i]);
} elseif (stristr($languages[$i], '-')) {
$lcomponents = preg_split('/-/', $languages[$i]);
$languages[$i] = $lcomponents[0] . '_' . strtoupper($lcomponents[1]);
}
$languages[$i] = $languages[$i] . ".UTF-8";
}
}
setlocale(LC_ALL, $languages);
bindtextdomain("nixtape", $install_path . '/themes/' . $default_theme . '/locale/');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment