Use intl Collator to sort strings
authorMarcel Werk <burntime@woltlab.com>
Thu, 28 Sep 2023 15:30:35 +0000 (17:30 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 28 Sep 2023 15:30:35 +0000 (17:30 +0200)
See #4672

wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php
wcfsetup/install/files/lib/acp/form/DataImportForm.class.php
wcfsetup/install/files/lib/acp/form/LanguageExportForm.class.php
wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php
wcfsetup/install/files/lib/acp/page/TemplateListPage.class.php
wcfsetup/install/files/lib/action/EditorGetMentionSuggestionsAction.class.php
wcfsetup/install/files/lib/data/user/UserAction.class.php
wcfsetup/install/files/lib/data/user/group/UserGroup.class.php
wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php
wcfsetup/install/files/lib/system/search/acp/ACPSearchResultList.class.php

index 542cca4dda511e03b86a967b4de5e1533020a7d8..81ee80abd3a85b413aba589a15007efc121af493 100644 (file)
@@ -260,13 +260,14 @@ class BoxAddForm extends AbstractForm
         }
 
         $this->availableBoxControllers = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.boxController');
-
-        \uasort($this->availableBoxControllers, static function (ObjectType $a, ObjectType $b) {
-            return \strcmp(
+        $collator = new \Collator(WCF::getLanguage()->getLocale());
+        \uasort(
+            $this->availableBoxControllers,
+            static fn (ObjectType $a, ObjectType $b) => $collator->compare(
                 WCF::getLanguage()->get('wcf.acp.box.boxController.' . $a->objectType),
                 WCF::getLanguage()->get('wcf.acp.box.boxController.' . $b->objectType)
-            );
-        });
+            )
+        );
 
         $this->readBoxPositions();
     }
index 1a1cd34c7b53d12fd6f4f2d4ec39c628f28e78a6..052e8d50464dc34ff4c323584e95ecb082ed67e9 100644 (file)
@@ -133,12 +133,14 @@ class DataImportForm extends AbstractForm
         $this->exporters = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.exporter');
 
         // sort exporters by name
