Skip to content

Commit bff13db

Browse files
authored
UX: Prevent users from wondering why backfilling is not happening (#233)
Users are allowed to set `automatic translation target languages`, but the automatic translation depends on `automatic_translation_backfill_maximum_translations_per_hour`, and the latter is a hidden site setting defaulting to zero. It is not obvious that these settings are related. This commit ensures users are informed that this needs to be set as well.
1 parent 95a5cfe commit bff13db

File tree

7 files changed

+58
-5
lines changed

7 files changed

+58
-5
lines changed

config/locales/server.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ en:
2020
experimental_anon_language_switcher: "Enable experimental language switcher for anonymous users. This will allow anonymous users to switch between translated versions of Discourse and user-contributed content in topics."
2121
errors:
2222
set_locale_cookie_requirements: "The experimental language switcher for anonymous users requires the `set locale from cookie` site setting to be enabled."
23+
needs_nonzero_backfill: "Automatic language translation requires the 'automatic_translation_backfill_maximum_translations_per_hour' hidden setting to be a non-zero value. Please approach your site administrator to increase this limit."
2324
experimental_inline_translation: "Enable experimental inline translation feature. This replaces existing parallel translation, allowing site visitors with a non-default locale to view content in their language."
2425
automatic_translation_target_languages: "The languages to automatically translate user content (posts, topics) to. If empty, no languages will be automatically translated."
2526
translator:

config/settings.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ discourse_translator:
1616
validator: "DiscourseTranslator::TranslatorSelectionValidator"
1717
automatic_translation_target_languages:
1818
default: ""
19+
client: true
1920
type: list
2021
list_type: named
21-
choices: "DiscourseTranslator::TranslatableLanguagesSetting.values"
2222
allow_any: false
23+
choices: "DiscourseTranslator::TranslatableLanguagesSetting.values"
24+
validator: "DiscourseTranslator::TranslatableLanguagesValidator"
2325
automatic_translation_backfill_maximum_translations_per_hour:
2426
default: 0
2527
client: false
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module DiscourseTranslator
4+
class TranslatableLanguagesValidator
5+
def initialize(opts = {})
6+
@opts = opts
7+
end
8+
9+
def valid_value?(val)
10+
return true if val.blank?
11+
12+
SiteSetting.automatic_translation_backfill_maximum_translations_per_hour > 0
13+
end
14+
15+
def error_message
16+
I18n.t("site_settings.errors.needs_nonzero_backfill")
17+
end
18+
end
19+
end

spec/jobs/automatic_translation_backfill_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,23 @@ def expect_google_translate(text)
5959
end
6060

6161
it "does not backfill if backfill limit is set to 0" do
62+
SiteSetting.automatic_translation_backfill_maximum_translations_per_hour = 1
6263
SiteSetting.automatic_translation_target_languages = "de"
6364
SiteSetting.automatic_translation_backfill_maximum_translations_per_hour = 0
6465
expect_any_instance_of(Jobs::AutomaticTranslationBackfill).not_to receive(:process_batch)
6566
end
6667

6768
it "does not backfill if backfill lock is not secure" do
68-
SiteSetting.automatic_translation_target_languages = "de"
6969
SiteSetting.automatic_translation_backfill_maximum_translations_per_hour = 1
70+
SiteSetting.automatic_translation_target_languages = "de"
7071
Discourse.redis.set("discourse_translator_backfill_lock", "1")
7172
expect_any_instance_of(Jobs::AutomaticTranslationBackfill).not_to receive(:translate_records)
7273
end
7374

7475
describe "with two locales ['de', 'es']" do
7576
before do
76-
SiteSetting.automatic_translation_target_languages = "de|es"
7777
SiteSetting.automatic_translation_backfill_maximum_translations_per_hour = 100
78+
SiteSetting.automatic_translation_target_languages = "de|es"
7879
expect_google_check_language
7980
end
8081

@@ -107,8 +108,8 @@ def expect_google_translate(text)
107108

108109
describe "with just one locale ['de']" do
109110
before do
110-
SiteSetting.automatic_translation_target_languages = "de"
111111
SiteSetting.automatic_translation_backfill_maximum_translations_per_hour = 5 * 12
112+
SiteSetting.automatic_translation_target_languages = "de"
112113
expect_google_check_language
113114
end
114115

spec/jobs/translate_translatable_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
before do
99
SiteSetting.translator_enabled = true
1010
SiteSetting.translator_provider = "Google"
11+
SiteSetting.automatic_translation_backfill_maximum_translations_per_hour = 100
1112
SiteSetting.automatic_translation_target_languages = "es|fr"
1213
allow(DiscourseTranslator::Google).to receive(:translate)
1314
end

spec/models/post_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
fab!(:user)
140140

141141
it "enqueues translate_translatable job when post cooked" do
142+
SiteSetting.automatic_translation_backfill_maximum_translations_per_hour = 100
142143
SiteSetting.automatic_translation_target_languages = "es"
143144
post = Fabricate(:post, user: user)
144145
CookedPostProcessor.new(post).post_process
@@ -152,7 +153,8 @@
152153
)
153154
end
154155

155-
it "does not enqueues translate_translatable job for bot posts" do
156+
it "does not enqueue translate_translatable job for bot posts" do
157+
SiteSetting.automatic_translation_backfill_maximum_translations_per_hour = 1
156158
SiteSetting.automatic_translation_target_languages = "es"
157159
post = Fabricate(:post, user: Discourse.system_user)
158160
CookedPostProcessor.new(post).post_process
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe "Translation settings", type: :system do
4+
fab!(:admin)
5+
6+
before do
7+
sign_in(admin)
8+
SiteSetting.translator_enabled = true
9+
end
10+
11+
it "warns when automatic_translation_target_languages is being set but backfill limit is 0" do
12+
visit(
13+
"/admin/plugins/discourse-translator/settings?filter=automatic%20translation%20target%20languages",
14+
)
15+
16+
setting =
17+
PageObjects::Components::SelectKit.new(
18+
"[data-setting='automatic_translation_target_languages'] .select-kit",
19+
)
20+
setting.expand
21+
setting.select_row_by_value("ja")
22+
23+
page.find(".setting-controls button.ok").click()
24+
25+
expect(page).to have_content(I18n.t("site_settings.errors.needs_nonzero_backfill"))
26+
end
27+
end

0 commit comments

Comments
 (0)