Commit ac4338d7 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Split locale-setting code out of current_language function



When generating new clean urls, transliteration of utf8 characters
works better when the locale is set appropriately, so it will be
useful to be able to change locales without having to change the
current language.

Change-Id: Ife9e65661dc582cb830a20c73cecd6942d28d62c
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 7e189ab6
......@@ -1024,6 +1024,23 @@ function print_object($mixed) {
echo '</pre>';
}
/**
* Reads the locales string from a language pack and attempts to set the current locale
* based on the contents of that string.
*
* @param string $lang
*/
function set_locale_for_language($lang) {
if (empty($lang)) {
return;
}
if ($args = split(',', get_string_location('locales', 'langconfig', array(), 'raw_langstring', $lang))) {
array_unshift($args, LC_ALL);
call_user_func_array('setlocale', $args);
}
}
/**
* This function returns the current
* language to use, either for a given user
......@@ -1066,12 +1083,7 @@ function current_language() {
return $lang;
}
// Set locale. We are probably being called from get_string_location.
// $lang had better be non-empty, or it will call us again.
if ($args = split(',', get_string_location('locales', 'langconfig', array(), 'raw_langstring', $lang))) {
array_unshift($args, LC_ALL);
call_user_func_array('setlocale', $args);
}
set_locale_for_language($lang);
return $lastlang = $lang;
}
......
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