From d728fa99919197dcd539206340f1f3668db208cc Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 18 Oct 2024 12:21:25 +0200 Subject: [PATCH] Fix follow recommendation moderation page default language when using regional variant (#32580) --- app/models/follow_recommendation_filter.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/follow_recommendation_filter.rb b/app/models/follow_recommendation_filter.rb index 62a02eba5a..f3b0fd319b 100644 --- a/app/models/follow_recommendation_filter.rb +++ b/app/models/follow_recommendation_filter.rb @@ -11,7 +11,7 @@ class FollowRecommendationFilter attr_reader :params, :language def initialize(params) - @language = params.delete('language') || I18n.locale + @language = usable_language(params.delete('language') || I18n.locale) @params = params end @@ -22,4 +22,15 @@ class FollowRecommendationFilter Account.includes(:account_stat).joins(:follow_recommendation).merge(FollowRecommendation.localized(@language).order(rank: :desc)) end end + + private + + def usable_language(locale) + return locale if Trends.available_locales.include?(locale) + + locale = locale.to_s.split(/[_-]/).first + return locale if Trends.available_locales.include?(locale) + + nil + end end