Weblate: [API] autotranslate and possible others dont accept json

Created on 9 May 2021  路  3Comments  路  Source: WeblateOrg/weblate

Hey,
im missing a autotranlate all components and all language buttons on the ui, so i tried to use the api but i ran into following error:

The documenttion said that i could transfer form data as json in a curl, but it does not get processed from the api.
The component has no error and is not locked.

This is my test script:

$data='{"mode":"translate","filter_type":"nottranslated","auto_source":"mt","component":"","engines":"google-translate","threshold":"90"}'

curl \
  --data-binary "$data" \
  -H "Content-Type: application/json" \
  -H "Authorization: Token MY_USER_TOKEN" \
  https://myweblateurl.com/api/translations/testproject/testcomponent/de_DE/autotranslate/  

Response:

{"detail":"Failed to process autotranslation data!"}

https://github.com/WeblateOrg/weblate/blob/fbc7a9587f773e3b1cbfb6513027667c93bee8ff/weblate/api/views.py#L1079-L1099

(note: i suggest to answer with its locked if its locked and not with process data failing)

When i use form data, it works:

curl \
  -X POST \
  -F 'mode=translate' \
  -F 'filter_type=nottranslated' \
  -F 'auto_source=mt' \
  -F 'engines=google-translate' \
  -F 'threshold=90' \
  -H "Authorization: Token MY_USER_TOKEN" \
  https://myweblateurl.com/api/translations/testproject/testcomponent/de_DE/autotranslate/

Doc:
CURL JSON example:
https://docs.weblate.org/en/latest/api.html#passing-parameters-examples

Autotranslate:
https://docs.weblate.org/en/latest/api.html#post--api-translations-(string-project)-(string-component)-(string-language)-autotranslate-

enhancement

Most helpful comment

Engines should be an array in JSON, the documentation is wrong here. So, it should be "engines":["google-translate"].

I will improve the error handling to report this correctly.

All 3 comments

Engines should be an array in JSON, the documentation is wrong here. So, it should be "engines":["google-translate"].

I will improve the error handling to report this correctly.

ahhh okay thank you very much! ill give it a try asap.
that would answer my next question on how to send multiple engines, i tried comma seperated but ther eis no info if it worked/got accepted or not :)

Thank you for your report; the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don鈥檛 hesitate to support Weblate by making a donation.
Was this page helpful?
0 / 5 - 0 ratings