You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

26 lines
618 B

import json
import requests
import config
def translate(text, to_language, from_language="auto"):
r =
"q": text,
"source": from_language,
"target": to_language
#response = dict(r.text)
response = json.loads(r.text)
if "translatedText" in response:
return response["translatedText"]
elif "error" in response:
return response["error"]
return "odd, something went wrong"
if __name__ == "__main__":
print(translate("lutsch meinen schwanz", "en"))