From d3343ddb3fe7f6038d1b9b7950f6d9681b72c51e Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 8 Jan 2022 11:08:53 +0100 Subject: [PATCH 1/2] Sort locales according to their names --- modules/translation/translation.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/translation/translation.go b/modules/translation/translation.go index af1e5d25df53..9db731fecbe8 100644 --- a/modules/translation/translation.go +++ b/modules/translation/translation.go @@ -5,6 +5,8 @@ package translation import ( + "sort" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/options" "code.gitea.io/gitea/modules/setting" @@ -72,6 +74,11 @@ func InitLocales() { for i, v := range langs { allLangs = append(allLangs, LangType{v, names[i]}) } + + // Sort languages according to their name - needed for the user settings + sort.Slice(allLangs, func(i, j int) bool { + return allLangs[i].Name < allLangs[j].Name + }) } // Match matches accept languages From 905fdb7967dade08a040b68e4a4e88ee1ed099a1 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 8 Jan 2022 12:03:54 +0100 Subject: [PATCH 2/2] Fix documentation and sort case insensitive --- modules/translation/translation.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/translation/translation.go b/modules/translation/translation.go index 9db731fecbe8..2dce6e16b952 100644 --- a/modules/translation/translation.go +++ b/modules/translation/translation.go @@ -6,6 +6,7 @@ package translation import ( "sort" + "strings" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/options" @@ -33,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 } @@ -75,9 +76,9 @@ func InitLocales() { allLangs = append(allLangs, LangType{v, names[i]}) } - // Sort languages according to their name - needed for the user settings + // Sort languages case insensitive according to their name - needed for the user settings sort.Slice(allLangs, func(i, j int) bool { - return allLangs[i].Name < allLangs[j].Name + return strings.ToLower(allLangs[i].Name) < strings.ToLower(allLangs[j].Name) }) }