Module: Globalize
- Defined in:
- lib/globalize/active_record/attributes.rb,
lib/globalize.rb,
lib/globalize/version.rb,
lib/globalize/active_record.rb,
lib/globalize/interpolation.rb,
lib/patches/active_record/relation.rb,
lib/globalize/active_record/adapter.rb,
lib/globalize/active_record/act_macro.rb,
lib/globalize/active_record/migration.rb,
lib/patches/active_record/persistence.rb,
lib/globalize/active_record/exceptions.rb,
lib/globalize/active_record/translation.rb,
lib/globalize/active_record/adapter_dirty.rb,
lib/globalize/active_record/class_methods.rb,
lib/globalize/active_record/instance_methods.rb,
lib/patches/active_record/rails4/serialization.rb,
lib/patches/active_record/rails5_1/serialization.rb,
lib/patches/active_record/xml_attribute_serializer.rb,
lib/patches/active_record/rails4/uniqueness_validator.rb,
lib/patches/active_record/rails5/uniqueness_validator.rb,
lib/globalize/active_record/translated_attributes_query.rb,
lib/patches/active_record/rails5_1/uniqueness_validator.rb
Overview
Helper class for storing values per locale. Used by Globalize::Adapter to stash and cache attribute values.
Defined Under Namespace
Modules: ActiveRecord, AttributeMethods, Interpolation, Persistence, Relation, UniquenessValidatorOverride, Validations, XmlSerializer
Constant Summary
collapse
- Version =
'5.3.1'
Class Method Summary
collapse
Class Method Details
.default_fallbacks(for_locale = self.locale) ⇒ Object
52
53
54
|
# File 'lib/globalize.rb', line 52
def default_fallbacks(for_locale = self.locale)
i18n_fallbacks? ? I18n.fallbacks[for_locale] : [for_locale.to_sym]
end
|
.fallbacks(for_locale = self.locale) ⇒ Object
48
49
50
|
# File 'lib/globalize.rb', line 48
def fallbacks(for_locale = self.locale)
read_fallbacks[for_locale] || default_fallbacks(for_locale)
end
|
.fallbacks=(locales) ⇒ Object
40
41
42
|
# File 'lib/globalize.rb', line 40
def fallbacks=(locales)
set_fallbacks(locales)
end
|
.i18n_fallbacks? ⇒ Boolean
44
45
46
|
# File 'lib/globalize.rb', line 44
def i18n_fallbacks?
I18n.respond_to?(:fallbacks)
end
|
.locale ⇒ Object
15
16
17
|
# File 'lib/globalize.rb', line 15
def locale
read_locale || I18n.locale
end
|
.locale=(locale) ⇒ Object
19
20
21
|
# File 'lib/globalize.rb', line 19
def locale=(locale)
set_locale(locale)
end
|
.rails_52? ⇒ Boolean
65
66
67
|
# File 'lib/globalize.rb', line 65
def rails_52?
::ActiveRecord.version >= Gem::Version.new('5.2.0')
end
|
.rails_5? ⇒ Boolean
61
62
63
|
# File 'lib/globalize.rb', line 61
def rails_5?
::ActiveRecord.version >= Gem::Version.new('5.1.0')
end
|
.storage ⇒ Object
Thread-safe global storage
57
58
59
|
# File 'lib/globalize.rb', line 57
def storage
RequestStore.store
end
|
.with_locale(locale, &block) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/globalize.rb', line 23
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
34
35
36
37
38
|
# File 'lib/globalize.rb', line 34
def with_locales(*locales, &block)
locales.flatten.map do |locale|
with_locale(locale, &block)
end
end
|