5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/active_translation/translation_job.rb', line 5
def perform(object, locale, checksum)
translated_data = {}
object.translatable_attribute_names.each do |attribute|
translated_data[attribute.to_s] = object.translate_attribute(attribute, locale)
end
translation = object.translations
.find_or_initialize_by(
locale: locale,
)
existing_data = translation.translated_attributes.present? ? translation.translated_attributes : {}
merged_attributes = existing_data.merge(translated_data)
translation.update!(
translated_attributes: merged_attributes,
source_checksum: checksum
)
end
|