-        \uksort($this->exporters, static function ($a, $b) {
-            return \strcasecmp(
+        $collator = new \Collator(WCF::getLanguage()->getLocale());
+        \uksort(
+            $this->exporters,
+            static fn (string $a, string $b) => $collator->compare(
                 WCF::getLanguage()->get('wcf.acp.dataImport.exporter.' . $a),
                 WCF::getLanguage()->get('wcf.acp.dataImport.exporter.' . $b)
-            );
-        });
+            )
+        );
 
         $this->importers = \array_keys(ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.importer'));
 
index 253b67ba151ff8cba4484ae7eaf9f9a484bc5457..aa5b9555de9be139ccbed321762845819e8a67d3 100644 (file)
@@ -151,9 +151,11 @@ class LanguageExportForm extends AbstractForm
         parent::assignVariables();
 
         $packages = PackageCache::getInstance()->getPackages();
-        \usort($packages, static function (Package $a, Package $b) {
-            return $a->getName() <=> $b->getName();
-        });
+        $collator = new \Collator(WCF::getLanguage()->getLocale());
+        \usort(
+            $packages,
+            static fn (Package $a, Package $b) => $collator->compare($a->getName(), $b->getName())
+        );
 
         WCF::getTPL()->assign([
             'languageID' => $this->languageID,
index d10466e016d9e5855f9a30f895218c4c489b2f7c..6cfd2f7ef870ba8300470e3a89450e269ce8f268 100644 (file)
@@ -174,9 +174,11 @@ class LanguageImportForm extends AbstractForm
         parent::assignVariables();
 
         $packages = PackageCache::getInstance()->getPackages();
-        \usort($packages, static function (Package $a, Package $b) {
-            return $a->getName() <=> $b->getName();
-        });
+        $collator = new \Collator(WCF::getLanguage()->getLocale());
+        \usort(
+            $packages,
+            static fn (Package $a, Package $b) => $collator->compare($a->getName(), $b->getName())
+        );
 
         WCF::getTPL()->assign([
             'languages' => $this->languages,
index 8c22b66e2d2f88464ffe2e200e1b50658702b8b0..a7859d8ce3267c1a38a9fc0c89e6b8ce30341cc1 100644 (file)
@@ -148,9 +148,11 @@ class TemplateListPage extends SortablePage
             $package->getName();
         }
 
-        \uasort($this->availableApplications, static function (Package $a, Package $b) {
-            return $a->getName() <=> $b->getName();
-        });
+        $collator = new \Collator(WCF::getLanguage()->getLocale());
+        \uasort(
+            $this->availableApplications,
+            static fn (Package $a, Package $b) => $collator->compare($a->getName(), $b->getName())
+        );
     }
 
     /**
index ddf6513102658294ed036f3566f0b2db7a049a76..0e56965860aae79b648a83d9fc848793a9bbb941 100644 (file)
@@ -10,6 +10,7 @@ use wcf\data\user\group\UserGroup;
 use wcf\data\user\UserProfile;
 use wcf\data\user\UserProfileList;
 use wcf\http\Helper;
+use wcf\system\WCF;
 
 /**
  * Suggests users that may be mentioned.
@@ -91,9 +92,11 @@ final class EditorGetMentionSuggestionsAction implements RequestHandlerInterface
             return \str_starts_with(\mb_strtolower($userGroup->getName()), $query);
         });
 
-        \usort($userGroups, static function (UserGroup $a, UserGroup $b) {
-            return \mb_strtolower($a->getName()) <=> \mb_strtolower($b->getName());
-        });
+        $collator = new \Collator(WCF::getLanguage()->getLocale());
+        \usort(
+            $userGroups,
+            static fn (UserGroup $a, UserGroup $b) => $collator->compare($a->getName(), $b->getName())
+        );
 
         return $userGroups;
     }
index d964c3ca503ef5e0e3d9bd63636ba94e9292fafe..0b5e6ab1f4148733427dae8fe3a4693c4222bb98 100644 (file)
@@ -584,9 +584,11 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
                 }
             }
 
-            \usort($list, static function (array $item1, array $item2) {
-                return \strcasecmp($item1['label'], $item2['label']);
-            });
+            $collator = new \Collator(WCF::getLanguage()->getLocale());
+            \usort(
+                $list,
+                static fn (array $item1, array $item2) => $collator->compare($item1['label'], $item2['label'])
+            );
         }
 
         // find users
index 8e2cccd914d3461bb53bb57a0613b52e6dbbe360..242e2b885e33dfd50eee9be884b22b39e84a7ce0 100644 (file)
@@ -639,8 +639,10 @@ class UserGroup extends DatabaseObject implements ITitledObject
      */
     public static function sortGroups(array &$userGroups)
     {
-        \uasort($userGroups, static function (self $groupA, self $groupB) {
-            return \strcasecmp($groupA->getName(), $groupB->getName());
-        });
+        $collator = new \Collator(WCF::getLanguage()->getLocale());
+        \uasort(
+            $userGroups,
+            static fn (self $groupA, self $groupB) => $collator->compare($groupA->getName(), $groupB->getName())
+        );
     }
 }
index f244f59d6ad39e5d1907259fe12c6559dc6b59f6..801ba0f125fff647abc31d4f054cc6492771b166 100644 (file)
@@ -207,9 +207,11 @@ HTML;
             $trophyList->readObjects();
             $this->trophies = $trophyList->getObjects();
 
-            \uasort($this->trophies, static function (Trophy $a, Trophy $b) {
-                return \strcmp($a->getTitle(), $b->getTitle());
-            });
+            $collator = new \Collator(WCF::getLanguage()->getLocale());
+            \uasort(
+                $this->trophies,
+                static fn (Trophy $a, Trophy $b) => $collator->compare($a->getTitle(), $b->getTitle())
+            );
         }
 
         return $this->trophies;
index afb9c73cd0c3f18d6804ddd27d5c7cd885857c37..cdfeb98f90e7f252cbf17e9a6acc815a6fd64c3f 100644 (file)
@@ -85,9 +85,11 @@ class ACPSearchResultList implements \Countable, \Iterator
      */
     public function sort(): void
     {
-        \usort($this->results, static function (ACPSearchResult $a, ACPSearchResult $b) {
-            return \strcmp($a->getTitle(), $b->getTitle());
-        });
+        $collator = new \Collator(WCF::getLanguage()->getLocale());
+        \usort(
+            $this->results,
+            static fn (ACPSearchResult $a, ACPSearchResult $b) => $collator->compare($a->getTitle(), $b->getTitle())
+        );
     }
 
     /**