mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
FIX: Reports did not respect user locale (#30524)
Our bulk report endpoint uses `hijack`, which does not use the current user's locale via the `with_resolved_locale` method in `ApplicationController`. This is happening because we are doing `around_action` to set the locale, then calling the code in the block inside the action directly when we use `hijack`. We can fix this by capturing `I18n.locale` when starting the hijack then using `I18n.with_locale` when evaluating the block inside `hijack`, this way the translations will always use the correct locale based on the current user.
This commit is contained in:
@ -13,6 +13,10 @@ module Hijack
|
||||
request.env["discourse.request_tracker.skip"] = true
|
||||
request_tracker = request.env["discourse.request_tracker"]
|
||||
|
||||
# need this because we can't call with_resolved_locale with around_action
|
||||
# when we are evaluating the block
|
||||
resolved_locale = I18n.locale
|
||||
|
||||
# in the past unicorn would recycle env, this is not longer the case
|
||||
env = request.env
|
||||
|
||||
@ -61,7 +65,7 @@ module Hijack
|
||||
|
||||
view_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||
begin
|
||||
instance.instance_eval(&blk)
|
||||
I18n.with_locale(resolved_locale) { instance.instance_eval(&blk) }
|
||||
rescue => e
|
||||
# TODO we need to reuse our exception handling in ApplicationController
|
||||
Discourse.warn_exception(
|
||||
|
Reference in New Issue
Block a user