Use more generic locale as fallback for rules (#34756)

This commit is contained in:
Claire 2025-05-21 18:22:54 +02:00 committed by GitHub
parent 97b9e8849d
commit 6ab96ba647
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 4 deletions

View file

@ -42,6 +42,6 @@ class Rule < ApplicationRecord
def translation_for(locale)
@cached_translations ||= {}
@cached_translations[locale] ||= translations.find_by(language: locale) || RuleTranslation.new(language: locale, text: text, hint: hint)
@cached_translations[locale] ||= translations.where(language: [locale, locale.to_s.split('-').first]).order('length(language) desc').first || RuleTranslation.new(language: locale, text: text, hint: hint)
end
end