diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/general.php | 9 | ||||
-rw-r--r-- | includes/lib/l10n.php | 66 | ||||
-rw-r--r-- | includes/loggedin.php | 13 |
3 files changed, 43 insertions, 45 deletions
diff --git a/includes/general.php b/includes/general.php index d608d2d..8687ee6 100644 --- a/includes/general.php +++ b/includes/general.php @@ -72,6 +72,7 @@ } L10n::detect_language(); + L10n::init_gettext(); if(array_key_exists('profile',$_SESSION) && is_array($_SESSION['profile']) && array_key_exists('id',$_SESSION['profile']) && $_SESSION['profile']['id'] > 0) { @@ -518,14 +519,6 @@ return(utf8_decode($data)); } - function screenshot($img) - { - if(file_exists("../screenshots/".$_SESSION['_config']['language']."/$img")) - return("/screenshots/".$_SESSION['_config']['language']."/$img"); - else - return("/screenshots/en/$img"); - } - function signmail($to, $subject, $message, $from, $replyto = "") { if($replyto == "") diff --git a/includes/lib/l10n.php b/includes/lib/l10n.php index 58b6859..1a8109b 100644 --- a/includes/lib/l10n.php +++ b/includes/lib/l10n.php @@ -228,7 +228,8 @@ class L10n { /** * Get the set translation * - * @return string a translation code or the empty string if not set + * @return string + * a translation code or the empty string if not set */ public static function get_translation() { if (array_key_exists('language', $_SESSION['_config'])) { @@ -241,8 +242,8 @@ class L10n { /** * Set the translation to use. * - * @param string $translation_code the translation code as specified in - * the keys of {@link translations} + * @param string $translation_code + * the translation code as specified in the keys of {@link $translations} * * @return bool * <ul> @@ -297,37 +298,46 @@ class L10n { return false; } - // configure gettext - $domain = 'messages'; - bindtextdomain($domain, $_SESSION['_config']['filepath']."/locale"); - textdomain($domain); - - - // save the setting - $_SESSION['_config']['language'] = $translation_code; - - // Set up the recode settings needed e.g. in PDF creation - $_SESSION['_config']['recode'] = "html..latin-1"; - - if($translation_code === "zh-cn" || $translation_code === "zh-tw") - { - $_SESSION['_config']['recode'] = "html..gb2312"; + // only set if we're running in a server not in a script + if (isset($_SESSION)) { + // save the setting + $_SESSION['_config']['language'] = $translation_code; - } else if($translation_code === "pl" || $translation_code === "hu") { - $_SESSION['_config']['recode'] = "html..ISO-8859-2"; - } else if($translation_code === "ja") { - $_SESSION['_config']['recode'] = "html..SHIFT-JIS"; - - } else if($translation_code === "ru") { - $_SESSION['_config']['recode'] = "html..ISO-8859-5"; - - } else if($translation_code == "lt") { // legacy, keep for reference - $_SESSION['_config']['recode'] = "html..ISO-8859-13"; + // Set up the recode settings needed e.g. in PDF creation + $_SESSION['_config']['recode'] = "html..latin-1"; + if($translation_code === "zh-cn" || $translation_code === "zh-tw") + { + $_SESSION['_config']['recode'] = "html..gb2312"; + + } else if($translation_code === "pl" || $translation_code === "hu") { + $_SESSION['_config']['recode'] = "html..ISO-8859-2"; + + } else if($translation_code === "ja") { + $_SESSION['_config']['recode'] = "html..SHIFT-JIS"; + + } else if($translation_code === "ru") { + $_SESSION['_config']['recode'] = "html..ISO-8859-5"; + + } else if($translation_code == "lt") { // legacy, keep for reference + $_SESSION['_config']['recode'] = "html..ISO-8859-13"; + + } } return true; } + + /** + * Sets up the text domain used by gettext + * + * @param string $domain + * the gettext domain that should be used, defaults to "messages" + */ + public static function init_gettext($domain = 'messages') { + bindtextdomain($domain, $_SESSION['_config']['filepath'].'/locale'); + textdomain($domain); + } }
\ No newline at end of file diff --git a/includes/loggedin.php b/includes/loggedin.php index bf6b455..5734fad 100644 --- a/includes/loggedin.php +++ b/includes/loggedin.php @@ -17,6 +17,7 @@ */ include_once("../includes/lib/general.php"); + require_once("../includes/lib/l10n.php"); if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && $_SESSION['profile']['id'] > 0 && $_SESSION['profile']['loggedin'] != 0) { @@ -110,18 +111,12 @@ if($_SESSION['profile']['language'] == "") { - $query = "update `users` set `language`='".$_SESSION['_config']['language']."' + $query = "update `users` set `language`='".L10n::get_translation()."' where `id`='".$_SESSION['profile']['id']."'"; mysql_query($query); } else { - $_SESSION['_config']['language'] = $_SESSION['profile']['language']; - - putenv("LANG=".$_SESSION['_config']['language']); - setlocale(LC_ALL, $_SESSION['_config']['language']); - - $domain = 'messages'; - bindtextdomain("$domain", $_SESSION['_config']['filepath']."/locale"); - textdomain("$domain"); + L10n::set_translation($_SESSION['profile']['language']); + L10n::init_gettext(); } } |