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
2 changes: 2 additions & 0 deletions app/jobs/scheduled/posts_locale_detection_backfill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def execute(args)
posts.each do |post|
begin
DiscourseTranslator::PostLocaleDetector.detect_locale(post)
rescue FinalDestination::SSRFDetector::LookupFailedError
# do nothing, there are too many sporadic lookup failures
rescue => e
Rails.logger.error(
"Discourse Translator: Failed to detect post #{post.id}'s locale: #{e.message}",
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/scheduled/topics_locale_detection_backfill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def execute(args)
topics.each do |topic|
begin
DiscourseTranslator::TopicLocaleDetector.detect_locale(topic)
rescue FinalDestination::SSRFDetector::LookupFailedError
# do nothing, there are too many sporadic lookup failures
rescue => e
Rails.logger.error(
"Discourse Translator: Failed to detect topic #{topic.id}'s locale: #{e.message}",
Expand Down
2 changes: 1 addition & 1 deletion app/services/discourse_translator/topic_locale_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.detect_locale(topic)
translator = DiscourseTranslator::Provider::TranslatorProvider.get
detected_locale = translator.detect!(topic)
locale = LocaleNormalizer.normalize_to_i18n(detected_locale)
topic.update!(locale:)
topic.update_column(:locale, locale)
locale
end
end
Expand Down
11 changes: 11 additions & 0 deletions spec/services/topic_locale_detector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,16 @@
nil,
).to("zh_CN")
end

it "bypasses validations when updating locale" do
topic.update_column(:title, "A")
SiteSetting.min_topic_title_length = 15
SiteSetting.max_topic_title_length = 16

translator.stubs(:detect!).with(topic).returns("zh")

described_class.detect_locale(topic)
expect(topic.reload.locale).to eq("zh_CN")
end
end
end
Loading