From 2915048afaff53884d2245c72c5fbec2e2a863da Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 5 Oct 2023 11:02:56 +1100 Subject: [PATCH] Always set locale for reflexes I considered using I18nHelper like we do in controllers, but that is for choosing a locale, which we don't need to do for reflexes. --- app/reflexes/application_reflex.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/reflexes/application_reflex.rb b/app/reflexes/application_reflex.rb index 941a8c4f0c..2945517ad0 100644 --- a/app/reflexes/application_reflex.rb +++ b/app/reflexes/application_reflex.rb @@ -5,21 +5,16 @@ class ApplicationReflex < StimulusReflex::Reflex # # Learn more at: https://docs.stimulusreflex.com/rtfm/reflex-classes # - # If your ActionCable connection is: `identified_by :current_user` - # delegate :current_user, to: :connection - # - # If you need to localize your Reflexes, you can set the I18n locale here: - # - # before_reflex do - # I18n.locale = :fr - # end - # # For code examples, considerations and caveats, see: # https://docs.stimulusreflex.com/rtfm/patterns#internationalization include CanCan::ControllerAdditions delegate :current_user, to: :connection + before_reflex do + I18n.locale = current_user.locale + end + private def current_ability