Skip to content
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

Add Yandex translator option to translate_missing functionality #343

Merged
merged 5 commits into from
Mar 10, 2020

Conversation

SlakrHakr
Copy link
Contributor

translate_missing can be incredibly useful but the two existing options both cost money to use. Yandex Translate is a potential free option for people.

lib/i18n/tasks/version.rb Outdated Show resolved Hide resolved
lib/i18n/tasks/version.rb Outdated Show resolved Hide resolved
end

def options_for_html
{}
Copy link
Owner

Choose a reason for hiding this comment

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

The Yandex API needs format: 'html' for translating HTML values
https://tech.yandex.com/translate/doc/dg/reference/translate-docpage/

I see that the yandex-translate gem doesn't support the format option yet.
We should make sure HTML keys are supported before merging this, because otherwise they will have broken markup.

Looks like there is an abandoned PR for this aegorov/yandex-translator#13

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened a pr to do that work over there and updated the implementation here to utilize it:
aegorov/yandex-translator#14

protected

def translate_values(list, **options)
list.map { |item| translator.translate(item, options) }
Copy link
Owner

@glebm glebm Mar 8, 2020

Choose a reason for hiding this comment

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

Note: This is going to cause lots of requests to the Yandex API, processed in-sequence (slow).

It would be better to pass multiple text parameters to the request, batched to avoid hitting the 10,000 character limit, each batch in its own Thread or Fiber. This should be implemented in the yandex gem.

This is not a blocker for submitting this PR (just waiting for a new release of the yandex gem).

@glebm glebm merged commit 8b6a312 into glebm:master Mar 10, 2020
@glebm glebm added this to the v0.9.31 milestone Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants