Table of Contents
Motivation
Sometimes you need to translate text from one language to another.
I for example often write articles in German but want to have them in English for this blog.
For this use case you can use google’s translation function in the browser.
But wouldn’t it be sweet to automate this task and spare some copy/paste orgies?
Installation
pip install googletrans==3.1.0a0
First Translation – German to English
def test_translate_de_en():
from googletrans import Translator
translator = Translator()
text = "Wie geht's?"
translated = translator.translate(text, src="de", dest="en")
assert translated.text == "How are you?"
English to German
def test_translate_en_de():
from googletrans import Translator
translator = Translator()
text = 'How are you?'
translated = translator.translate(text, src='en', dest="de")
assert translated.text == 'Wie geht es dir?'
Limitations
The maximum character limit on a single text is 15,000