diff --git a/include/class.i18n.php b/include/class.i18n.php index ed3df93bfcdbbb44fcfc9b4a1f7d0e02dcff2ece..3c0da2b24b7fd5cebfc67dad996f2cbfb95c776e 100644 --- a/include/class.i18n.php +++ b/include/class.i18n.php @@ -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'; diff --git a/include/class.topic.php b/include/class.topic.php index 9b98db058027fcbb7cee603f7f2c6a2dfc36caa3..b97513636e4f5ca935a206e0b4a662491610d049 100644 --- a/include/class.topic.php +++ b/include/class.topic.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) {