Module: EmbeddedLocalization::ActiveRecord::ClassMethods

Defined in:
lib/embedded_localization/active_record/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#fallback_locales(locale) ⇒ Object

The locales to look at, in order, when locale has no translation for an attribute: the chain configured in I18n.fallbacks (e.g. config.i18n.fallbacks = { 'de-AT' => 'de' } gives :de for :"de-AT"; I18n.fallbacks exists once i18n/backend/fallbacks is loaded, which Rails does for config.i18n.fallbacks), followed by I18n.default_locale. locale itself is not part of the result.



34
35
36
37
# File 'lib/embedded_localization/active_record/class_methods.rb', line 34

def fallback_locales(locale)
  chain = I18n.respond_to?(:fallbacks) ? I18n.fallbacks[locale] : []
  (chain + [I18n.default_locale]).uniq - [locale]
end

#fallbacks?Boolean

determine if we are using fallbacks

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/embedded_localization/active_record/class_methods.rb', line 25

def fallbacks?
  i18n_fallbacks = I18n.backend.class.included_modules.map(&:to_s).include?('I18n::Backend::Fallbacks')   # will be true if config.i18n.fallbacks => true in config
  i18n_fallbacks || translation_options[:fallbacks] == true
end

#translated?(name) ⇒ Boolean

Checks whether field with given name is translated field. Param String or Symbol Returns true or false

Returns:

  • (Boolean)


15
16
17
# File 'lib/embedded_localization/active_record/class_methods.rb', line 15

def translated?(name)
  translated_attribute_names.include?(name.to_sym)
end

#translated_attributesObject

Returns Array of Symbols for all attributes of this class, which have translations through acts_as_i18n. returns an Array of Symbols



8
9
10
# File 'lib/embedded_localization/active_record/class_methods.rb', line 8

def translated_attributes
  translated_attribute_names
end

#translation_storageObject

How the i18n column is stored: :yaml (text column, the default), :json, :jsonb or :hstore



20
21
22
# File 'lib/embedded_localization/active_record/class_methods.rb', line 20

def translation_storage
  (translation_options[:storage] || :yaml).to_sym
end