Module: CountryLocale

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/country_locale.rb

Overview

callback para controlar locale según el country del usuario

Constant Summary collapse

COUNTRY_LOCALE =
{
  cl: 'es-cl',
  mx: 'es-mx',
  pe: 'es-pe',
  ar: 'es-ar'
}.with_indifferent_access

Instance Method Summary collapse

Instance Method Details

#locale_by_country(country) ⇒ Object



26
27
28
# File 'app/controllers/concerns/country_locale.rb', line 26

def locale_by_country(country)
  COUNTRY_LOCALE[country] || I18n.default_locale
end

#switch_locale(&action) ⇒ Object



17
18
19
20
21
22
23
24
# File 'app/controllers/concerns/country_locale.rb', line 17

def switch_locale(&action)
  if current_user&.id
    locale = locale_by_country(current_user&.country&.downcase)
    I18n.with_locale(locale, &action)
  else
    I18n.with_locale('es-cl', &action)
  end
end