diff options
author | Louise Crow <louise.crow@gmail.com> | 2015-02-02 14:34:02 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2015-02-23 11:17:56 +0000 |
commit | 2c6250666b8dd5ca383ec29ea786805b102e2ac7 (patch) | |
tree | 25b528e65c625007cf064dee4d9cc6b1e0eb2d59 /app/models | |
parent | 60e3aad7ac32ac826b93a707db9589237fd4948d (diff) |
Test localised value for import against existing localised value
Previously the call to public_body.send would return the value for
the default locale if no value was set in the current locale,
meaning that translations for attributes that were the same as
the attribute values in the default locale were not being loaded.
Fixes #2134.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/public_body.rb | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index a9cdfeab2..ec4e8bb32 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -422,6 +422,17 @@ class PublicBody < ActiveRecord::Base has_tag?('site_administration') end + + # Read an attribute value (without using locale fallbacks if the attribute is translated) + def read_attribute_value(name, locale) + if PublicBody.translates.include?(name.to_sym) + globalize.stash.contains?(locale, name) ? globalize.stash.read(locale, name) : translation_for(locale).send(name) + else + self.send(name) + end + end + + class ImportCSVDryRun < StandardError end @@ -521,8 +532,8 @@ class PublicBody < ActiveRecord::Base end end end + if !localized_value.nil? and public_body.read_attribute_value(field_name, locale) != localized_value - if !localized_value.nil? and public_body.send(field_name) != localized_value changed[field_name] = "#{public_body.send(field_name)}: #{localized_value}" public_body.send("#{field_name}=", localized_value) end @@ -549,7 +560,7 @@ class PublicBody < ActiveRecord::Base localized_value = "#{localized_value} #{tag}" unless tag.empty? end - if !localized_value.nil? and public_body.send(field_name) != localized_value + if !localized_value.nil? and public_body.read_attribute_value(field_name, locale) != localized_value changed[field_name] = localized_value public_body.send("#{field_name}=", localized_value) end @@ -793,6 +804,19 @@ class PublicBody < ActiveRecord::Base private + # Read an attribute value (without using locale fallbacks if the attribute is translated) + def read_attribute_value(name, locale) + if self.class.translates.include?(name.to_sym) + if globalize.stash.contains?(locale, name) + globalize.stash.read(locale, name) + else + translation_for(locale).send(name) + end + else + send(name) + end + end + def request_email_if_requestable # Request_email can be blank, meaning we don't have details if self.is_requestable? |