diff --git a/app/services/discourse_translator/base.rb b/app/services/discourse_translator/base.rb index 8a1eaff3..187f8b38 100644 --- a/app/services/discourse_translator/base.rb +++ b/app/services/discourse_translator/base.rb @@ -88,7 +88,9 @@ def self.get_detected_locale(translatable) end def self.save_detected_locale(translatable) - detected_locale = yield + # sometimes we may have a user post that is just an emoji + # in that case, we will just indicate the post is in the default locale + detected_locale = yield.presence || SiteSetting.default_locale translatable.set_detected_locale(detected_locale) detected_locale diff --git a/spec/services/base_spec.rb b/spec/services/base_spec.rb index 0f224ddd..22785d93 100644 --- a/spec/services/base_spec.rb +++ b/spec/services/base_spec.rb @@ -115,6 +115,14 @@ class EmptyTranslator < DiscourseTranslator::Base expect(TestTranslator.detect(post)).to eq("en") end + it "saves the site default locale when detection is empty" do + SiteSetting.default_locale = "ja" + + TestTranslator.save_detected_locale(post) { "" } + + expect(post.detected_locale).to eq("ja") + end + it "performs detection if no cached result" do TestTranslator.expects(:detect!).with(post).returns("es")