Skip to content

Commit 051adea

Browse files
committed
no translate same locale
1 parent 3b054c0 commit 051adea

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

app/services/discourse_translator/post_translator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module DiscourseTranslator
44
class PostTranslator
55
def self.translate(post, target_locale = I18n.locale)
6-
return if post.blank? || target_locale.blank?
6+
return if post.blank? || target_locale.blank? || post.locale == target_locale.to_s
77

88
target_locale_sym = target_locale.to_s.sub("-", "_").to_sym
99

spec/services/post_translator_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
expect(described_class.translate(post, "")).to eq(nil)
2323
end
2424

25+
it "returns nil if target_locale is same as post locale" do
26+
post.locale = "en"
27+
28+
expect(described_class.translate(post, "en")).to eq(nil)
29+
end
30+
2531
it "translates with post and locale" do
2632
translator.expects(:translate_post!).with(post, :ja).returns(translated_raw)
2733

0 commit comments

Comments
 (0)