From c8c02ae0a8a4cbb11c0d76386ab12fad73376aef Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 23 Jan 2009 13:41:37 +0000 Subject: Moved current language detection out into the function get_language(); git-svn-id: https://code.elgg.org/elgg/trunk@2607 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/languages.php | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'engine') diff --git a/engine/lib/languages.php b/engine/lib/languages.php index 5c62eaa81..096980bb3 100644 --- a/engine/lib/languages.php +++ b/engine/lib/languages.php @@ -69,6 +69,35 @@ return $language; } + /** + * Gets the current language in use by the system or user + * + * @return string The language code (eg "en") + */ + function get_language() { + + global $CONFIG; + static $lang; + + if (isset($lang)) return $lang; + + $user = get_loggedin_user(); + + if ((empty($language)) && (isset($user)) && ($user->language)) + $language = $user->language; + + if ((empty($language)) && (isset($CONFIG->language))) + $language = $CONFIG->language; + + if (!empty($lang)) { + $lang = $language; + return $lang; + } + + return false; + + } + /** * Given a message shortcode, returns an appropriately translated full-text string * @@ -78,16 +107,10 @@ */ function elgg_echo($message_key, $language = "") { - global $CONFIG; - - $user = get_loggedin_user(); - - if ((empty($language)) && (isset($user)) && ($user->language)) - $language = $user->language; - - if ((empty($language)) && (isset($CONFIG->language))) - $language = $CONFIG->language; + global $CONFIG; + $language = get_language(); + if (isset($CONFIG->translations[$language][$message_key])) { return $CONFIG->translations[$language][$message_key]; } else if (isset($CONFIG->translations["en"][$message_key])) { @@ -105,7 +128,7 @@ */ function register_translations($path) { global $CONFIG; - + if (isset($CONFIG->debug) && $CONFIG->debug == true) error_log("Translations loaded from : $path"); if ($handle = opendir($path)) { @@ -126,7 +149,7 @@ { global $CONFIG; - $installed = array(); + $installed = array(); foreach ($CONFIG->translations as $k => $v) { -- cgit v1.2.3