Module: Globalize

Defined in:
lib/globalize/active_record/attributes.rb,
lib/globalize.rb,
lib/globalize/versioning.rb,
lib/globalize/active_record.rb,
lib/globalize/interpolation.rb,
lib/globalize/active_record/adapter.rb,
lib/globalize/versioning/paper_trail.rb,
lib/globalize/active_record/act_macro.rb,
lib/globalize/active_record/migration.rb,
lib/globalize/active_record/exceptions.rb,
lib/globalize/active_record/translation.rb,
lib/globalize/active_record/class_methods.rb,
lib/globalize/active_record/instance_methods.rb

Overview

Helper class for storing values per locale. Used by Globalize::Adapter to stash and cache attribute values.

Defined Under Namespace

Modules: ActiveRecord, Interpolation, Versioning

Class Method Summary collapse

Class Method Details

.default_fallbacks(for_locale = self.locale) ⇒ Object


50
51
52
# File 'lib/globalize.rb', line 50

def default_fallbacks(for_locale = self.locale)
  i18n_fallbacks? ? I18n.fallbacks[for_locale] : [for_locale.to_sym]
end

.fallbacks(for_locale = self.locale) ⇒ Object


46
47
48
# File 'lib/globalize.rb', line 46

def fallbacks(for_locale = self.locale)
  read_fallbacks[for_locale] || default_fallbacks(for_locale)
end

.fallbacks=(locales) ⇒ Object


38
39
40
# File 'lib/globalize.rb', line 38

def fallbacks=(locales)
  set_fallbacks(locales)
end

.i18n_fallbacks?Boolean

Returns:

  • (Boolean)

42
43
44
# File 'lib/globalize.rb', line 42

def i18n_fallbacks?
  I18n.respond_to?(:fallbacks)
end

.localeObject


13
14
15
# File 'lib/globalize.rb', line 13

def locale
  read_locale || I18n.locale
end

.locale=(locale) ⇒ Object


17
18
19
# File 'lib/globalize.rb', line 17

def locale=(locale)
  set_locale(locale)
end

.with_locale(locale, &block) ⇒ Object


21
22
23
24
25
26
27
28
29
30
# File 'lib/globalize.rb', line 21

def with_locale(locale, &block)
  previous_locale = read_locale
  begin
    set_locale(locale)
    result = yield(locale)
  ensure
    set_locale(previous_locale)
  end
  result
end

.with_locales(*locales, &block) ⇒ Object


32
33
34
35
36
# File 'lib/globalize.rb', line 32

def with_locales(*locales, &block)
  locales.flatten.map do |locale|
    with_locale(locale, &block)
  end
end