Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#Code for translation API
# -*- coding: utf-8 -*-
import requests
from keywords import readCountryCodes
import string
def tranlateText(text,country):
for char in string.punctuation: #To avoid any errors caused by undetected char
text = text.replace(char, ' ')
url = "https://google-translate20.p.rapidapi.com/translate"
userInput = text
code = readCountryCodes(country)
querystring = {"text":userInput,"tl":code,"sl":"en"}
headers = {
'x-rapidapi-key': "82f9448eb5msh9013e0006d93ae1p10e70ejsnad262f150737",
'x-rapidapi-host': "google-translate20.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring)
apiList = str(response.text)
apiList = apiList.replace('"', '')
apiList = list(apiList.split(","))
for word in apiList:
if 'data:{translation:' in word:
word = word.replace('data:{translation:','')
tranlatedText = word
return ('Translation from English to ' + country + ' is: ' + tranlatedText)