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 个赞

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

3 个赞

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.

2 个赞

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
        user.save!

        log_on_user(user)
        post_process_invite(user)
      end

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

1 个赞

自从 @david 的这次提交起,现在应该可以顺利运行了 :tada:

1 个赞

非常感谢大家。
但是……我还有另一个问题。:pensive_face:
我不知道该怎么用这个。:persevering_face:

若要允许根据浏览器的语言设置为匿名(未登录)用户设置区域设置,您需要同时启用“允许用户区域设置”和“从 Accept-Language 头设置区域设置”这两个站点设置。这两个设置均位于站点“基本设置”页面的顶部附近。

启用这些设置后,未登录站点的用户将自动将其 Discourse 用户界面设置为他们在浏览器中设定的首选语言。如果未登录用户决定在站点上创建账户,其区域设置将自动设置为浏览器所设定的区域设置。请注意,这仅在用户的区域设置对应于 Discourse 已翻译的语言时才有效。

“从 Accept-Language 头设置区域设置”设置对已在站点上创建账户的用户没有影响。一旦账户创建完成,Discourse 用户界面将显示为用户在偏好设置页面中设定的区域设置。只要启用了“允许用户区域设置”选项,现有用户即可在此处更新其区域设置:

关于“从 Accept-Language 头设置区域设置”这一设置,需要撰写一篇相关的 howto 主题文章。我已将此事项设为提醒,并将尽快完成该文章的撰写。

2 个赞

关于此设置与翻译插件的快速提问。如果插件翻译限制设置为“所有人”,翻译插件在这种情况下是否可用?
image
(鉴于不同的区域设置是触发翻译按钮首先显示的因素)

只是通知您一下,我认为“所有人”组在此翻译设置下无法正常工作。它也不对匿名用户可用,因此建议将其设置为 TL0 组。

1 个赞