terryyin / translate-python

Online translation as a Python module & command line tool. No key, no authentication needed.
MIT License
724 stars 155 forks source link

fix: update microsoft provider api #63

Closed pringon closed 3 years ago

pringon commented 3 years ago

This closes #58 and closes #59

Nice library, simple and intuitive client-facing API. :smile:

I tried using the Microsoft provider but was getting the error described in the issues above. After some digging, I realised that the Microsoft Translator API has since been updated and the location of it has moved.

This PR contains the changes that got it working for me. Hope it helps!

An example of how to use the provider:

from translate import Translator

AZURE_TRANSLATE_SECRET = <your-api-key>

translator = Translator(
  to_lang="en", from_lang="autodetect", provider="microsoft",
  secret_access_key=AZURE_TRANSLATE_SECRET, region="europewest"
)

print(translator.translate("e pur si muove"))
# Output should be: and even though it moves
terryyin commented 3 years ago

Thanks! It looks like the API has changed quite a lot!