Python language translator code
In this post, you will learn how to translate language using the Python programming language.
Translation is important for spreading new data, information, and thoughts across the world. It is very important to accomplish successful correspondence between various cultures. When we are spreading new information, translation is something that can change history. Sometimes, we are trying to say something to someone who doesn't understand our language, and we want or need them to understand. A language translator is the only solution.
Python provides a flexible deep-translator tool to translate between different languages in a simple way. We can use this module to translate languages, detect languages, translate from a file, compare different translations and much more.
Install deep_translator tool
The following command installs the deep translator module.
pip install deep_translator
Language translator supported by deep_translator
The deep_translator supports many language translators.
# list of language translators supported by deep_translator
from deep_translator import (GoogleTranslator,
MicrosoftTranslator,
PonsTranslator,
LingueeTranslator,
MyMemoryTranslator,
YandexTranslator,
DeepL,
QCRI,
single_detection,
batch_detection)
Python code to translate language
In the given Python program, we simply use the translate() method to translate the English text to German text.
from deep_translator import GoogleTranslator
translated = GoogleTranslator(source='auto', target='de').translate("Well done John! Keep it up!")
print(translated)
Output of the above code
Gut gemacht, John! Mach weiter!
Check supported language
We can also check all the supported languages of the translators. The following code displays lists of all supported languages by Google translator.
langs_list = GoogleTranslator.get_supported_languages(as_dict=True)
for language, abbreviation in langs_list.items():
print("language : {} abbreviation : {}".format(language, abbreviation))
Output of the above code - 
Related Articles
Convert list to dictionary Python
Convert array to list Python
numpy dot product
glob in Python
Python heap implementation
zip function in Python
Remove last element from list Python
Check if list is empty Python
Remove element from list Python
Python split multiple delimiters
Python loop through list
Python iterate list with index
Python add list to list
Python random choice
dictionary inside list python
Remove character from string Python
Python raise keyword