Variable default interface language for new users

This is also incorrect. I18n.locale is set from the header only if there is no logged in user. See here:

Now, I suspect that when the user first signs up, current_user is not set, thus kick-starting the whole get-the-language-from-header process, and then the I18n.locale got persisted into the user’s account.

However, this is certain NOT how it is done when a user redeems an invite.

1 Like

Yes, if you look at users_controller you can see how it’s done differently.


Yup. I see it.

UsersController inherits from ApplicationController, which runs set_locale as a before_action.

That kick-starts the whole thing.

But users redeeming an invitation does not go through this.


Judging from this here:

Would this work:

      user = invite.redeem(username: params[:username], name: params[:name], password: params[:password], user_custom_fields: params[:user_custom_fields])
      if user.present?
        user.locale = I18n.locale!


Sorry for my Ruby – I don’t really know it. :sweat_smile:

1 Like

As of this commit from @david, this should work cleanly now :tada:

1 Like

Thank guys so much.
But…there’s another problem for me.:pensive:
I don’t knew how to use this😣

To allow the locale to be set for anonymous (non-logged in) users based on their browser’s language settings, you need to enable both the allow user locale and set locale from accept language header site settings. Both of those settings are found near the top of your site’s “Basic Setup” settings page.

Once those settings are enabled, users who are not logged into the site will have the Discourse user interface automatically set to the preferred language they have set in their browser. If a non-logged-in user decides to create an account on the site, their locale will be automatically set to the locale that is set by their browser. Note that this will only work if their locale is set to a language that Discourse has been translated into.

The set locale from accept language header setting has no effect on users who have already created accounts on the site. Once an account has been created, the Discourse user interface will be displayed in the locale that is set on the user’s preferences page. As long as the allow user locale setting is enabled, existing users can update their locale here:

The set locale from accept language header needs to have a #howto topic written for it. I’m setting myself a reminder for that and will get the topic written soon.


Quick question on this in relation to the translator plugin. Will the translator plugin work in this scenario if the plugin translation restriction is set to Everyone?
(given that the different locale is the thing that triggers the translation button to show up in the first place)

Just an FYI, I don’t think the ‘Everyone’ group works properly with that Translator setting. It’s also not available to anons, so setting it to TL0 is the recommended group for that.

1 Like