Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/services/discourse_translator/amazon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def self.translate!(translatable, target_locale_sym = I18n.locale)
rescue Aws::Translate::Errors::UnsupportedLanguagePairException
raise I18n.t(
"translator.failed",
content_type:
I18n.t("translator.type_of_content.#{translatable.class.name.downcase}"),
source_locale: detected_lang,
target_locale: target_locale_sym,
)
Expand Down
2 changes: 2 additions & 0 deletions app/services/discourse_translator/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def self.translate(translatable, target_locale_sym = I18n.locale)
raise TranslatorError.new(
I18n.t(
"translator.failed",
content_type:
I18n.t("translator.type_of_content.#{translatable.class.name.downcase}"),
source_locale: detected_lang,
target_locale: target_locale_sym,
),
Expand Down
6 changes: 5 additions & 1 deletion config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ en:
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."
automatic_translation_target_languages: "The languages to automatically translate user content (posts, topics) to. If empty, no languages will be automatically translated."
translator:
failed: "The translator is unable to translate this content (%{source_locale}) to the default language of this site (%{target_locale})."
failed: "The translator is unable to translate this %{content_type} (%{source_locale}) to your language (%{target_locale})."
not_supported: "This language is not supported by the translator."
too_long: "This post is too long to be translated by the translator."
not_available: "The translator service is currently not available."
api_timeout: "The translator service took too long to respond. Please try again later."
type_of_content:
topic: "topic's title"
post: "post's content"

amazon:
invalid_credentials: "The provided credentials for AWS translate are invalid."

Expand Down
7 changes: 6 additions & 1 deletion spec/services/amazon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@

it "raises an error when trying to translate an unsupported language" do
expect { described_class.translate(post) }.to raise_error(
I18n.t("translator.failed", source_locale: "en", target_locale: "es"),
I18n.t(
"translator.failed",
content_type: I18n.t("translator.type_of_content.post"),
source_locale: "en",
target_locale: "es",
),
)
end
end
Expand Down
7 changes: 6 additions & 1 deletion spec/services/google_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@
)

expect { described_class.translate(post) }.to raise_error(
I18n.t("translator.failed", source_locale: "cat", target_locale: "dog"),
I18n.t(
"translator.failed",
content_type: I18n.t("translator.type_of_content.post"),
source_locale: "cat",
target_locale: "dog",
),
)
end

Expand Down
7 changes: 6 additions & 1 deletion spec/services/microsoft_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ def translate_endpoint

expect { described_class.translate(post) }.to raise_error(
DiscourseTranslator::TranslatorError,
I18n.t("translator.failed", source_locale: "donkey", target_locale: I18n.locale),
I18n.t(
"translator.failed",
content_type: I18n.t("translator.type_of_content.post"),
source_locale: "donkey",
target_locale: I18n.locale,
),
)
end

Expand Down
Loading