Module: Localite::Settings

Included in:
Localite
Defined in:
lib/localite/settings.rb

Instance Method Summary collapse

Instance Method Details

#available?(locale) ⇒ Boolean

is a specific locale available?

Returns:

  • (Boolean)


16
17
18
# File 'lib/localite/settings.rb', line 16

def available?(locale)
  locale && I18n.backend.available_locales.include?(locale.to_sym)
end

#baseObject

Returns the base locale; e.g. :en



4
5
6
# File 'lib/localite/settings.rb', line 4

def base
  I18n.default_locale
end

#in(locale, &block) ⇒ Object

runs a block in the changed locale



30
31
32
33
34
35
36
# File 'lib/localite/settings.rb', line 30

def in(locale, &block)
  old = self.locale
  self.locale = locale if locale
  yield
ensure
  self.locale = old
end

#localeObject

returns the current locale; defaults to the base locale



10
11
12
# File 'lib/localite/settings.rb', line 10

def locale
  I18n.locale
end

#locale=(locale) ⇒ Object

sets the current locale. If the locale is not available it changes the locale to the default locale.



23
24
25
26
# File 'lib/localite/settings.rb', line 23

def locale=(locale)
  locale = locale.to_sym
  I18n.locale = available?(locale) ? locale : base
end