Module: Maglev::I18n

Defined in:
lib/maglev/i18n.rb

Defined Under Namespace

Classes: UnavailableLocaleError

Class Method Summary collapse

Class Method Details

.available_localesObject



11
12
13
# File 'lib/maglev/i18n.rb', line 11

def available_locales
  Current.available_locales || %i[en]
end

.available_locales=(locales) ⇒ Object



15
16
17
# File 'lib/maglev/i18n.rb', line 15

def available_locales=(locales)
  Current.available_locales = locales.map(&:to_sym)
end

.current_localeObject



23
24
25
# File 'lib/maglev/i18n.rb', line 23

def current_locale
  Current.locale || default_locale
end

.current_locale=(locale) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/maglev/i18n.rb', line 27

def current_locale=(locale)
  locale = locale.to_sym

  raise UnavailableLocaleError unless available_locales.include?(locale)

  Current.locale = locale
end

.default_localeObject



19
20
21
# File 'lib/maglev/i18n.rb', line 19

def default_locale
  available_locales.first
end

.with_locale(locale, &block) ⇒ Object



35
36
37
# File 'lib/maglev/i18n.rb', line 35

def with_locale(locale, &block)
  Current.set(locale: locale, &block)
end