Skip to content

Commit

Permalink
Sort locales according to their names (#18211)
Browse files Browse the repository at this point in the history
* Sort locales according to their names

* Fix documentation and sort case insensitive
  • Loading branch information
delvh committed Jan 8, 2022
1 parent 832f987 commit 4f77645
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/translation/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
package translation

import (
"sort"
"strings"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/options"
"code.gitea.io/gitea/modules/setting"
Expand All @@ -31,7 +34,7 @@ var (
supportedTags []language.Tag
)

// AllLangs returns all supported langauages
// AllLangs returns all supported languages sorted by name
func AllLangs() []LangType {
return allLangs
}
Expand Down Expand Up @@ -72,6 +75,11 @@ func InitLocales() {
for i, v := range langs {
allLangs = append(allLangs, LangType{v, names[i]})
}

// Sort languages case insensitive according to their name - needed for the user settings
sort.Slice(allLangs, func(i, j int) bool {
return strings.ToLower(allLangs[i].Name) < strings.ToLower(allLangs[j].Name)
})
}

// Match matches accept languages
Expand Down

0 comments on commit 4f77645

Please sign in to comment.