schungx
(Stephen Chung)
2017 年9 月 26 日 04:46
41
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 个赞
simon
2017 年9 月 26 日 04:55
42
schungx:
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,
Yes, if you look at users_controller you can see how it’s done differently.
3 个赞
schungx
(Stephen Chung)
2017 年9 月 26 日 05:34
43
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 个赞
schungx
(Stephen Chung)
2017 年9 月 26 日 06:15
44
Judging from this here:
def perform_accept_invitation
params.require(:id)
params.permit(:username, :name, :password, :user_custom_fields)
invite = Invite.find_by(invite_key: params[:id])
if invite.present?
begin
user = invite.redeem(username: params[:username], name: params[:name], password: params[:password], user_custom_fields: params[:user_custom_fields])
if user.present?
log_on_user(user)
post_process_invite(user)
end
topic = user.present? ? invite.topics.first : nil
render json: {
success: true,
redirect_to: topic.present? ? path("#{topic.relative_url}") : path("/")
}
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
This file has been truncated. show original
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.
1 个赞
riking
(Kane York)
2020 年7 月 23 日 00:30
45
自从 @david 的这次提交起,现在应该可以顺利运行了
master ← davidtaylorhq:locale-anonymous-cache
merged 05:00PM - 22 Jul 20 UTC
This only applies when allow_user_locale is enabled
1 个赞
Elmer_Wu
(Elmer Wu)
2020 年8 月 24 日 22:12
46
非常感谢大家。
但是……我还有另一个问题。
我不知道该怎么用这个。
simon
2020 年8 月 26 日 23:19
47
若要允许根据浏览器的语言设置为匿名(未登录)用户设置区域设置,您需要同时启用“允许用户区域设置”和“从 Accept-Language 头设置区域设置”这两个站点设置。这两个设置均位于站点“基本设置”页面的顶部附近。
启用这些设置后,未登录站点的用户将自动将其 Discourse 用户界面设置为他们在浏览器中设定的首选语言。如果未登录用户决定在站点上创建账户,其区域设置将自动设置为浏览器所设定的区域设置。请注意,这仅在用户的区域设置对应于 Discourse 已翻译的语言时才有效。
“从 Accept-Language 头设置区域设置”设置对已在站点上创建账户的用户没有影响。一旦账户创建完成,Discourse 用户界面将显示为用户在偏好设置页面中设定的区域设置。只要启用了“允许用户区域设置”选项,现有用户即可在此处更新其区域设置:
关于“从 Accept-Language 头设置区域设置”这一设置,需要撰写一篇相关的 howto 主题文章。我已将此事项设为提醒,并将尽快完成该文章的撰写。
2 个赞
loginerror
(Maciej Kuźmicz)
2023 年11 月 21 日 12:04
48
simon:
要允许根据匿名(未登录)用户的浏览器语言设置来设置其区域设置,您需要启用“允许用户区域设置”和“从 accept language header 设置区域设置”这两个站点设置。这两个设置都位于站点“基本设置”页面的顶部附近。
启用这些设置后,未登录用户的 Discourse 用户界面将自动设置为他们在浏览器中设置的首选语言。如果未登录用户决定在站点上创建帐户,其区域设置将自动设置为由其浏览器设置的区域设置。请注意,这仅在用户的区域设置是 Discourse 已翻译成该语言时才有效。
关于此设置与翻译插件的快速提问。如果插件翻译限制设置为“所有人”,翻译插件在这种情况下是否可用?
(鉴于不同的区域设置是触发翻译按钮首先显示的因素)
只是通知您一下,我认为“所有人”组在此翻译设置下无法正常工作。它也不对匿名用户可用,因此建议将其设置为 TL0 组。
1 个赞