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/patches/active_support/inflections.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/rails6_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,
lib/patches/active_record/rails6_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, Inflections, Interpolation, Persistence, Relation, UniquenessValidatorOverride, Validations, XmlSerializer
Constant Summary
collapse
- ACTIVE_RECORD_50 =
Gem::Version.new('5.0.0')
- ACTIVE_RECORD_51 =
Gem::Version.new('5.1.0')
- ACTIVE_RECORD_52 =
Gem::Version.new('5.2.0')
- ACTIVE_RECORD_60 =
Gem::Version.new('6.0.0')
- ACTIVE_RECORD_61 =
Gem::Version.new('6.1.0')
- CURRENT_RUBY =
Gem::Version.new(RUBY_VERSION)
- RUBY_VERSION_27 =
Gem::Version.new('2.7.0')
- Version =
'6.2.1'
Class Method Summary
collapse
Class Method Details
.default_fallbacks(for_locale = self.locale) ⇒ Object
62
63
64
|
# File 'lib/globalize.rb', line 62
def default_fallbacks(for_locale = self.locale)
i18n_fallbacks? ? I18n.fallbacks[for_locale] : [for_locale.to_sym]
end
|
.fallbacks(for_locale = self.locale) ⇒ Object
58
59
60
|
# File 'lib/globalize.rb', line 58
def fallbacks(for_locale = self.locale)
read_fallbacks[for_locale] || default_fallbacks(for_locale)
end
|
.fallbacks=(locales) ⇒ Object
50
51
52
|
# File 'lib/globalize.rb', line 50
def fallbacks=(locales)
set_fallbacks(locales)
end
|
.i18n_fallbacks? ⇒ Boolean
54
55
56
|
# File 'lib/globalize.rb', line 54
def i18n_fallbacks?
I18n.respond_to?(:fallbacks)
end
|
.locale ⇒ Object
25
26
27
|
# File 'lib/globalize.rb', line 25
def locale
read_locale || I18n.locale
end
|
.locale=(locale) ⇒ Object
29
30
31
|
# File 'lib/globalize.rb', line 29
def locale=(locale)
set_locale(locale)
end
|
.storage ⇒ Object
Thread-safe global storage
67
68
69
|
# File 'lib/globalize.rb', line 67
def storage
RequestStore.store
end
|
.with_locale(locale, &block) ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/globalize.rb', line 33
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
44
45
46
47
48
|
# File 'lib/globalize.rb', line 44
def with_locales(*locales, &block)
locales.flatten.map do |locale|
with_locale(locale, &block)
end
end
|