Pretranslation API
Description
This PR implements a Pretranslation API at api/v2/pretranslate/?format_string=FORMAT&locale=CODE. It utilizes existing pretranslation functionality in Pontoon and extends it as an authenticated service for those who need a pretranslation from either Translation Memory or AutoML.
Fixes #3830.
Additional Notes
~Authentication for this endpoint is temporarily disabled for easier testing~
~Requires some testing on android and gettext resource formats.~
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 78.86%. Comparing base (6e57308) to head (cbe6f55).
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
I also applied the same above env change for PRETRANSLATION_API_MAX_CHARS to the PERSONAL_ACCESS_TOKEN configuration if that is something that we want.
The code looks good!
Why is the PR maked as Draft? Is there any functionality still missing?
You can test the PR on https://mozilla-pontoon-staging.herokuapp.com:
import requests
response = requests.post(
"https://mozilla-pontoon-staging.herokuapp.com/api/v2/pretranslate/?locale=sl",
data="Open",
headers={
"Content-Type": "text/plain",
"Accept": "application/json",
"Authorization": f"Bearer {TOKEN}",
},
)
Please add a flag in the UserProfile model or create a user group for users authorized to use pretranslation, and use that as another authentication step.
You can test the PR on mozilla-pontoon-staging.herokuapp.com:
import requests response = requests.post( "https://mozilla-pontoon-staging.herokuapp.com/api/v2/pretranslate/?locale=sl", data="Open", headers={ "Content-Type": "text/plain", "Accept": "application/json", "Authorization": f"Bearer {TOKEN}", }, )
Noting that this works on Heroku, but not on GCP (CSRF validation fails).
This is the error displayed if we're missing the Google API keys. We probably need to fix this.
{"error":"An error occurred: Pretranslation for `test = { -brand-short-name } says:` to it not available.. Please verify the resource format and syntax."}
This is the error displayed if we're missing the Google API keys. We probably need to fix this.
{"error":"An error occurred: Pretranslation for `test = { -brand-short-name } says:` to it not available.. Please verify the resource format and syntax."}
- Please wrap locale code into back ticks.
- Please make sure there is no double "..".
Please rebase.