đ Language Translation in Python using Deep Translator
Want to translate text in Python?
With the deep-translator
library, you can easily use Google Translate to convert text into many languages.
This is perfect for apps, chatbots, or any project that needs quick translations.
đ Why Use Deep Translator?
- ✅ Easy to use
- ✅ Supports multiple translation providers
- ✅ Handles more than 50 languages
- ✅ No need for complex API setup
đ ️ Installation
First, install the library in your Python environment:
pip install deep-translator
đģ Python Code for Language Translation
Here’s a complete example of how to translate the word "Atul" into multiple languages using a dictionary of language codes.
from deep_translator import GoogleTranslator
# By Atul Kushwaha
# Translate "Hello" into Hindi
Sentence="Hello"
Source_language="en" # english
Translated_language="hi" # hindi
result = GoogleTranslator(source=Source_language, target=Translated_language).translate(Sentence)
print("Translation in Hindi:", result)
# Translation in Hindi: ā¤¨ā¤Žā¤¸्⤤े
Output
# Translation in Hindi: ā¤¨ā¤Žā¤¸्⤤े
đ List of Supported Languages
Here’s a quick reference table of supported languages with their codes:
Language | Code |
---|---|
English | en |
Hindi | hi |
Arabic | ar |
Spanish | es |
Chinese (Simplified) | zh-CN |
Chinese (Traditional) | zh-TW |
French | fr |
German | de |
Portuguese | pt |
Russian | ru |
Japanese | ja |
Korean | ko |
Bengali | bn |
Urdu | ur |
Turkish | tr |
Italian | it |
Vietnamese | vi |
Indonesian | id |
Persian (Farsi) | fa |
Thai | th |
Dutch | nl |
Greek | el |
Hebrew | he |
Polish | pl |
Romanian | ro |
Ukrainian | uk |
Swedish | sv |
Hungarian | hu |
Czech | cs |
Filipino (Tagalog) | tl |
Malay | ms |
Tamil | ta |
Telugu | te |
Kannada | kn |
Marathi | mr |
Gujarati | gu |
Punjabi | pa |
Swahili | sw |
Serbian | sr |
Croatian | hr |
Slovak | sk |
Finnish | fi |
Norwegian | no |
Danish | da |
✅ Conclusion
Using Deep Translator in Python makes it super easy to translate text across multiple languages. This is especially useful for multilingual applications, AI projects, chatbots, or content localization. With just a few lines of code, you can automate translations into dozens of global languages.
Pro Tip: Always handle exceptions to skip unsupported languages gracefully.