Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/services/discourse_translator/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/services/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Loading