In the above video I told you how you can create simple translator using python.
Source code
import requests
import json
def translate(text, source_language, target_language):
url = 'https://translate.googleapis.com/translate_a/single'
params = {
'client': 'gtx',
'sl': source_language,
'tl': target_language,
'dt': 't',
'q': text
}
response = requests.get(url, params=params)
data = json.loads(response.text)
return data[0][0][0]
text = input("Enter the text you want to translate: ")
source_language = input("Enter the source language (e.g. en): ")
target_language = input("Enter the target language (e.g. fr): ")
translated_text = translate(text, source_language, target_language)
print(f'Translated text: {translated_text}')
Very thanks
ReplyDelete