Skip to content

Commit bdaa1dd

Browse files
committed
DEV: Send fancy_titles instead of titles for translation
1 parent c1aa718 commit bdaa1dd

File tree

9 files changed

+14
-11
lines changed

9 files changed

+14
-11
lines changed

app/jobs/scheduled/automatic_translation_backfill.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def translate_records(type, record_ids)
100100
def process_batch
101101
models_translated = [Post, Topic].size
102102
translations_per_model = [translations_per_run / models_translated, 1].max
103-
topic_ids = fetch_untranslated_model_ids(Topic, "title", translations_per_model)
103+
topic_ids = fetch_untranslated_model_ids(Topic, "fancy_title", translations_per_model)
104104
translations_per_model = translations_per_run - topic_ids.size
105105
post_ids = fetch_untranslated_model_ids(Post, "cooked", translations_per_model)
106106
return if topic_ids.empty? && post_ids.empty?

app/services/discourse_translator/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def self.get_text(translatable)
105105
when "Post"
106106
translatable.cooked
107107
when "Topic"
108-
translatable.title
108+
translatable.fancy_title
109109
end
110110
end
111111

lib/discourse_translator/topic_extension.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module DiscourseTranslator
44
module TopicExtension
55
extend ActiveSupport::Concern
6-
prepended { before_update :clear_translations, if: :title_changed? }
6+
prepended { before_update :clear_translations, if: :fancy_title_changed? }
77
include Translatable
88
end
99
end

spec/models/post_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
describe "translatable" do
1212
fab!(:post)
1313

14-
it "should reset translation data when post title has been updated" do
14+
it "should reset translation data when post raw has been updated" do
1515
Fabricate(:post_translation, post:)
1616
Fabricate(:post_locale, post:)
1717
post.update!(raw: "this is an updated title")

spec/models/topic_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
before { SiteSetting.translator_enabled = true }
1010

11-
it "should reset translation data when topic title has been updated" do
11+
it "should reset translation data when topic fancy_title has been updated" do
1212
Fabricate(:topic_translation, topic:)
1313
Fabricate(:topic_locale, topic:)
14-
topic.update!(title: "this is an updated title")
14+
topic.update!(fancy_title: "this is an updated title")
1515

1616
expect(DiscourseTranslator::TopicLocale.where(topic:)).to be_empty
1717
expect(DiscourseTranslator::TopicLocale.find_by(topic:)).to be_nil

spec/serializers/basic_topic_serializer_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
let!(:jap_title) { "フス・ロ・ダ・ア" }
1818

1919
before do
20-
topic.title = original_title
20+
topic.title = "x"
21+
topic.fancy_title = original_title
2122
SiteSetting.experimental_topic_translation = true
2223
I18n.locale = "ja"
2324
end

spec/serializers/topic_view_serializer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
let!(:jap_title) { "フス・ロ・ダ・ア" }
4141

4242
before do
43-
topic.title = original_title
43+
topic.fancy_title = original_title
4444
SiteSetting.experimental_topic_translation = true
4545
I18n.locale = "ja"
4646
end
@@ -76,7 +76,7 @@ def serialize_topic(guardian_user: user, params: {})
7676
expect(serialize_topic.fancy_title).to eq(topic.fancy_title)
7777
end
7878

79-
it "returns translated title in fancy_title when translation exists for current locale" do
79+
it "returns translated fancy title in fancy_title when translation exists for current locale" do
8080
topic.set_translation("ja", jap_title)
8181
expect(serialize_topic.fancy_title).to eq(jap_title)
8282
end

spec/services/google_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
end
101101

102102
describe ".translate_supported?" do
103-
let(:topic) { Fabricate(:topic, title: "This title is in english") }
103+
let(:topic) { Fabricate(:topic, fancy_title: "This title is in english") }
104104
it "should equate source language to target" do
105105
source = "en"
106106
target = "fr"

spec/system/full_page_translation_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
fab!(:site_local_user) { Fabricate(:user, locale: "en") }
66
fab!(:author) { Fabricate(:user) }
77

8-
fab!(:topic) { Fabricate(:topic, title: "Life strategies from The Art of War", user: author) }
8+
fab!(:topic) do
9+
Fabricate(:topic, fancy_title: "Life strategies from The Art of War", user: author)
10+
end
911
fab!(:post_1) do
1012
Fabricate(:post, topic: topic, raw: "The masterpiece isn’t just about military strategy")
1113
end

0 commit comments

Comments
 (0)