Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI language setting problems #15612

Closed
2 of 6 tasks
X-Lucifer opened this issue Apr 25, 2021 · 5 comments · Fixed by #17734
Closed
2 of 6 tasks

UI language setting problems #15612

X-Lucifer opened this issue Apr 25, 2021 · 5 comments · Fixed by #17734
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented topic/ui Change the appearance of the Gitea UI
Milestone

Comments

@X-Lucifer
Copy link

  • Gitea version (or commit ref): 1.14.1
  • Git version: 2.31.1
  • Operating system: Windows 10
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
  • Log gist:

Description

I used the Microsoft Edge browser and set the UI language to English, but after logging in again, it changed to Chinese by default.

Screenshots

屏幕截图 2021-04-25 111115

@lunny lunny added the topic/ui Change the appearance of the Gitea UI label Jun 5, 2021
@r10r
Copy link

r10r commented Nov 17, 2021

Hi there,

I can confirm this issue in the following clients in Gitea Version: 1.15.6

  • Safari on macOS 11.6
  • Edge on Windows 10

Steps to Reproduce

  1. Set a language different from the browser language in Settings->Profile->Language and save the changes. The UI language is changed.
  2. Logout from gitea
  3. Login to gitea
  4. The UI uses browser language which is different from the Settings->Profile->Language.

@wxiaoguang
Copy link
Contributor

Oh yes, I also meet the similar problem. The UI language sometimes differs from the language setting.

@wxiaoguang wxiaoguang added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Nov 17, 2021
@zeripath
Copy link
Contributor

I think this:

diff --git a/modules/context/api.go b/modules/context/api.go
index c978835af..e25318940 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -245,6 +245,9 @@ func APIAuth(authMethod auth.Method) func(*APIContext) {
 		// Get user from session if logged in.
 		ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
 		if ctx.User != nil {
+			if ctx.Locale.Language() != ctx.User.Language {
+				ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
+			}
 			ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
 			ctx.IsSigned = true
 			ctx.Data["IsSigned"] = ctx.IsSigned
diff --git a/modules/context/context.go b/modules/context/context.go
index 8adf1f306..a405f93d1 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -614,6 +614,9 @@ func Auth(authMethod auth.Method) func(*Context) {
 	return func(ctx *Context) {
 		ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
 		if ctx.User != nil {
+			if ctx.Locale.Language() != ctx.User.Language {
+				ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
+			}
 			ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
 			ctx.IsSigned = true
 			ctx.Data["IsSigned"] = ctx.IsSigned
diff --git a/routers/web/user/auth.go b/routers/web/user/auth.go
index ba37c8e3e..1b1c70c8f 100644
--- a/routers/web/user/auth.go
+++ b/routers/web/user/auth.go
@@ -572,6 +572,10 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
 
 	middleware.SetLocaleCookie(ctx.Resp, u.Language, 0)
 
+	if ctx.Locale.Language() != u.Language {
+		ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
+	}
+
 	// Clear whatever CSRF has right now, force to generate a new one
 	middleware.DeleteCSRFCookie(ctx.Resp)
 

would solve the issue.

It would be useful if you could test this patch.

@r10r
Copy link

r10r commented Nov 17, 2021

I'll try to test it on top of 1.15.6

r10r added a commit to drachenfels-de/gitea that referenced this issue Nov 18, 2021
@r10r
Copy link

r10r commented Nov 19, 2021

Works! Thanks @zeripath!

Tested with

  • Safari on macOS 11.6
  • Firefox on Windows 10

Will this be added to the 1.15.7 ?

zeripath added a commit to zeripath/gitea that referenced this issue Nov 20, 2021
When logging in reset the user's locale to ensure that it matches their
preferred locale.

Fix go-gitea#15612

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath added this to the 1.15.7 milestone Nov 20, 2021
zeripath added a commit that referenced this issue Nov 20, 2021
When logging in reset the user's locale to ensure that it matches their
preferred locale.

Fix #15612

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit to zeripath/gitea that referenced this issue Dec 25, 2021
Backport go-gitea#17734

When logging in reset the user's locale to ensure that it matches their
preferred locale.

Fix go-gitea#15612

Signed-off-by: Andrew Thornton <art27@cantab.net>
lunny pushed a commit that referenced this issue Dec 25, 2021
Backport #17734

When logging in reset the user's locale to ensure that it matches their
preferred locale.

Fix #15612

Signed-off-by: Andrew Thornton <art27@cantab.net>
Chianina pushed a commit to Chianina/gitea that referenced this issue Mar 28, 2022
When logging in reset the user's locale to ensure that it matches their
preferred locale.

Fix go-gitea#15612

Signed-off-by: Andrew Thornton <art27@cantab.net>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented topic/ui Change the appearance of the Gitea UI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants