UI language setting problems #7244

Closed
opened 2025-11-02 07:20:41 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @X-Lucifer on GitHub (Apr 25, 2021).

  • 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

Originally created by @X-Lucifer on GitHub (Apr 25, 2021). <!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue --> <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Make sure it's not mentioned in the FAQ (https://docs.gitea.io/en-us/faq) 5. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.14.1 - Git version: 2.31.1 - Operating system: Windows 10 <!-- Please include information on whether you built gitea yourself, used one of our downloads or are using some other package --> <!-- Please also tell us how you are running gitea, e.g. if it is being run from docker, a command-line, systemd etc. ---> <!-- If you are using a package or systemd tell us what distribution you are using --> - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [x] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [x] No - Log gist: <!-- It really is important to provide pertinent logs --> <!-- Please read https://docs.gitea.io/en-us/logging-configuration/#debugging-problems --> <!-- In addition, if your problem relates to git commands set `RUN_MODE=dev` at the top of app.ini --> ## Description <!-- If using a proxy or a CDN (e.g. CloudFlare) in front of gitea, please disable the proxy/CDN fully and connect to gitea directly to confirm the issue still persists without those services. --> 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 <!-- **If this issue involves the Web Interface, please include a screenshot** --> ![屏幕截图 2021-04-25 111115](https://user-images.githubusercontent.com/11420730/115979173-fb14b000-a5b6-11eb-92a3-b08d5702cbf5.png)
GiteaMirror added the topic/uiissue/confirmed labels 2025-11-02 07:20:41 -06:00
Author
Owner

@r10r commented on GitHub (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.
@r10r commented on GitHub (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`.
Author
Owner

@wxiaoguang commented on GitHub (Nov 17, 2021):

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

@wxiaoguang commented on GitHub (Nov 17, 2021): Oh yes, I also meet the similar problem. The UI language sometimes differs from the language setting.
Author
Owner

@zeripath commented on GitHub (Nov 17, 2021):

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.

@zeripath commented on GitHub (Nov 17, 2021): I think this: ```patch 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.
Author
Owner

@r10r commented on GitHub (Nov 17, 2021):

I'll try to test it on top of 1.15.6

@r10r commented on GitHub (Nov 17, 2021): I'll try to test it on top of 1.15.6
Author
Owner

@r10r commented on GitHub (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 ?

@r10r commented on GitHub (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 ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#7244