schungx
(Stephen Chung)
2017 年 9 月 26 日午前 4: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 日午前 4: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 日午前 5: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 日午前 6: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 日午前 12: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 日午後 10:12
46
皆さん、本当にありがとうございます。
でも……私にはもう一つ問題があるんです😔
使い方がわからないんです😣
simon
2020 年 8 月 26 日午後 11: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ヘッダーからロケールを設定」の両方のサイト設定を有効にする必要があります。これらの設定は両方とも、サイトの「基本設定」設定ページのほぼ上部にあります。
これらの設定が有効になると、サイトにログインしていないユーザーは、ブラウザで設定されている優先言語にDiscourseのユーザーインターフェースが自動的に設定されます。ログインしていないユーザーがサイトにアカウントを作成することにした場合、ロケールはブラウザによって設定されたロケールに自動的に設定されます。これは、ロケールがDiscourseが翻訳された言語に設定されている場合にのみ機能することに注意してください。
この件について、翻訳者プラグインとの関連で簡単な質問があります。プラグインの翻訳制限が「全員」に設定されている場合、このシナリオで翻訳者プラグインは機能しますか?
(そもそも翻訳ボタンが表示されるのをトリガーするのが異なるロケールであるということを考えると)
念のためお伝えしておきますが、「全員」グループは、その翻訳者の設定では正しく機能しないと思います。また、匿名のユーザーは利用できないため、TL0に設定することが推奨されるグループです。
「いいね!」 1