Skip to content

Commit 4f77645

Browse files
authored
Sort locales according to their names (#18211)
* Sort locales according to their names * Fix documentation and sort case insensitive
1 parent 832f987 commit 4f77645

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

modules/translation/translation.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
package translation
66

77
import (
8+
"sort"
9+
"strings"
10+
811
"code.gitea.io/gitea/modules/log"
912
"code.gitea.io/gitea/modules/options"
1013
"code.gitea.io/gitea/modules/setting"
@@ -31,7 +34,7 @@ var (
3134
supportedTags []language.Tag
3235
)
3336

34-
// AllLangs returns all supported langauages
37+
// AllLangs returns all supported languages sorted by name
3538
func AllLangs() []LangType {
3639
return allLangs
3740
}
@@ -72,6 +75,11 @@ func InitLocales() {
7275
for i, v := range langs {
7376
allLangs = append(allLangs, LangType{v, names[i]})
7477
}
78+
79+
// Sort languages case insensitive according to their name - needed for the user settings
80+
sort.Slice(allLangs, func(i, j int) bool {
81+
return strings.ToLower(allLangs[i].Name) < strings.ToLower(allLangs[j].Name)
82+
})
7583
}
7684

7785
// Match matches accept languages

0 commit comments

Comments
 (0)