Skip to content

Commit bf3ae87

Browse files
authored
UX: Show extra details in failure popup when translation fails (#262)
When we translate a newly created topic (therefore topic title and post content), we send both title and cooked in separately. There is a chance that the title cannot be translated, but the post can be translated. The error does not make it obvious on which content the error is happening. This commit makes it precise to the reader if it is the "topic's title" or "post's content".
1 parent 74cf670 commit bf3ae87

File tree

6 files changed

+9
-6
lines changed

6 files changed

+9
-6
lines changed

app/services/discourse_translator/amazon.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def self.translate!(translatable, target_locale_sym = I18n.locale)
134134
)
135135
rescue Aws::Translate::Errors::UnsupportedLanguagePairException
136136
raise I18n.t(
137-
"translator.failed",
137+
"translator.failed.#{translatable.class.name.downcase}",
138138
source_locale: detected_lang,
139139
target_locale: target_locale_sym,
140140
)

app/services/discourse_translator/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def self.translate(translatable, target_locale_sym = I18n.locale)
4242
unless translate_supported?(detected_lang, target_locale_sym)
4343
raise TranslatorError.new(
4444
I18n.t(
45-
"translator.failed",
45+
"translator.failed.#{translatable.class.name.downcase}",
4646
source_locale: detected_lang,
4747
target_locale: target_locale_sym,
4848
),

config/locales/server.en.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ en:
2424
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."
2525
automatic_translation_target_languages: "The languages to automatically translate user content (posts, topics) to. If empty, no languages will be automatically translated."
2626
translator:
27-
failed: "The translator is unable to translate this content (%{source_locale}) to the default language of this site (%{target_locale})."
27+
failed:
28+
topic: "The translator is unable to translate this topic's title (%{source_locale}) to your language (%{target_locale})."
29+
post: "The translator is unable to translate this post's content (%{source_locale}) to your language (%{target_locale})."
2830
not_supported: "This language is not supported by the translator."
2931
too_long: "This post is too long to be translated by the translator."
3032
not_available: "The translator service is currently not available."
3133
api_timeout: "The translator service took too long to respond. Please try again later."
34+
3235
amazon:
3336
invalid_credentials: "The provided credentials for AWS translate are invalid."
3437

spec/services/amazon_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
it "raises an error when trying to translate an unsupported language" do
6969
expect { described_class.translate(post) }.to raise_error(
70-
I18n.t("translator.failed", source_locale: "en", target_locale: "es"),
70+
I18n.t("translator.failed.post", source_locale: "en", target_locale: "es"),
7171
)
7272
end
7373
end

spec/services/google_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
)
144144

145145
expect { described_class.translate(post) }.to raise_error(
146-
I18n.t("translator.failed", source_locale: "cat", target_locale: "dog"),
146+
I18n.t("translator.failed.post", source_locale: "cat", target_locale: "dog"),
147147
)
148148
end
149149

spec/services/microsoft_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def translate_endpoint
169169

170170
expect { described_class.translate(post) }.to raise_error(
171171
DiscourseTranslator::TranslatorError,
172-
I18n.t("translator.failed", source_locale: "donkey", target_locale: I18n.locale),
172+
I18n.t("translator.failed.post", source_locale: "donkey", target_locale: I18n.locale),
173173
)
174174
end
175175

0 commit comments

Comments
 (0)