aboutsummaryrefslogtreecommitdiffstats
path: root/modules/web
diff options
context:
space:
mode:
authorNaohisa Murakami <tiqwab.ch90@gmail.com>2021-04-15 03:52:01 +0900
committerGitHub <noreply@github.com>2021-04-14 19:52:01 +0100
commit1426601cf7dd6e2cefca218a84d38905dc1cb295 (patch)
tree3adb7d635388cb8d10634b62870f80f5147591f3 /modules/web
parent078df7a39272fb4c20db2d72b39338f3d4920f1b (diff)
downloadgitea-1426601cf7dd6e2cefca218a84d38905dc1cb295.tar.gz
gitea-1426601cf7dd6e2cefca218a84d38905dc1cb295.zip
Use index of the supported tags to choose user lang (#15452)
Fix #14793. The previous implementation used the first return value of matcher.Match, which is the chosen language tag but may contain extensions such as de-DE-u-rg-chzzzz. As mentioned in the documentation of language package, matcher.Match also returns the index of the supported tags, so I think it is better to use it rather than manipulate the returned language tag.
Diffstat (limited to 'modules/web')
-rw-r--r--modules/web/middleware/locale.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/modules/web/middleware/locale.go b/modules/web/middleware/locale.go
index a08e5aaeec..ede38ef933 100644
--- a/modules/web/middleware/locale.go
+++ b/modules/web/middleware/locale.go
@@ -38,7 +38,7 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale {
// The first element in the list is chosen to be the default language automatically.
if len(lang) == 0 {
tags, _, _ := language.ParseAcceptLanguage(req.Header.Get("Accept-Language"))
- tag, _, _ := translation.Match(tags...)
+ tag := translation.Match(tags...)
lang = tag.String()
}