Skip to content

Commit ce7ffa7

Browse files
committed
UX: Prevent users from wondering why backfilling is not happening
1 parent 95a5cfe commit ce7ffa7

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
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
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)