Skip to content

Commit 0cb4015

Browse files
committed
Do not load translation for posts already in correct locale
1 parent 9c6a7c4 commit 0cb4015

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

plugin.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ module ::DiscourseTranslator
4444

4545
register_modifier(:basic_post_serializer_cooked) do |cooked, serializer|
4646
if !SiteSetting.experimental_topic_translation ||
47-
serializer.scope.request.params["show"] == "original"
47+
serializer.scope.request.params["show"] == "original" ||
48+
serializer.object.detected_locale == I18n.locale.to_s.gsub("_", "-")
4849
cooked
4950
else
5051
translation = serializer.object.translation_for(I18n.locale)

spec/serializers/post_serializer_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ def serialize_post(guardian_user: user, params: {})
106106
expect(serialize_post(params: { "show" => "derp" }).cooked).to eq("こんにちは")
107107
end
108108

109+
it "does not return translated_cooked when post is already in correct locale" do
110+
I18n.locale = "ja"
111+
post.set_detected_locale("ja")
112+
post.set_translation("ja", "こんにちは")
113+
114+
expect(serialize_post.cooked).to eq(post.cooked)
115+
end
116+
109117
it "returns translated content based on locale" do
110118
I18n.locale = "ja"
111119
post.set_translation("ja", "こんにちは")

0 commit comments

Comments
 (0)