Module: ActsAsLocalizable::AR::InstanceMethods
- Defined in:
- lib/acts_as_localizable.rb
Instance Method Summary collapse
-
#localized(locale = nil) ⇒ Object
has_many :localized_fields,:as => :object.
Instance Method Details
#localized(locale = nil) ⇒ Object
has_many :localized_fields,:as => :object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/acts_as_localizable.rb', line 94 def localized(locale=nil) if locale == nil locale = I18n.locale end default_values = self.attributes if self.class.acts_as_localizable_config.default_locale.downcase != locale.to_s.downcase && (self.localized_cache.blank? == true || self.localized_cache[locale].blank? == true) fields = self.localized_fields.select {|localized_field| localized_field.locale.downcase == locale.to_s.downcase} if fields.blank? == false fields.each do |field| default_values[field.field_name] = field.value; end end end if self.localized_cache == nil self.localized_cache = {locale => ActsAsLocalizable::AR::LocalValues.new(locale,default_values)} elsif self.localized_cache[locale].blank? self.localized_cache[locale] = ActsAsLocalizable::AR::LocalValues.new(locale,default_values) end return self.localized_cache[locale] end |