diff --git a/.discourse-compatibility b/.discourse-compatibility index 9b3f6f37..44e5580a 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,3 +1,4 @@ +< 3.5.0.beta5-dev: 5c44f829ef82ded3416b0cddc521e9e6d62ed534 < 3.5.0.beta4-dev: 14ca3c07efa0a80712a4cbb8ca455c32a727adec < 3.5.0.beta2-dev: 5f24835801fdc7cb98e1bcf42d2ab2e49e609921 < 3.5.0.beta1-dev: 7d411e458bdd449f8aead2bc07cedeb00b856798 diff --git a/app/services/discourse_translator/topic_translator.rb b/app/services/discourse_translator/topic_translator.rb index 3df5f547..5ff3f8a0 100644 --- a/app/services/discourse_translator/topic_translator.rb +++ b/app/services/discourse_translator/topic_translator.rb @@ -10,11 +10,14 @@ def self.translate(topic, target_locale = I18n.locale) translator = DiscourseTranslator::Provider::TranslatorProvider.get translated_title = translator.translate_topic!(topic, target_locale_sym) + translated_excerpt = translator.translate_text!(topic.excerpt, target_locale_sym) + localization = TopicLocalization.find_or_initialize_by(topic_id: topic.id, locale: target_locale_sym.to_s) localization.title = translated_title localization.fancy_title = Topic.fancy_title(translated_title) + localization.excerpt = translated_excerpt localization.localizer_user_id = Discourse.system_user.id localization.save! localization diff --git a/spec/services/topic_translator_spec.rb b/spec/services/topic_translator_spec.rb index 3bae3e37..8ac55ca2 100644 --- a/spec/services/topic_translator_spec.rb +++ b/spec/services/topic_translator_spec.rb @@ -2,15 +2,23 @@ describe DiscourseTranslator::TopicTranslator do describe ".translate" do - fab!(:topic) { Fabricate(:topic, title: "this is a cat topic :)") } + fab!(:topic) do + Fabricate( + :topic, + title: "this is a cat topic :)", + excerpt: "cats are great. how many do you have?", + ) + end let(:translator) { mock } let(:translated_title) { "これは猫の話題です :)" } + let(:translated_excerpt) { "猫は素晴らしいですね。何匹飼っていますか?" } let(:fancy_title) { "これは猫の話題です :slight_smile:" } let(:target_locale) { "ja" } before do DiscourseTranslator::Provider::TranslatorProvider.stubs(:get).returns(translator) translator.stubs(:translate_topic!).with(topic, :ja).returns(translated_title) + translator.stubs(:translate_text!).with(topic.excerpt, :ja).returns(translated_excerpt) end it "returns nil if topic is blank" do @@ -30,12 +38,14 @@ it "translates with topic and locale" do translator.expects(:translate_topic!).with(topic, :ja).returns(translated_title) + translator.expects(:translate_text!).with(topic.excerpt, :ja).returns(translated_title) described_class.translate(topic, "ja") end it "normalizes dashes to underscores and symbol type for locale" do translator.expects(:translate_topic!).with(topic, :zh_CN).returns("这是一个猫主题 :)") + translator.expects(:translate_text!).with(topic.excerpt, :zh_CN).returns("这是一个猫主题 :)") described_class.translate(topic, "zh-CN") end @@ -48,6 +58,7 @@ topic_id: topic.id, locale: target_locale, title: translated_title, + excerpt: translated_excerpt, fancy_title: fancy_title, localizer_user_id: Discourse.system_user.id, ) @@ -61,6 +72,7 @@ topic:, locale: "ja", title: "old title", + excerpt: "old excerpt", fancy_title: "old_fancy_title", ) expect { @@ -68,10 +80,12 @@ id: localization.id, title: translated_title, fancy_title: fancy_title, + excerpt: translated_excerpt, ) expect(localization.reload).to have_attributes( title: translated_title, fancy_title: fancy_title, + excerpt: translated_excerpt, ) }.to_not change { TopicLocalization.count } end