-
Notifications
You must be signed in to change notification settings - Fork 90
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 LibreTranslate machine translator, documentation and its test cases. #753
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #753 +/- ##
==========================================
- Coverage 92.60% 92.53% -0.07%
==========================================
Files 46 47 +1
Lines 4017 4034 +17
Branches 598 600 +2
==========================================
+ Hits 3720 3733 +13
- Misses 175 179 +4
Partials 122 122 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drivard thank you for this.
Left a few suggestions for improvement
wagtail_localize/machine_translators/tests/test_libretranslate_translator.py
Outdated
Show resolved
Hide resolved
api_endpoint = self.translator.get_api_endpoint() | ||
self.assertEqual(api_endpoint, "https://libretranslate.org") | ||
|
||
# This probably requires a request to use the API but the test works against my local instance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than making an actual API call, I'd test 2 things:
- that
translate
will raise for status (so, mock the post call to that effect) - that we get a dict of
string: StringValue(translation)
from the response, if there are translated strings. Again, using a mocked response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could I have a bit of pointer on mocking a post request please?
"CLASS": "wagtail_localize.machine_translators.libretranslate.LibreTranslator", | ||
"OPTIONS": { | ||
"LIBRETRANSLATE_URL": "https://libretranslate.org", | ||
"API_KEY": "<Your LibreTranslate api key here>", # Optional on self-hosted instance by providing a random string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"API_KEY": "<Your LibreTranslate api key here>", # Optional on self-hosted instance by providing a random string | |
"API_KEY": "<Your LibreTranslate api key here>", # Use any random string with self-hosted instances. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this would be more appropriate
# On self-hosted instances, if you did not setup the api keys support use any random string.
Co-authored-by: Dan Braghiș <[email protected]>
Co-authored-by: Dan Braghiș <[email protected]>
@zerolab I have completed the changes requests. Please review. |
wagtail_localize/machine_translators/tests/test_libretranslate_translator.py
Outdated
Show resolved
Hide resolved
wagtail_localize/machine_translators/tests/test_libretranslate_translator.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zerolab Do you have an idea of when it will be released ? |
Got a couple of more PRs and if all goes well, sometime next week (i.e before the end of the year) |
This PR introduces a new machine translator to the wagtail-localize project, leveraging the LibreTranslate API. The LibreTranslator class extends the BaseMachineTranslator and implements the necessary methods for translation.
It supports configuration alike
The LibreTranslate API can also be hosted using many methods documented on their github page https://github.com/LibreTranslate/LibreTranslate.
I tested it against a self-hosted instance.
Here are some screenshots of an about us page that I translated using the LibreTranslator.
Please review and provide any feedback.