From f3b2ee8e1b73d7f79bd8a573be45d3ffcb74c415 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 2 Aug 2022 20:49:28 +0200 Subject: [PATCH] FIX: Use default locale for footer of embedded topics (#17760) The content from the remote site and the footer get cached for 10 minutes, so Discourse should use the default locale instead of the user locale for the footer. Otherwise Discourse might cache the message in a different language. --- app/models/topic_embed.rb | 4 +++- spec/models/topic_embed_spec.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rb index 18e154e977..1d5676e5d9 100644 --- a/app/models/topic_embed.rb +++ b/app/models/topic_embed.rb @@ -23,7 +23,9 @@ class TopicEmbed < ActiveRecord::Base end def self.imported_from_html(url) - "\n
\n#{I18n.t('embed.imported_from', link: "#{url}")}\n" + I18n.with_locale(SiteSetting.default_locale) do + "\n
\n#{I18n.t('embed.imported_from', link: "#{url}")}\n" + end end # Import an article from a source (RSS/Atom/Other) diff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rb index a63c9eaef4..a112a126ff 100644 --- a/spec/models/topic_embed_spec.rb +++ b/spec/models/topic_embed_spec.rb @@ -399,4 +399,18 @@ RSpec.describe TopicEmbed do end end + describe ".imported_from_html" do + after { I18n.reload! } + + it "uses the default site locale for the 'imported_from' footer" do + TranslationOverride.upsert!("en", "embed.imported_from", "English translation of embed.imported_from with %{link}") + TranslationOverride.upsert!("de", "embed.imported_from", "German translation of embed.imported_from with %{link}") + + I18n.locale = :en + expected_html = TopicEmbed.imported_from_html("some_url") + + I18n.locale = :de + expect(TopicEmbed.imported_from_html("some_url")).to eq(expected_html) + end + end end