diff --git a/app/controllers/admin/communication/websites/application_controller.rb b/app/controllers/admin/communication/websites/application_controller.rb index 5fccac61b9fd497a325dd02fef528e6120f9e949..4d6e7c31016727cf5d01ca96489099ccd628e3b7 100644 --- a/app/controllers/admin/communication/websites/application_controller.rb +++ b/app/controllers/admin/communication/websites/application_controller.rb @@ -7,11 +7,7 @@ class Admin::Communication::Websites::ApplicationController < Admin::Communicati protected def current_website_language - @current_website_language ||= begin - language = @website.languages.find_by(iso_code: params[:lang]) - language ||= @website.default_language - language - end + @current_website_language ||= @website.best_language_for(params[:lang]) end helper_method :current_website_language diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 9242fb535b380af38d859771fdcabe8bc1f4dc61..a750fc64799da4e044e784fcbb69cdc2d4238fff 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -98,6 +98,12 @@ class Communication::Website < ApplicationRecord dependencies end + def best_language_for(iso_code) + # We look for the language by the ISO code in the websites languages. + # If not found, we fallback to the default language. + languages.find_by(iso_code: iso_code) || default_language + end + protected def languages_must_include_default_language