Skip to content

Conversation

@nattsw
Copy link
Contributor

@nattsw nattsw commented Mar 6, 2025

Historically, each translation provider has been saving translation as part of doing the translation.

We are moving the saving outside of the providers, so detect! and translate! only does the detection and translation. Saving is now done in the base class so any future changes do not have to involve each translator.

This PR is to prepare / reduce complexity for the subsequent PR where we move to using raw to translate instead of cooked.

Comment on lines -111 to +120
save_detected_locale(topic_or_post) do
begin
client.translate_text(
{
text: truncate(text_for_detection(topic_or_post)),
source_language_code: "auto",
target_language_code: SUPPORTED_LANG_MAPPING[I18n.locale],
},
)&.source_language_code
rescue Aws::Errors::MissingCredentialsError
raise I18n.t("translator.amazon.invalid_credentials")
end
begin
client.translate_text(
{
text: truncate(text_for_detection(topic_or_post)),
source_language_code: "auto",
target_language_code: SUPPORTED_LANG_MAPPING[I18n.locale],
},
)&.source_language_code
rescue Aws::Errors::MissingCredentialsError
raise I18n.t("translator.amazon.invalid_credentials")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bulk of the change is just removing save_... out of the providers.

@nattsw nattsw merged commit d371bb3 into main Mar 6, 2025
6 checks passed
@nattsw nattsw deleted the save-in-base branch March 6, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants