Variable default interface language for new users

(Conor O'rourke) #1

Hey guys,

New Discourse user here, but super impressed and excited about what a great product it is. I am developing a forum that will be multilingual (Arabic/English/German). Most users will be extremely limited in the other languages, basically I don’t want to expect a German/English speaker to be able to read Arabic script, and vice versa. I also don’t want to rely too much on their computer skills—want to make this as easy as possible.

Is there a way that I can provide a separate URL that would auto-set the interface language on first visit, so that registration can happen in their native language? Something like and

Very open to other ways of solving this problem.


Detecting user language
MOSS Roadmap - Mailing lists
Setting user locale via SSO
Multilingual sites: ask for preferred language at registration
When user locale is `default`, should use HTTP `accept-language`
(Sam Saffron) #2

This is not an existing feature, it would need to be built, can be done in a plugin.

(Simon Cossar) #3

Maybe it could be useful to add an input to the existing sign-up form that allows a user to select their default language at the time they sign up. That way, when they first log in they will see the forum in a language they understand. This could be made as a plugin. There could also be a banner that appears for non-logged-in users. It could be in all your forum’s languages and guide speakers of each language through the log-in process.

(Jeff Atwood) #4

If user language selection is enabled I see no downside to having this as a default, built in thing at signup time.

(Sam Saffron) #5

The tricky thing though is that if you can not read English you are in a bit of a bind to even get to that page or select the language.

(Simon Cossar) #6

Another way to do it would be to provide a separate site to help users log in. There could be a link on the forum in each of the target languages saying something like ‘click here if you need help getting started.’ That would link to a sign-up form in the appropriate language. It looks like it takes two API requests - one to create the user and one to set their language preference.

(Conor O'rourke) #7

Thanks for all the great responses.

Would it be easier to implement a language toggle (e.g. using images of flags) that would would stay on the top of every page like some websites have?

(Simon Cossar) #8

That makes sense. I think it could be done as a plugin. Clicking on the flag would cause a new translation file to be downloaded and tell the application to start using it.

(Gerhard Schlager) #9

How about using the Accept-Language HTTP header when allow_user_locale is enabled?

If someone visits the site and isn’t logged in yet we could use the first language from the HTTP header that is also available in Discourse.

(Sam Saffron) #10

How prevalent is that header?

(Gerhard Schlager) #11

I’d say it’s quite common and will work for 99% of all users. Most browsers send it unless the user explicitly changes or deactivates it.

What does it look like on my system?

  • Chrome: de-AT,de;q=0.8,de-DE;q=0.6,en-US;q=0.4,en;q=0.2
  • Firefox: de,en-US;q=0.7,en;q=0.3
  • Internet Explorer: de-AT
  • Edge: de-AT
  • Chrome on Android: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4

Of course users should always be able to override the server detected language.

(Sam Saffron) #12

I support this, out of the box.

  • If user locales are enabled


  • If we have a mapping (keep in mind region locales make this annoying - de-AT vs de)

Automatically select locale for anonymous and logged on user, unless explicitly set in user prefs.

(Noneck) #13

WAAAHOOO! I’m glad this is being discussed. Here’s my take.

Effectively, I have two forums running on one codebase. Right now, I have an english and farsi forum, and we’re making plans on adding more but are stuck on this language issue.

Ideally, we want browser detection. I’ve deployed this jQuery script to some success.

For my user story:

  • I want “guest/non-athunicated” users see the forum in their native language.
  • When a user creates an account, they select the interface language they want to use.

I think this is what @sam is saying.

@Simon_Cossar I’d really love your feedback and would love to collaborate with you on this idea.

(Simon Cossar) #14

I’ve made a plugin for this. GitHub - scossar/accept-language: A Discourse plugin to set the language for non-logged-in users

The logic is that if the site is visited by a non-logged-in user and the site allows user-locales, the locale is set from the request headers. If there is a logged-in user the locale is set from the user’s effective locale. If there is no logged-in user and user locales are disabled, the locale is set from the site default locale.

It uses the http_accept_language gem to deal with those.

The only problem I am finding with this is when login is required to view any site content, the ‘login required welcome message’ markdown content isn’t translated. The rest of the user interface is translated though.

The problem with the login message is that SiteText.text_for method caches it’s content.

New option: auto-select language by HTTP header
(Conor O'rourke) #15

Amazing! Thanks @Simon_Cossar!

edit: seems to work flawlessly! Well done

(Simon Cossar) #16

It works until the user signs in. After that they are back using the site default locale until they set the locale they want in their user preferences. I’ll see if I can add the locale selector to the sign-up form.

(Simon Cossar) #17

I’ve added a locale selector to the sign-up form. It defaults to the locale from the users Accept-Language headers.

The activation email that is sent after the user signs up is sent in the site’s default language - not the user’s chosen language. Other than that, everything seems to be working as it should.

(Conor O'rourke) #18

For some reason, I am having trouble getting this plugin to choose Arabic as a language. I’ve tried with German and French, and with those languages, the automatic switch works perfectly. But with Arabic, my actual target language, the auto-switch seems to fail, and it just shows English interface text. Any ideas?

(Simon Cossar) #19

It works with Arabic for me. What browser and operating system are you trying it on?

Can you try it here and see if that is working for you? (Ignore the content on the site - it’s just set-up for testing)

(Conor O'rourke) #20

Unfortunately that site’s interface was also not displaying in Arabic for
me, the login buttons etc were displayed in English.

I am using Chrome Version 46.0.2490.86 (64-bit) on a Macbook Air with the
latest system updates (10.11.1)