mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Refactor current_user_locale to a new method
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
module I18nHelper
|
||||
def set_locale
|
||||
# Save a given locale
|
||||
# Save a given locale from params
|
||||
if params[:locale] && available_locale?(params[:locale])
|
||||
spree_current_user&.update!(locale: params[:locale])
|
||||
cookies[:locale] = params[:locale]
|
||||
end
|
||||
|
||||
# After logging in, check if the user chose a locale before
|
||||
if spree_current_user && spree_current_user.locale.nil? && cookies[:locale]
|
||||
spree_current_user.update!(locale: params[:locale])
|
||||
if current_user_locale.nil? && cookies[:locale]
|
||||
spree_current_user&.update!(locale: params[:locale])
|
||||
end
|
||||
|
||||
I18n.locale = spree_current_user.andand.locale || cookies[:locale] || I18n.default_locale
|
||||
I18n.locale = current_user_locale || cookies[:locale] || I18n.default_locale
|
||||
end
|
||||
|
||||
def valid_locale(user)
|
||||
@@ -29,4 +29,8 @@ module I18nHelper
|
||||
def available_locale?(locale)
|
||||
Rails.application.config.i18n.available_locales.include?(locale)
|
||||
end
|
||||
|
||||
def current_user_locale
|
||||
spree_current_user.andand.locale
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user