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.
This commit is contained in:
Gerhard Schlager 2022-08-02 20:49:28 +02:00 committed by GitHub
parent 5ac4e82540
commit f3b2ee8e1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -23,7 +23,9 @@ class TopicEmbed < ActiveRecord::Base
end
def self.imported_from_html(url)
"\n<hr>\n<small>#{I18n.t('embed.imported_from', link: "<a href='#{url}'>#{url}</a>")}</small>\n"
I18n.with_locale(SiteSetting.default_locale) do
"\n<hr>\n<small>#{I18n.t('embed.imported_from', link: "<a href='#{url}'>#{url}</a>")}</small>\n"
end
end
# Import an article from a source (RSS/Atom/Other)

View File

@ -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