Module: Spree::Core::ControllerHelpers::Locale

Extended by:
ActiveSupport::Concern
Included in:
BaseController
Defined in:
lib/spree/core/controller_helpers/locale.rb

Instance Method Summary collapse

Instance Method Details

#available_localesObject



48
49
50
# File 'lib/spree/core/controller_helpers/locale.rb', line 48

def available_locales
  Spree::Store.available_locales
end

#current_localeObject



24
25
26
27
28
29
30
31
32
# File 'lib/spree/core/controller_helpers/locale.rb', line 24

def current_locale
  @current_locale ||= if params[:locale].present? && supported_locale?(params[:locale])
                        params[:locale]
                      elsif respond_to?(:config_locale, true) && config_locale.present?
                        config_locale
                      else
                        current_store&.default_locale || Rails.application.config.i18n.default_locale || I18n.default_locale
                      end
end

#locale_paramObject



52
53
54
55
56
# File 'lib/spree/core/controller_helpers/locale.rb', line 52

def locale_param
  return if I18n.locale.to_s == current_store.default_locale || current_store.default_locale.nil?

  I18n.locale.to_s
end

#set_localeObject



20
21
22
# File 'lib/spree/core/controller_helpers/locale.rb', line 20

def set_locale
  I18n.locale = current_locale
end

#supported_locale?(locale_code) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/spree/core/controller_helpers/locale.rb', line 38

def supported_locale?(locale_code)
  return false if supported_locales.nil?

  supported_locales.include?(locale_code&.to_s)
end

#supported_localesObject



34
35
36
# File 'lib/spree/core/controller_helpers/locale.rb', line 34

def supported_locales
  @supported_locales ||= current_store&.supported_locales_list
end

#supported_locales_for_all_storesObject



44
45
46
# File 'lib/spree/core/controller_helpers/locale.rb', line 44

def supported_locales_for_all_stores
  @supported_locales_for_all_stores ||= Spree.available_locales
end