Skip to content
Snippets Groups Projects
Commit 196a1576 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #2357 from greezybacon/issue/2350


topic: Sort localized list case insensitively

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents 79c44ef4 d90093a3
No related branches found
No related tags found
No related merge requests found
......@@ -461,6 +461,28 @@ class Internationalization {
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() {
require_once INCLUDE_DIR . 'class.translation.php';
......
......@@ -347,10 +347,12 @@ implements TemplateVariable {
$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,
// because the locale is not going to be changed within a single
// request.
if ($localize)
return Internationalization::sortKeyedList($requested_names);
return $requested_names;
}
......@@ -520,16 +522,7 @@ implements TemplateVariable {
if (!($names = static::getHelpTopics(false, true, false)))
return;
if ($cfg && function_exists('collator_create')) {
$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);
}
$names = Internationalization::sortKeyedList($names);
$update = array_keys($names);
foreach ($update as $idx=>&$id) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment