Skip to content

Commit

Permalink
Merge pull request #5670 from WoltLab/intl-collator-sort
Browse files Browse the repository at this point in the history
Use intl Collator to sort strings
  • Loading branch information
BurntimeX authored Sep 29, 2023
2 parents 70e3d20 + 5f952b8 commit 70e7768
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 33 deletions.
11 changes: 6 additions & 5 deletions wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,14 @@ public function readParameters()
}

$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();
}
Expand Down
10 changes: 6 additions & 4 deletions wcfsetup/install/files/lib/acp/form/DataImportForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ public function readParameters()
$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'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ public function assignVariables()
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ public function assignVariables()
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ public function readData()
$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())
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use wcf\data\user\UserProfile;
use wcf\data\user\UserProfileList;
use wcf\http\Helper;
use wcf\system\WCF;

/**
* Suggests users that may be mentioned.
Expand Down Expand Up @@ -91,9 +92,11 @@ private function getGroups(string $query): array
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;
}
Expand Down
8 changes: 5 additions & 3 deletions wcfsetup/install/files/lib/data/user/UserAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,11 @@ public function getSearchResultList()
}
}

\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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,10 @@ public static function getOwnerGroupID()
*/
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())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,11 @@ protected function getTrophies()
$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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ public function reduceResultsTo(int $size): void
*/
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())
);
}

/**
Expand Down

0 comments on commit 70e7768

Please sign in to comment.