Skip to content

DEV: Move providers into their own module #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions app/controllers/discourse_translator/translator_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ def translate
begin
title_json = {}
detected_lang, translation =
"DiscourseTranslator::#{SiteSetting.translator_provider}".constantize.translate(post)
"DiscourseTranslator::Provider::#{SiteSetting.translator_provider}".constantize.translate(
post,
)
if post.is_first_post?
_, title_translation =
"DiscourseTranslator::#{SiteSetting.translator_provider}".constantize.translate(
"DiscourseTranslator::Provider::#{SiteSetting.translator_provider}".constantize.translate(
post.topic,
)
title_json = { title_translation: title_translation }
end
render json: { translation: translation, detected_lang: detected_lang }.merge(title_json),
status: 200
rescue ::DiscourseTranslator::TranslatorError => e
rescue ::DiscourseTranslator::Provider::TranslatorError => e
render_json_error e.message, status: 422
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/regular/detect_translatable_language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def execute(args)
translatable = args[:type].constantize.find_by(id: args[:translatable_id])
return if translatable.blank?
begin
translator = "DiscourseTranslator::#{SiteSetting.translator_provider}".constantize
translator = "DiscourseTranslator::Provider::#{SiteSetting.translator_provider}".constantize
translator.detect(translatable)
rescue ::DiscourseTranslator::ProblemCheckedTranslationError
rescue ::DiscourseTranslator::Provider::ProblemCheckedTranslationError
# problem-checked translation errors gracefully
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/regular/translate_translatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def execute(args)

target_locales = SiteSetting.automatic_translation_target_languages.split("|")
target_locales.each do |target_locale|
"DiscourseTranslator::#{SiteSetting.translator_provider}".constantize.translate(
"DiscourseTranslator::Provider::#{SiteSetting.translator_provider}".constantize.translate(
translatable,
target_locale.to_sym,
)
Expand Down
3 changes: 2 additions & 1 deletion app/jobs/scheduled/automatic_translation_backfill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def backfill_locales
end

def translator
@translator_klass ||= "DiscourseTranslator::#{SiteSetting.translator_provider}".constantize
@translator_klass ||=
"DiscourseTranslator::Provider::#{SiteSetting.translator_provider}".constantize
end

def translate_records(type, record_ids, target_locale)
Expand Down
164 changes: 0 additions & 164 deletions app/services/discourse_translator/amazon.rb

This file was deleted.

152 changes: 0 additions & 152 deletions app/services/discourse_translator/base.rb

This file was deleted.

Loading
Loading