Add option to disable language autodetect #3830

Closed
opened 2025-11-02 05:27:15 -06:00 by GiteaMirror · 19 comments
Owner

Originally created by @markg85 on GitHub (Aug 23, 2019).

Hi,

While language autodetect often seems like a nice feature to have (and i'd agree if i never had issues with it), it has it's downsides too.

For instance, i've had the issue for years of being detected as German (i'm dutch, was in the netherlands and was not using a proxy). Even google was at one point in German for me...

So... the feature can be damn pesky if it doesn't work as you'd expect it to work.

i know of the trick to just remove all but english from LANGS and NAMES in the i18n section, but that's not what i want. As that removes them entirely. I want to be able to choose, just disabling autoconnect and using English by default.

Cheers,
Mark

Originally created by @markg85 on GitHub (Aug 23, 2019). Hi, While language autodetect often seems like a nice feature to have (and i'd agree if i never had issues with it), it has it's downsides too. For instance, i've had the issue for years of being detected as German (i'm dutch, was in the netherlands and was not using a proxy). Even google was at one point in German for me... So... the feature can be damn pesky if it doesn't work as you'd expect it to work. i know of the trick to just remove all but english from `LANGS` and `NAMES` in the `i18n` section, but that's **not** what i want. As that removes them entirely. I want to be able to choose, just disabling autoconnect and using English by default. Cheers, Mark
GiteaMirror added the type/enhancementissue/stale labels 2025-11-02 05:27:15 -06:00
Author
Owner

@lunny commented on GitHub (Aug 26, 2019):

@markg85 If you have login, you could chose your favorite language that will not obey browser's chose.

@lunny commented on GitHub (Aug 26, 2019): @markg85 If you have login, you could chose your favorite language that will not obey browser's chose.
Author
Owner

@markg85 commented on GitHub (Aug 26, 2019):

@markg85 If you have login, you could chose your favorite language that will not obey browser's chose.

I know, but that's not the request i'm doing here :)

@markg85 commented on GitHub (Aug 26, 2019): > @markg85 If you have login, you could chose your favorite language that will not obey browser's chose. I know, but that's not the request i'm doing here :)
Author
Owner

@lafriks commented on GitHub (Aug 26, 2019):

What your browser preferred language string looks like?

@lafriks commented on GitHub (Aug 26, 2019): What your browser preferred language string looks like?
Author
Owner

@markg85 commented on GitHub (Aug 26, 2019):

I suppose you mean the output of "navigator.language" which is in fact "nl". I don't know how it determines that as my system language is English. i do use NL for some settings. Like having a 24 hour clock. So to be very detailed:

LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_NUMERIC=en_NL.UTF-8
LC_TIME=en_NL.UTF-8
LC_COLLATE=en_NL.UTF-8
LC_MONETARY=en_NL.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT=en_NL.UTF-8
LC_IDENTIFICATION="en_US.UTF-8"

But again, i fail to see the point of even telling this. The feature i'm requesting is to have language detection disabled and overruled by the site administrator. Not to debug my browser..

@markg85 commented on GitHub (Aug 26, 2019): I suppose you mean the output of "navigator.language" which is in fact "nl". I don't know how it determines that as my system language is English. i do use NL for some settings. Like having a 24 hour clock. So to be very detailed: > LANG=en_US.UTF-8 > LC_CTYPE=en_US.UTF-8 > **LC_NUMERIC=en_NL.UTF-8** > **LC_TIME=en_NL.UTF-8** > **LC_COLLATE=en_NL.UTF-8** > **LC_MONETARY=en_NL.UTF-8** > LC_MESSAGES="en_US.UTF-8" > LC_PAPER="en_US.UTF-8" > LC_NAME="en_US.UTF-8" > LC_ADDRESS="en_US.UTF-8" > LC_TELEPHONE="en_US.UTF-8" > **LC_MEASUREMENT=en_NL.UTF-8** > LC_IDENTIFICATION="en_US.UTF-8" But again, i fail to see the point of even telling this. The feature i'm requesting is to have language detection **disabled** and overruled by the site administrator. Not to debug my browser..
Author
Owner

@lafriks commented on GitHub (Aug 26, 2019):

You can set preferred languages in browser and Gitea will use it choose default language if you have not set other in user settings

@lafriks commented on GitHub (Aug 26, 2019): You can set preferred languages in browser and Gitea will use it choose default language if you have not set other in user settings
Author
Owner

@markg85 commented on GitHub (Aug 26, 2019):

You can set preferred languages in browser and Gitea will use it choose default language if you have not set other in user settings

Please stop.
Sure, that works but is a workaround and not the feature i'm asking for.
I'd be happy to explain the feature i'm asking for in more detail if it isn't clear (i think it is).

On the other hand, if you can point me to the code that does handle this in Go and the requirements to make the requested feature acceptable then i'd like to give Go a shot and try to implement this.

@markg85 commented on GitHub (Aug 26, 2019): > You can set preferred languages in browser and Gitea will use it choose default language if you have not set other in user settings Please stop. Sure, that works but is a **workaround** and **not** the feature i'm asking for. I'd be happy to explain the feature i'm asking for in more detail if it isn't clear (i think it is). On the other hand, if you can point me to the code that does handle this in Go and the requirements to make the requested feature acceptable then i'd like to give Go a shot and try to implement this.
Author
Owner

@guillep2k commented on GitHub (Aug 26, 2019):

I hope you don't mind if I give you this information; if it's not useful to you, please ignore it. I'm also annoyed by auto-detect in many web sites, but I have no problems with Gitea.

In my server, in /etc/gitea/app.ini, I have the following:

[i18n]
LANGS = en-US,es-ES
NAMES = English, Español

This prevents Gitea from choosing any language other than English and Spanish, which are the languages spoken in my company.

Then, as I prefer English, while I'm logged in I click here:
image

image

image

image

I'm not aware of Gitea doing any kind of auto-detection based on browser/client data (e.g. ip address database). I've sought all around the source code and I've only found the code I'd expect (e.g. related to user settings).

You can disable all offending languages by setting the /etc/gitea/app.ini LANG/NAMES values to the short list you want.

Cheers!

@guillep2k commented on GitHub (Aug 26, 2019): I hope you don't mind if I give you this information; if it's not useful to you, please ignore it. I'm also annoyed by auto-detect in many web sites, but I have no problems with Gitea. In my server, in `/etc/gitea/app.ini`, I have the following: ``` [i18n] LANGS = en-US,es-ES NAMES = English, Español ``` This prevents Gitea from choosing any language other than English and Spanish, which are the languages spoken in my company. Then, as I prefer English, while I'm logged in I click here: ![image](https://user-images.githubusercontent.com/18600385/63725259-3bdf8300-c830-11e9-9969-3b418f6a40fb.png) ![image](https://user-images.githubusercontent.com/18600385/63725360-8103b500-c830-11e9-8bcf-345f86297c7a.png) ![image](https://user-images.githubusercontent.com/18600385/63725399-9973cf80-c830-11e9-868f-7c80cbfc467c.png) ![image](https://user-images.githubusercontent.com/18600385/63725420-a7c1eb80-c830-11e9-8bd7-5fb4025b838b.png) I'm not aware of Gitea doing any kind of auto-detection based on browser/client data (e.g. ip address database). I've sought all around the source code and I've only found the code I'd expect (e.g. related to user settings). You can disable all offending languages by setting the `/etc/gitea/app.ini` LANG/NAMES values to the short list you want. Cheers!
Author
Owner

@stale[bot] commented on GitHub (Oct 25, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Oct 25, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@markg85 commented on GitHub (Oct 26, 2019):

Nope, not stale. The issue as described is still there. Some might consider it a feature, i consider it a bug.

@guillep2k thank you for your comment, but that is exactly what i described only in text. You added nice pictures to it ;) Anyhow, that's not what i'm looking for.

@markg85 commented on GitHub (Oct 26, 2019): Nope, not stale. The issue as described is still there. Some might consider it a feature, i consider it a bug. @guillep2k thank you for your comment, but that is **exactly** what i described only in text. You added nice pictures to it ;) Anyhow, that's not what i'm looking for.
Author
Owner

@guillep2k commented on GitHub (Oct 26, 2019):

@markg85 I keep reading your description and it's still unclear to me what do you actually want. I think that Gitea doesn't autodetect language for the logged in user, so I'm trying to understand your exact problem. Yes, I've read the title, but your message only describes your frustration with software in general. 🤔

There's some context here that I'm missing. For instance, you might be referring to one of the following (there are more):

  • The home page, before login
  • Your site in general, after login, when navigate
  • Messages from git when you interact with a repository hosted by a Gitea instance.
  • Error messages that might be still untranslated (I understand you want only English, so this will not be the case).

Can you post a picture of the part that's bothering you?

@guillep2k commented on GitHub (Oct 26, 2019): @markg85 I keep reading your description and it's still unclear to me what do you actually want. I think that Gitea doesn't autodetect language for the logged in user, so I'm trying to understand your exact problem. Yes, I've read the title, but your message only describes your frustration with software in general. 🤔 There's some context here that I'm missing. For instance, you might be referring to one of the following (there are more): * The home page, before login * Your site in general, after login, when navigate * Messages from `git` when you interact with a repository hosted by a Gitea instance. * Error messages that might be still untranslated (I understand you want only English, so this will not be the case). Can you post a picture of the part that's bothering you?
Author
Owner

@markg85 commented on GitHub (Oct 26, 2019):

@guillep2k oke.

Follow my words exactly!
I installed gitea and am not logged in. Then i visit my gitea instance.
again, all not logged in!!!!
Now the site shows in Dutch for me. something somehow somewhere in the Gitea codebase uses some heuristic to detect my language and display the site in that language. i want to disable that feature and force it to always be english. Everything else should remain as-is.

So why do i want that? Why do i hate this "feature"?
Well, in Dutch technical sites like github, gitea, codelab, etc.. look soooo freaking weird. With "attempted translations" of technical terms that are just better explained in English.

I get that some people consider this a "feature". I just hate it.
Again, i need to stress this over and over and over again. I'm not logged on. Yes, there is a language dropdown, even when i'm not logged on, but that is not the point. The point is that an attempt is made to show a localized site. I want to disable that attempt.

@markg85 commented on GitHub (Oct 26, 2019): @guillep2k oke. Follow my words **exactly**! I installed gitea and am **not logged in**. Then i visit my gitea instance. **again, all not logged in!!!!** Now the site shows in Dutch for me. **something somehow somewhere** in the Gitea codebase uses some heuristic to detect my language and display the site in that language. i want to **disable that feature** and force it to always be english. Everything else should remain as-is. So why do i want that? Why do i hate this "feature"? Well, in Dutch technical sites like github, gitea, codelab, etc.. look soooo freaking weird. With "attempted translations" of technical terms that are just better explained in English. I get that some people consider this a "feature". I just hate it. Again, i need to stress this over and over and over again. I'm **not logged on**. Yes, there is a language dropdown, even when i'm not logged on, but that is **not the point**. The point is that an attempt is made to show a localized site. I want to disable that attempt.
Author
Owner

@guillep2k commented on GitHub (Oct 26, 2019):

OK, it's clear now. Thank you. 😉

@guillep2k commented on GitHub (Oct 26, 2019): OK, it's clear now. Thank you. 😉
Author
Owner

@lunny commented on GitHub (Oct 27, 2019):

@markg85 You can remove all other languages from your app.ini. So that this site will only support one language.

@lunny commented on GitHub (Oct 27, 2019): @markg85 You can remove all other languages from your app.ini. So that this site will only support one language.
Author
Owner

@markg85 commented on GitHub (Oct 27, 2019):

@markg85 You can remove all other languages from your app.ini. So that this site will only support one language.

Now we're going in circles.
Quote from my first post in this thread:

i know of the trick to just remove all but english from LANGS and NAMES in the i18n section, but that's not what i want. As that removes them entirely. I want to be able to choose, just disabling autoconnect and using English by default.

I guess the technical term is that i want to disable i18n on the main site without removing the localized translations. I just want to force an overruling default.

@markg85 commented on GitHub (Oct 27, 2019): > @markg85 You can remove all other languages from your app.ini. So that this site will only support one language. Now we're going in circles. Quote from my first post in this thread: > i know of the trick to just remove all but english from LANGS and NAMES in the i18n section, but that's not what i want. As that removes them entirely. I want to be able to choose, just disabling autoconnect and using English by default. I guess the technical term is that i want to disable i18n on the main site **without** removing the localized translations. I just want to force an overruling default.
Author
Owner

@mrsdizzie commented on GitHub (Oct 27, 2019):

By default Macaron (Web framework Gitea uses) looks at the "Accept-Language" header sent by the browser if nothing is specified otherwise (so for a non-logged in user), and the code for that is here:

https://gitea.com/macaron/i18n/src/branch/master/i18n.go#L183

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language

And then Gitea uses that here:

70fa80df11/templates/base/head.tmpl (L2)

@lafriks point remains that Gitea isn't auto-detecting anything, it is just responding to the browsers specific request for language. The Browser is saying "Send this page in Dutch" (in this example). There isn't a heuristic or anything like that on the Gitea end that makes it guess a language, it just responds with what the browser specifically asks for in the request header. What you'd really be asking for is "Ignore language request my browser sends".

As requested, above are the links to the specific code where Gitea eventually uses the header the browser sends if you are interested in modifying it.

With the current code you can also force a different language by adding this to the URL query: lang=xxx

So to force US English for gitea.com regardless of what your browser sends it would be:

https://gitea.com/?lang=en-US

That should be enough to then set that language in the users Cookie for other pages, but I haven't tested that in very much detail at all.

Alternatively, a custom header template that would force the lang tag to something specific if a user isn't signed in

{{if .IsSigned}}<html lang="{{.Language}}">{{else}}<html lang="en-US">{{end}}
@mrsdizzie commented on GitHub (Oct 27, 2019): By default Macaron (Web framework Gitea uses) looks at the "Accept-Language" header sent by the browser if nothing is specified otherwise (so for a non-logged in user), and the code for that is here: https://gitea.com/macaron/i18n/src/branch/master/i18n.go#L183 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language And then Gitea uses that here: https://github.com/go-gitea/gitea/blob/70fa80df114c1b54f77f0f7ccede2cf19775c61f/templates/base/head.tmpl#L2 @lafriks point remains that Gitea isn't auto-detecting anything, it is just responding to the browsers specific request for language. The Browser is saying "Send this page in Dutch" (in this example). There isn't a heuristic or anything like that on the Gitea end that makes it guess a language, it just responds with what the browser specifically asks for in the request header. What you'd really be asking for is "Ignore language request my browser sends". As requested, above are the links to the specific code where Gitea eventually uses the header the browser sends if you are interested in modifying it. With the current code you can also force a different language by adding this to the URL query: ```lang=xxx``` So to force US English for gitea.com regardless of what your browser sends it would be: https://gitea.com/?lang=en-US That should be enough to then set that language in the users Cookie for other pages, but I haven't tested that in very much detail at all. Alternatively, a custom header template that would force the lang tag to something specific if a user isn't signed in ``` {{if .IsSigned}}<html lang="{{.Language}}">{{else}}<html lang="en-US">{{end}} ```
Author
Owner

@markg85 commented on GitHub (Oct 27, 2019):

Thank you @mrsdizzie !

I might play a bit with this to get it to my liking. But then again, the inconvenience is really minor. So it's not all that important.

Just curious, if i make a feature to set a default i18n override when the user hasn't picked anything, would that be acceptable as a feature for Gitea? Or as you phrased it: "Ignore language request my browser sends". If it is, i might try to make a patch for it. If it's not.. well... why would i bother ;)

@markg85 commented on GitHub (Oct 27, 2019): Thank you @mrsdizzie ! I might play a bit with this to get it to my liking. But then again, the inconvenience is really minor. So it's not all that important. Just curious, if i make a feature to set a default i18n override when the user hasn't picked anything, would that be acceptable as a feature for Gitea? Or as you phrased it: "Ignore language request my browser sends". If it is, i might try to make a patch for it. If it's not.. well... why would i bother ;)
Author
Owner

@mrsdizzie commented on GitHub (Oct 27, 2019):

Great glad that helps!

Personally I think the two separate workarounds above for this should be enough in this case where somebody wants to ignore what the browser has sent and it wouldn't be worth complicating the code further to add another option.

@mrsdizzie commented on GitHub (Oct 27, 2019): Great glad that helps! Personally I think the two separate workarounds above for this should be enough in this case where somebody wants to ignore what the browser has sent and it wouldn't be worth complicating the code further to add another option.
Author
Owner

@stale[bot] commented on GitHub (Dec 26, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Dec 26, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@stale[bot] commented on GitHub (Jan 9, 2020):

This issue has been automatically closed because of inactivity. You can re-open it if needed.

@stale[bot] commented on GitHub (Jan 9, 2020): This issue has been automatically closed because of inactivity. You can re-open it if needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#3830