From a0377c5b11431dbd67edd1ed74efb7326dcd7812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Fri, 27 Jan 2023 10:33:00 +0100 Subject: [PATCH] i18n permalink --- app/models/communication/website/menu.rb | 5 +---- app/models/communication/website/permalink.rb | 12 +++++++----- .../communication/website/permalink/administrator.rb | 2 +- app/models/communication/website/permalink/author.rb | 2 +- .../communication/website/permalink/category.rb | 4 ++-- .../communication/website/permalink/diploma.rb | 4 ++-- .../communication/website/permalink/organization.rb | 4 ++-- app/models/communication/website/permalink/paper.rb | 2 +- app/models/communication/website/permalink/person.rb | 2 +- app/models/communication/website/permalink/post.rb | 4 ++-- .../communication/website/permalink/program.rb | 2 +- .../communication/website/permalink/researcher.rb | 2 +- .../communication/website/permalink/teacher.rb | 2 +- app/models/communication/website/permalink/volume.rb | 2 +- .../configs/default_languages/static.html.erb | 4 ++++ .../configs/default_permalinks/static.html.erb | 5 +---- 16 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app/models/communication/website/menu.rb b/app/models/communication/website/menu.rb index 29bb82bfa..2e46762f9 100644 --- a/app/models/communication/website/menu.rb +++ b/app/models/communication/website/menu.rb @@ -46,10 +46,7 @@ class Communication::Website::Menu < ApplicationRecord end def git_path(website) - path = "data/menus/" - # TODO I18n : Right now, we continue to send only a master version - # path += "#{website.default_language.iso_code}/" if website.languages.any? - "#{path}#{identifier}.yml" + "data/menus/#{language.iso_code}/#{identifier}.yml" end def template_static diff --git a/app/models/communication/website/permalink.rb b/app/models/communication/website/permalink.rb index 276d8df83..88f821fd2 100644 --- a/app/models/communication/website/permalink.rb +++ b/app/models/communication/website/permalink.rb @@ -54,9 +54,9 @@ class Communication::Website::Permalink < ApplicationRecord scope :current, -> { where(is_current: true) } scope :not_current, -> { where(is_current: false) } - def self.config_in_website(website) + def self.config_in_website(website, language) required_kinds_in_website(website).map { |permalink_class| - [permalink_class.static_config_key, permalink_class.pattern_in_website(website)] + [permalink_class.static_config_key, permalink_class.pattern_in_website(website, language)] }.to_h end @@ -84,12 +84,13 @@ class Communication::Website::Permalink < ApplicationRecord MAPPING.keys.include?(lookup_key) end - def self.pattern_in_website(website) + def self.pattern_in_website(website, language) raise NotImplementedError end def pattern - self.class.pattern_in_website(website) + language = about.respond_to?(:language) ? about.language : website.default_language + self.class.pattern_in_website(website, language) end def computed_path @@ -122,8 +123,9 @@ class Communication::Website::Permalink < ApplicationRecord # Can be overwritten (Page for example) def published_path # TODO I18n doit prendre la langue du about + language = about.respond_to?(:language) ? about.language : website.default_language p = "" - p += "/#{website.default_language.iso_code}" if website.languages.many? + p += "/#{language.iso_code}" if website.languages.many? p += pattern substitutions.each do |key, value| p.gsub! ":#{key}", "#{value}" diff --git a/app/models/communication/website/permalink/administrator.rb b/app/models/communication/website/permalink/administrator.rb index 9a95d44d5..9a3034007 100644 --- a/app/models/communication/website/permalink/administrator.rb +++ b/app/models/communication/website/permalink/administrator.rb @@ -33,7 +33,7 @@ class Communication::Website::Permalink::Administrator < Communication::Website: end # /equipe/:slug/roles/ - def self.pattern_in_website(website) + def self.pattern_in_website(website, language) "/#{website.special_page(Communication::Website::Page::Person).slug_with_ancestors}/:slug/roles/" end end diff --git a/app/models/communication/website/permalink/author.rb b/app/models/communication/website/permalink/author.rb index 8c0b639b4..7cd0e41d3 100644 --- a/app/models/communication/website/permalink/author.rb +++ b/app/models/communication/website/permalink/author.rb @@ -34,7 +34,7 @@ class Communication::Website::Permalink::Author < Communication::Website::Permal end # /equipe/:slug/actualites/ - def self.pattern_in_website(website) + def self.pattern_in_website(website, language) "/#{website.special_page(Communication::Website::Page::Person).slug_with_ancestors}/:slug/#{website.special_page(Communication::Website::Page::CommunicationPost).slug}/" end end diff --git a/app/models/communication/website/permalink/category.rb b/app/models/communication/website/permalink/category.rb index 852dbfb3f..b4ae97e26 100644 --- a/app/models/communication/website/permalink/category.rb +++ b/app/models/communication/website/permalink/category.rb @@ -33,8 +33,8 @@ class Communication::Website::Permalink::Category < Communication::Website::Perm end # /actualites/:slug/ - def self.pattern_in_website(website) - "/#{website.special_page(Communication::Website::Page::CommunicationPost).slug_with_ancestors}/:slug/" + def self.pattern_in_website(website, language) + "/#{website.special_page(Communication::Website::Page::CommunicationPost, language: language).slug_with_ancestors}/:slug/" end protected diff --git a/app/models/communication/website/permalink/diploma.rb b/app/models/communication/website/permalink/diploma.rb index 64e9f2a9e..8b46f82a3 100644 --- a/app/models/communication/website/permalink/diploma.rb +++ b/app/models/communication/website/permalink/diploma.rb @@ -33,7 +33,7 @@ class Communication::Website::Permalink::Diploma < Communication::Website::Perma end # /diplomes/:slug/ - def self.pattern_in_website(website) - "/#{website.special_page(Communication::Website::Page::EducationDiploma).slug_with_ancestors}/:slug/" + def self.pattern_in_website(website, language) + "/#{website.special_page(Communication::Website::Page::EducationDiploma, language: language).slug_with_ancestors}/:slug/" end end diff --git a/app/models/communication/website/permalink/organization.rb b/app/models/communication/website/permalink/organization.rb index c3d3e8ec7..6c203f9e8 100644 --- a/app/models/communication/website/permalink/organization.rb +++ b/app/models/communication/website/permalink/organization.rb @@ -33,7 +33,7 @@ class Communication::Website::Permalink::Organization < Communication::Website:: end # /organisations/:slug/ - def self.pattern_in_website(website) - "/#{website.special_page(Communication::Website::Page::Organization).slug_with_ancestors}/:slug/" + def self.pattern_in_website(website, language) + "/#{website.special_page(Communication::Website::Page::Organization, language: language).slug_with_ancestors}/:slug/" end end diff --git a/app/models/communication/website/permalink/paper.rb b/app/models/communication/website/permalink/paper.rb index 430fee83b..25e7fd2d1 100644 --- a/app/models/communication/website/permalink/paper.rb +++ b/app/models/communication/website/permalink/paper.rb @@ -33,7 +33,7 @@ class Communication::Website::Permalink::Paper < Communication::Website::Permali end # /papiers/:slug/ - def self.pattern_in_website(website) + def self.pattern_in_website(website, language) "/#{website.special_page(Communication::Website::Page::ResearchPaper).slug_with_ancestors}/:year-:month-:day-:slug/" end diff --git a/app/models/communication/website/permalink/person.rb b/app/models/communication/website/permalink/person.rb index 760c5d9ce..ecd620e56 100644 --- a/app/models/communication/website/permalink/person.rb +++ b/app/models/communication/website/permalink/person.rb @@ -33,7 +33,7 @@ class Communication::Website::Permalink::Person < Communication::Website::Permal end # /equipe/:slug/ - def self.pattern_in_website(website) + def self.pattern_in_website(website, language) "/#{website.special_page(Communication::Website::Page::Person).slug_with_ancestors}/:slug/" end end diff --git a/app/models/communication/website/permalink/post.rb b/app/models/communication/website/permalink/post.rb index 8525ea0e6..b12ce72ba 100644 --- a/app/models/communication/website/permalink/post.rb +++ b/app/models/communication/website/permalink/post.rb @@ -33,8 +33,8 @@ class Communication::Website::Permalink::Post < Communication::Website::Permalin end # /actualites/2022-10-21-un-article/ - def self.pattern_in_website(website) - "/#{website.special_page(Communication::Website::Page::CommunicationPost).slug_with_ancestors}/:year-:month-:day-:slug/" + def self.pattern_in_website(website, language) + "/#{website.special_page(Communication::Website::Page::CommunicationPost, language: language).slug_with_ancestors}/:year-:month-:day-:slug/" end protected diff --git a/app/models/communication/website/permalink/program.rb b/app/models/communication/website/permalink/program.rb index 8c1c0e02d..69b8da1fb 100644 --- a/app/models/communication/website/permalink/program.rb +++ b/app/models/communication/website/permalink/program.rb @@ -33,7 +33,7 @@ class Communication::Website::Permalink::Program < Communication::Website::Perma end # /formations/:slug/ - def self.pattern_in_website(website) + def self.pattern_in_website(website, language) "/#{website.special_page(Communication::Website::Page::EducationProgram).slug_with_ancestors}/:slug/" end end diff --git a/app/models/communication/website/permalink/researcher.rb b/app/models/communication/website/permalink/researcher.rb index d9a85ca2e..59d8dd7a8 100644 --- a/app/models/communication/website/permalink/researcher.rb +++ b/app/models/communication/website/permalink/researcher.rb @@ -34,7 +34,7 @@ class Communication::Website::Permalink::Researcher < Communication::Website::Pe # /equipe/:slug/papers/ # FIXME - def self.pattern_in_website(website) + def self.pattern_in_website(website, language) "/#{website.special_page(Communication::Website::Page::Person).slug_with_ancestors}/:slug/papers/" end end diff --git a/app/models/communication/website/permalink/teacher.rb b/app/models/communication/website/permalink/teacher.rb index 6a75142aa..a952bbfdf 100644 --- a/app/models/communication/website/permalink/teacher.rb +++ b/app/models/communication/website/permalink/teacher.rb @@ -34,7 +34,7 @@ class Communication::Website::Permalink::Teacher < Communication::Website::Perma # /equipe/:slug/programs/ # FIXME - def self.pattern_in_website(website) + def self.pattern_in_website(website, language) "/#{website.special_page(Communication::Website::Page::Person).slug_with_ancestors}/:slug/programs/" end end diff --git a/app/models/communication/website/permalink/volume.rb b/app/models/communication/website/permalink/volume.rb index 96774e65d..81b2aab5c 100644 --- a/app/models/communication/website/permalink/volume.rb +++ b/app/models/communication/website/permalink/volume.rb @@ -33,7 +33,7 @@ class Communication::Website::Permalink::Volume < Communication::Website::Permal end # /volumes/:slug/ - def self.pattern_in_website(website) + def self.pattern_in_website(website, language) "/#{website.special_page(Communication::Website::Page::ResearchVolume).slug_with_ancestors}/:year-:slug/" end diff --git a/app/views/admin/communication/websites/configs/default_languages/static.html.erb b/app/views/admin/communication/websites/configs/default_languages/static.html.erb index 8657a91ea..f221d6658 100644 --- a/app/views/admin/communication/websites/configs/default_languages/static.html.erb +++ b/app/views/admin/communication/websites/configs/default_languages/static.html.erb @@ -6,4 +6,8 @@ contentDir: content/<%= language.iso_code %> languageCode: <%= language.iso_code %> languageName: <%= language.name %> + permalinks: + <% Communication::Website::Permalink.config_in_website(@website, language).each do |key, value| %> + <%= key %>: <%= value %> + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/admin/communication/websites/configs/default_permalinks/static.html.erb b/app/views/admin/communication/websites/configs/default_permalinks/static.html.erb index 27ed0728f..ec8135a85 100644 --- a/app/views/admin/communication/websites/configs/default_permalinks/static.html.erb +++ b/app/views/admin/communication/websites/configs/default_permalinks/static.html.erb @@ -1,5 +1,2 @@ # DO NOT EDIT THIS FILE BY HAND - IT WILL BE OVERWRITTEN BY OSUNY - -<% Communication::Website::Permalink.config_in_website(@website).each do |key, value| %> -<%= key %>: <%= value %> -<% end %> \ No newline at end of file +# Moved to languages.yml -- GitLab