A free, self-hostable news aggregator…
Feeds tree: sort feed names with locale-aware collation (#8985)
Jam Balayaf201061345fd
diff --git a/app/Models/Category.php b/app/Models/Category.phpindex cae56008c..f7c765a66 100644--- a/app/Models/Category.php+++ b/app/Models/Category.php@@ -299,7 +299,7 @@ class FreshRSS_Category extends Minz_Model {if ($this->feeds === null) {return;}- uasort($this->feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b) => strnatcasecmp($a->name(), $b->name()));+ uasort($this->feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b): int => FreshRSS_Context::localeCompare($a->name(), $b->name()));}/**diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.phpindex d9b5e6efb..6f62e2641 100644--- a/app/Models/CategoryDAO.php+++ b/app/Models/CategoryDAO.php@@ -310,7 +310,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo {$aPosition = $a->attributeInt('position');$bPosition = $b->attributeInt('position');if ($aPosition === $bPosition) {- return strnatcasecmp($a->name(), $b->name());+ return FreshRSS_Context::localeCompare($a->name(), $b->name());} elseif (null === $aPosition) {return 1;} elseif (null === $bPosition) {diff --git a/app/Models/Context.php b/app/Models/Context.phpindex 10a399059..c78994bb6 100644--- a/app/Models/Context.php+++ b/app/Models/Context.php@@ -667,4 +667,29 @@ final class FreshRSS_Context {$timezone = ini_get('date.timezone');return $timezone != false ? $timezone : 'UTC';}++ /**+ * Sort locale-aware with Collator if available+ */+ public static function localeCompare(string $a, string $b): int {+ static $collator = null;++ if ($collator === null) {+ $language = FreshRSS_Context::hasUserConf() ? FreshRSS_Context::userConf()->language : '';+ if ($language === '' || !class_exists(\Collator::class)) {+ $collator = false;+ } else {+ $collator = \Collator::create($language) ?? false;+ }+ if ($collator instanceof \Collator) {+ $collator->setAttribute(\Collator::NUMERIC_COLLATION, \Collator::ON);+ }+ }++ if (!($collator instanceof \Collator)) {+ return strnatcasecmp($a, $b);+ }+ $result = $collator->compare($a, $b);+ return $result === false ? strnatcasecmp($a, $b) : $result;+ }}diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.phpindex 2e68b1f64..d8530fbc8 100644--- a/app/Models/FeedDAO.php+++ b/app/Models/FeedDAO.php@@ -537,7 +537,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {/** @var list<array{id:int,url:string,kind:int,category:int,name:string,website:string,description:string,lastUpdate:int,priority:int,* pathEntries:string,httpAuth:string,error:int,ttl:int,attributes?:string,cache_nbUnreads:int,cache_nbEntries:int}> $res */$feeds = self::daoToFeeds($res);- uasort($feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b) => strnatcasecmp($a->name(), $b->name()));+ uasort($feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b) => FreshRSS_Context::localeCompare($a->name(), $b->name()));return $feeds;}diff --git a/app/Models/Share.php b/app/Models/Share.phpindex d7ee3bde7..9f8bf6b30 100644--- a/app/Models/Share.php+++ b/app/Models/Share.php@@ -55,7 +55,7 @@ class FreshRSS_Share {self::register($share_options);}- uasort(self::$list_sharing, static fn(FreshRSS_Share $a, FreshRSS_Share $b) => strcasecmp($a->name() ?? '', $b->name() ?? ''));+ uasort(self::$list_sharing, static fn(FreshRSS_Share $a, FreshRSS_Share $b) => FreshRSS_Context::localeCompare($a->name() ?? '', $b->name() ?? ''));}/**