xxxxxxxxxx
from googletrans import Translator
def translate_text(text, source_lang, target_lang):
translator = Translator()
translated = translator.translate(text, src=source_lang, dest=target_lang)
return translated.text
text_to_translate = "Hello, how are you?"
source_language = "en"
target_language = "fr"
translated_text = translate_text(text_to_translate, source_language, target_language)
print(translated_text)
xxxxxxxxxx
# install
# pip install googletrans
from googletrans import Translator
translator = Translator()
result = translator.translate('Mitä sinä teet')
print(result)
# result :
#Translated(src=fi, dest=en, text=What are you doing, pronunciation=None, extra_data="{'confiden...")
xxxxxxxxxx
You cand find 2 complete Python Code for translate at this links:
https://neculaifantanaru.com/en/python-code-text-google-translate-website-translation-beautifulsoup-library.html
or here:
https://neculaifantanaru.com/en/example-google-translate-api-key-python-code-beautifulsoup.html
xxxxxxxxxx
you can use a much better python code for translating with google:
https://neculaifantanaru.com/en/python-code-text-google-translate-website-translation-beautifulsoup-new.html