Set language for SSO users

Hi,

I have been trying to automatically set language for my SSO users using the Accept-Language headers. As far as I can see this should be supported by Discourse.

I enable the two options below:

image

Then with Chrome, I use an extension to set the Accept-Language:
image

Unfortunately, my UI stays in English. I tried different formats for accept-language (fr, Accept-Language: fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5…) with no luck…

Any idea?

Thx,
Seb

1 Like

The set locale from header setting will not work with SSO. It only sets the locale for anonymous (not logged in) users. When SSO isn’t enabled, it will also set the locale for a user when they first register based on their language header. When SSO is enabled, users are created through a different process and the accept language header has no affect on their locale.

3 Likes

Thx for your answer. Is there any work around?

For instance, would it possible to use a parameter (locale) to automatically set the language?

The only workaround I can think of would be to create a plugin that added locale to the Discourse SSO parameters.

1 Like

I have the exact same issue. My user interface is define at first by the browser language of my user, but once connected it fallback to the default discourse language. I just look at the code, and I’m now sure we can solve this with a plugin. Maybe we could implement this in the core. Seems some line of code into

https://github.com/discourse/discourse/blob/fe37ce165dff0bf269c0492ece8c5ecb3b1cc903/app/models/discourse_single_sign_on.rb#L204

would do the trick. Can you be interested in a PR for this? The PR would be “Allow to set user locale through SSO”

2 Likes

Hi @jeanmonod and team,
Even I am also looking for the same request. From the SSO I want to pass the User preferred language. I am trying to achieve it with plugin but no luck for me. If you know any plugin to take care of this SSO language part please let me know.

When I was looking for a way to set the locale via SSO, and I came across this plugin: https://github.com/liip/discourse-multilingual-support

It works, but I would prefer a solution that doesn’t require a plugin.

You can now set a user’s locale with SSO without a plugin. There are two parameters you can add to the SSO payload for this: locale and locale_force_update. The locale parameter needs to be set to a value that Discourse will accept. Here’s the list of locales that Discourse will accept:

ar, bg, bs_BA, ca, cs, da, de, el, en, es, et, fa_IR, fi, fr, gl, he, hu, id, it, ja, ko, lt, lv, nb_NO, nl, pl_PL, pt, pt_BR, ro, ru, sk, sl, sq, sr, sv, sw, te, th, tr_TR, uk, ur, vi, zh_CN, zh_TW

The locale_force_update parameter is used if you wish to update the locale of an existing user via SSO.

3 Likes

Indeed I can, thanks for the heads-up! The feature seems to have been added in Discourse 2.1.

In that case I am not actually sure if the above-mentioned plugin works because the SSO parameter was already named ‘locale’. I disabled the plugin and it just continued to work.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.