Skip to content
Snippets Groups Projects
Commit 7dc2b98c authored by Arnaud Levy's avatar Arnaud Levy
Browse files

Merge branch 'main' of github.com:noesya/osuny

parents 1b201a69 04aac152
No related branches found
No related tags found
No related merge requests found
......@@ -136,11 +136,12 @@ class Communication::Block < ApplicationRecord
block
end
def translate!(about_translation)
def translate!(about_translation, heading_id = nil)
translation = self.dup
translation.about = about_translation
translation.template.translate!
translation.data = translation.template.data
translation.heading_id = heading_id
translation.save
end
......@@ -171,7 +172,7 @@ class Communication::Block < ApplicationRecord
def set_heading_from_about
# IMPROVEMENT: Ne gère que le 1er niveau actuellement
self.heading = about.headings.root.ordered.last
self.heading ||= about.headings.root.ordered.last
end
# FIXME @sebou
......
......@@ -54,6 +54,21 @@ class Communication::Block::Heading < ApplicationRecord
[about]
end
def translate!(about_translation, parent_id = nil)
translation = self.dup
translation.about = about_translation
translation.parent_id = parent_id
translation.save
# then translate blocks
blocks.ordered.each do |block|
block.translate!(about_translation, translation.id)
end
# and then children
children.ordered.each do |child|
child.translate!(about_translation, translation.id)
end
end
def to_s
"#{title}"
end
......
......@@ -67,8 +67,8 @@ module WithTranslations
# Handle featured image if object has one
translate_attachment(translation, :featured_image) if respond_to?(:featured_image) && featured_image.attached?
translation.save
# Handle blocks if object has any
translate_blocks!(translation) if respond_to?(:blocks)
# Handle headings & blocks if object has any
translate_contents!(translation) if respond_to?(:contents)
translate_additional_data!(translation)
translation
......@@ -81,10 +81,14 @@ module WithTranslations
parent.find_or_translate!(language)
end
def translate_blocks!(translation)
blocks.ordered.each do |block|
def translate_contents!(translation)
blocks.without_heading.ordered.each do |block|
block.translate!(translation)
end
headings.root.ordered.each do |heading|
heading.translate!(translation)
end
end
# Utility method to duplicate attachments
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment