Skip to content
Snippets Groups Projects
Commit d90093a3 authored by Jared Hancock's avatar Jared Hancock
Browse files

topic: Sort localized list case insensitively

parent f3244b5b
No related branches found
No related tags found
No related merge requests found
...@@ -461,6 +461,28 @@ class Internationalization { ...@@ -461,6 +461,28 @@ class Internationalization {
return $locales; return $locales;
} }
static function sortKeyedList($list, $case=false) {
global $cfg;
if ($cfg && function_exists('collator_create')) {
$coll = Collator::create($cfg->getPrimaryLanguage());
if (!$case)
$coll->setStrength(Collator::TERTIARY);
// UASORT is necessary to preserve the keys
uasort($list, function($a, $b) use ($coll) {
return $coll->compare($a, $b); });
}
else {
if (!$case)
uasort($list, function($a, $b) {
return strcmp(mb_strtoupper($a), mb_strtoupper($b)); });
else
// Really only works on ascii names
asort($list);
}
return $list;
}
static function bootstrap() { static function bootstrap() {
require_once INCLUDE_DIR . 'class.translation.php'; require_once INCLUDE_DIR . 'class.translation.php';
......
...@@ -347,10 +347,12 @@ implements TemplateVariable { ...@@ -347,10 +347,12 @@ implements TemplateVariable {
$requested_names[$id] = $n; $requested_names[$id] = $n;
} }
// XXX: If localization requested and the current locale is not the // If localization requested and the current locale is not the
// primary, the list may need to be sorted. Caching is ok here, // primary, the list may need to be sorted. Caching is ok here,
// because the locale is not going to be changed within a single // because the locale is not going to be changed within a single
// request. // request.
if ($localize)
return Internationalization::sortKeyedList($requested_names);
return $requested_names; return $requested_names;
} }
...@@ -520,16 +522,7 @@ implements TemplateVariable { ...@@ -520,16 +522,7 @@ implements TemplateVariable {
if (!($names = static::getHelpTopics(false, true, false))) if (!($names = static::getHelpTopics(false, true, false)))
return; return;
if ($cfg && function_exists('collator_create')) { $names = Internationalization::sortKeyedList($names);
$coll = Collator::create($cfg->getPrimaryLanguage());
// UASORT is necessary to preserve the keys
uasort($names, function($a, $b) use ($coll) {
return $coll->compare($a, $b); });
}
else {
// Really only works on English names
asort($names);
}
$update = array_keys($names); $update = array_keys($names);
foreach ($update as $idx=>&$id) { foreach ($update as $idx=>&$id) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment