# Variable default interface language for new users

**URL:** https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741
**Category:** Feature
**Created:** [September 25, 2015, 11:38am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741 "2015-09-25T11:38:40Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [November 17, 2015, 4:50pm UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/21 "2015-11-17T16:50:45Z")

</div>

Weird, are you setting your language with something like this?

 ![](https://global.discourse-cdn.com/meta/original/3X/8/c/8c674c1419e60891f5c57d553b429af6a0e31cf8.png)

I have found sometimes the ordering on the Chrome language selector doesn’t stick where it should.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [November 17, 2015, 10:11pm UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/22 "2015-11-17T22:11:03Z")

</div>

If it’s still not working could you check what the `Accept-Language` parameters are? In chrome, right-click on the page, select `Inspect Element`. On the window that pops up select `Network` and then click on one of the `poll` requests from the left-hand menu. It should look something like this:

 ![](https://global.discourse-cdn.com/meta/original/3X/0/6/06a7989a0aa74a202e6f796e2b46aaf86f61310d.png)

---

<div class="post-metadata">

### Author: ![Conor\_O\_Rourke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/conor_o_rourke/32/116698_2.png) [@Conor\_O\_Rourke](https://meta.discourse.org/u/Conor_O_Rourke)
#### Post date: [November 24, 2015, 10:25am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/23 "2015-11-24T10:25:47Z")

</div>

OK, I see the problem, which is that the browser had preserved some of its language settings, but not all of them. Any way to have this detect system/OS language?

edit: thanks for all the troubleshooting help BTW, it’s really incredible

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [November 25, 2015, 3:35am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/24 "2015-11-25T03:35:20Z")

</div>

> [@Conor\_O\_Rourke](#):
>
> Any way to have this detect system/OS language?

I don’t think so.

If you’re using this in production, make sure to update to the latest version. In the previous version it was throwing an error if the accept-language header wasn’t set.

[https://github.com/scossar/accept-language](https://github.com/scossar/accept-language)

---

<div class="post-metadata">

### Author: ![rriemann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rriemann/32/115238_2.png) [@rriemann](https://meta.discourse.org/u/rriemann)
#### Post date: [January 31, 2016, 3:55pm UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/25 "2016-01-31T15:55:50Z")

</div>

Nice to have such a plugin. Would you mind to post the link once again to the category section or move this topic to the plugin category? 🙂

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [January 31, 2016, 9:46pm UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/26 "2016-01-31T21:46:24Z")

</div>

There’s some talk about adding something like this to the Discourse core. Most of the major sites I look at (facebook, twitter, google etc.) are doing something similar. One difference is that they seem to be overriding the http headers if a user’s locale has been set in a cookie.

If nothing is happening with this I will post it to the plugins category.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [January 31, 2016, 10:01pm UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/27 "2016-01-31T22:01:02Z")

</div>

It would be great if this could be included in core. 👍

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 1, 2016, 3:21am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/28 "2016-02-01T03:21:08Z")

</div>

@erlend_sh can you confirm with @simon the plan here? Would love to fund this work with the Mozilla grant.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 4, 2016, 3:10am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/29 "2016-03-04T03:10:54Z")

</div>

Ok I pinged @zogstrip to look at the two outstanding PRs here if they are ready @simon.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [March 4, 2016, 8:13am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/30 "2016-03-04T08:13:39Z")

</div>

Just merged both PRs. Thanks @simon 👍

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 4, 2016, 12:19pm UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/31 "2016-03-04T12:19:33Z")

</div>

I just refined this a bit:

[https://github.com/discourse/discourse/commit/759803708077dc061ec4449395abb3505486e4fd](https://github.com/discourse/discourse/commit/759803708077dc061ec4449395abb3505486e4fd)

This gem was injecting extra middleware and adding stuff on our application controller. I changed it so it has no impact for users not using the feature.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [September 26, 2017, 2:58am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/32 "2017-09-26T02:58:53Z")

</div>

Seems that not all of @simon’s code gets merged into core.

For example, the current:

> <https://github.com/discourse/discourse/blob/main/app/controllers/application_controller.rb#L212-L223>

where `effective_locale` is:

> <https://github.com/discourse/discourse/blob/main/app/models/user.rb#L207-L213>

is missing certain features from @simon’s original plugin code:

> <https://github.com/scossar/accept-language/blob/master/plugin.rb#L27-L49>

In particular, this part:

```plaintext
elsif SiteSetting.accept_language_overrides_default_locale
I18n.locale = locale_from_http_header

```

So, in other words, a logged in user does not get this auto-language-detection benefit.

@simon’s plugin has not been updated for 2 years and I’m not sure how well it works with the current Discourse version… otherwise it would be perfect.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [September 26, 2017, 3:25am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/33 "2017-09-26T03:25:10Z")

</div>

> [@schungx](#):
>
> So, in other words, a logged in user does not get this auto-language-detection benefit.

That’s intentional. If ‘allow user locale’ is also enabled, the user’s locale will be set when they register, so it will be set from the accept language header.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [September 26, 2017, 3:27am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/34 "2017-09-26T03:27:14Z")

</div>

Are you sure? Because I’ve seen _ALL_ my users’ interface language being `default`. Only a few of them knew to change it in profile.

And they all came from invites, not public registration. I’m pretty sure it only asked for:

1. username
2. nickname
3. password

when they first sign on.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [September 26, 2017, 3:36am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/35 "2017-09-26T03:36:46Z")

</div>

> [@schungx](#):
>
> Are you sure?

Yes, it should work that way when both ‘allow user locale’ and ‘set locale from accept language header’ are enabled. I just tested it with my browser’s preferred language set to french, and it created a user with their preferred locale set to french.

> [@schungx](#):
>
> And they all came from invites, not public registration.

That will be the problem.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [September 26, 2017, 3:44am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/36 "2017-09-26T03:44:32Z")

</div>

> [@simon](#):
>
> That will be the problem.

Yes, the invite sign-on form seems to be different from the public sign-up…

This is the invite sign-on when creating a user:

> <https://github.com/discourse/discourse/blob/cf9607a0cb5753bdae1c756752021aeb2df3f264/app/controllers/invites_controller.rb#L39-L39>

Language is not specified.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [September 26, 2017, 3:50am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/37 "2017-09-26T03:50:22Z")

</div>

The locale isn’t on the signup form. I haven’t looked at the code for a while, but from what I remember, it’s set from the `locale`. This means that if the locale has been set from the header, that locale will be set for the user.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [September 26, 2017, 3:52am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/38 "2017-09-26T03:52:22Z")

</div>

> [@simon](#):
>
> from what I remember, it’s set from the effective\_locale.

Yes, but `effective_locale` has nothing to do with the `accept-language` header. Evident from this code:

> <https://github.com/discourse/discourse/blob/main/app/models/user.rb#L207-L213>

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [September 26, 2017, 3:58am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/39 "2017-09-26T03:58:32Z")

</div>

> [@schungx](#):
>
> Yes, but effective\_locale has nothing to do with the accept-language header.

Sorry, I edited my post. It’s set from the locale, which is set from the header.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [September 26, 2017, 4:00am UTC](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741/40 "2017-09-26T04:00:25Z")

</div>

Nope. I don’t think so. At least not for `invite.redeem`.

Check this:

> <https://github.com/discourse/discourse/blob/5012d46cbd3bcf79b7351f7d2d41003496a796c5/app/models/invite_redeemer.rb#L29-L29>

Maybe for new user sign-up.

[Previous page](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741.md?page=1)

[Next page](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741.md?page=3)
