Profile language lost when browser is closed #8262

Closed
opened 2025-11-02 08:00:01 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @fmunch on GitHub (Dec 18, 2021).

Gitea Version

1.15.7

Git Version

2.30.2

Operating System

Debian 11.2

How are you running Gitea?

Using https://dl.gitea.io/gitea/1.15.7/gitea-1.15.7-linux-amd64 running from systemd.

Database

MySQL

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Description

Hello!

I am using Chrome 96 which is sending accept-language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7.

  1. I go to https://mygitea/
  2. Gitea is in French.
  3. Navigate to Configuration > Profile, set Language = English, save.
  4. Gitea is now in English when I navigate in it.
  5. Close and reopen browser.
  6. Gitea is in French once again.
  7. If I go back to Configuration > Profile, Language is still English but the page is in French. I just have to click Update Profile to have Gitea in English without touching anything else.

I created an account on try.gitea.io, same thing happens.

The screenshots show the configuration page from my Gitea and try.gitea.io displayed in French but with the language setting showing English.

Screenshots

https://imgur.com/a/EP0mAO2

Originally created by @fmunch on GitHub (Dec 18, 2021). ### Gitea Version 1.15.7 ### Git Version 2.30.2 ### Operating System Debian 11.2 ### How are you running Gitea? Using https://dl.gitea.io/gitea/1.15.7/gitea-1.15.7-linux-amd64 running from systemd. ### Database MySQL ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Description Hello! I am using Chrome 96 which is sending `accept-language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7`. 1. I go to https://mygitea/ 2. Gitea is in French. 3. Navigate to Configuration > Profile, set Language = English, save. 4. Gitea is now in English when I navigate in it. 5. Close and reopen browser. 6. Gitea is in French once again. 7. If I go back to Configuration > Profile, Language is still English but the page is in French. I just have to click Update Profile to have Gitea in English without touching anything else. I created an account on try.gitea.io, same thing happens. The screenshots show the configuration page from my Gitea and try.gitea.io displayed in French but with the language setting showing English. ### Screenshots https://imgur.com/a/EP0mAO2
Author
Owner

@wxiaoguang commented on GitHub (Dec 18, 2021):

+1, I can reproduce this problem with a very recent dev version (1.16), eg: cc129d2ca2

@wxiaoguang commented on GitHub (Dec 18, 2021): +1, I can reproduce this problem with a very recent dev version (1.16), eg: cc129d2ca22100fe9c28106d9bc302678651f339
Author
Owner

@zeripath commented on GitHub (Dec 18, 2021):

Ah it looks like there are a couple of other places that the below magic needs to be copied in:

   // Language setting of the user overwrites the one previously set
   // If the user does not have a locale set, we save the current one.
   if len(u.Language) == 0 {
   	u.Language = ctx.Locale.Language()
   	if err := user_model.UpdateUserCols(db.DefaultContext, u, "language"); err != nil {
   		log.Error(fmt.Sprintf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language))
   		return setting.AppSubURL + "/"
   	}
   }

   middleware.SetLocaleCookie(ctx.Resp, u.Language, 0)

   if ctx.Locale.Language() != u.Language {
   	ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
   }
@zeripath commented on GitHub (Dec 18, 2021): Ah it looks like there are a couple of other places that the below magic needs to be copied in: ```go // Language setting of the user overwrites the one previously set // If the user does not have a locale set, we save the current one. if len(u.Language) == 0 { u.Language = ctx.Locale.Language() if err := user_model.UpdateUserCols(db.DefaultContext, u, "language"); err != nil { log.Error(fmt.Sprintf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language)) return setting.AppSubURL + "/" } } middleware.SetLocaleCookie(ctx.Resp, u.Language, 0) if ctx.Locale.Language() != u.Language { ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req) } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#8262