Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Admin
Commits
4ee7914a
Unverified
Commit
4ee7914a
authored
2 years ago
by
Sébastien Gaya
Browse files
Options
Downloads
Patches
Plain Diff
cc
parent
3c0bc2d0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/communication/website/menu.rb
+16
-19
16 additions, 19 deletions
app/models/communication/website/menu.rb
app/models/concerns/with_translations.rb
+7
-6
7 additions, 6 deletions
app/models/concerns/with_translations.rb
with
23 additions
and
25 deletions
app/models/communication/website/menu.rb
+
16
−
19
View file @
4ee7914a
...
...
@@ -62,28 +62,25 @@ class Communication::Website::Menu < ApplicationRecord
item_translation
.
menu
=
menu_translation
item_translation
.
parent
=
parent_translation
case
item_translation
.
kind
when
'blank'
,
'url'
# Nothing to do
when
'program'
,
'diploma'
,
'volume'
,
'paper'
# TODO: Translate Education & Research Models
when
'page'
,
'category'
,
'post'
translated_about
=
item
.
about
.
translation_for
(
menu_translation
.
language
)
if
translated_about
.
present?
item_translation
.
about
=
translated_about
elsif
item
.
children
.
any?
# Convert to a blank menu item to translate children correctly
item_translation
.
kind
=
'blank'
item_translation
.
about
=
nil
else
# Skip menu item if no translation and no children to translate
return
# TODO : I18n
# For now, only pages, posts, categories are handled.
# We need to translate programs, diplomas, volumes and papers
set_item_translation_attributes
(
item_translation
,
item
,
menu_translation
)
# If no translation and no children to translate, translation won't be save, as about is nil and kind requires one.
if
item_translation
.
save
item
.
children
.
ordered
.
each
do
|
child
|
translate_menu_item!
(
child
,
menu_translation
,
item_translation
)
end
end
end
item_translation
.
save
item
.
children
.
ordered
.
each
do
|
child
|
translate_menu_item!
(
child
,
menu_translation
,
item_translation
)
def
set_item_translation_attributes
(
item_translation
,
item
,
menu_translation
)
return
unless
item
.
about
.
present?
&&
item
.
about
.
respond_to?
(
:translation_for
)
# Search for the target translation based on the given language.
item_translation
.
about
=
item
.
about
.
translation_for
(
menu_translation
.
language
)
# If no target translation found, convert to a blank menu item if item has children.
item_translation
.
kind
=
'blank'
if
item_translation
.
about
.
nil?
&&
item
.
children
.
any?
end
end
end
This diff is collapsed.
Click to expand it.
app/models/concerns/with_translations.rb
+
7
−
6
View file @
4ee7914a
...
...
@@ -50,12 +50,6 @@ module WithTranslations
def
translate!
(
language
)
translation
=
self
.
dup
# Translate parent if needed
if
respond_to?
(
:parent_id
)
&&
parent_id
.
present?
parent_translation
=
parent
.
find_or_translate!
(
language
)
translation
.
parent_id
=
parent_translation
&
.
id
end
# Inherits from original_id or set it to itself
translation
.
assign_attributes
(
original_id:
original_object
.
id
,
...
...
@@ -64,6 +58,8 @@ module WithTranslations
# Handle publication
translation
.
published
=
false
if
respond_to?
(
:published
)
# Translate parent if needed
translation
.
parent_id
=
translate_parent!
(
language
)
&
.
id
if
respond_to?
(
:parent_id
)
# Handle featured image if object has one
translate_attachment
(
translation
,
:featured_image
)
if
respond_to?
(
:featured_image
)
&&
featured_image
.
attached?
translation
.
save
...
...
@@ -76,6 +72,11 @@ module WithTranslations
protected
def
translate_parent!
(
language
)
return
nil
if
parent_id
.
nil?
parent
.
find_or_translate!
(
language
)
end
def
translate_blocks!
(
translation
)
blocks
.
ordered
.
each
do
|
block
|
block
.
translate!
(
translation
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment