TEXT TRANSLATION – In this tutorial, you learn how to translate text from one language to another language (python text translator) using best python translation library with python programming examples.
- Process of translating text from one language into another language that is called as text translation
- Python provides several libraries for text translations. They are
- googletrans (Google)
- translate (Microsoft)
- textblob
- goslate
- Py-translate
I. IMPLEMENTATION OF TEXT TRANSLATION USING MICROSOFT TRANSLATE
REQUIRED MODULE
IMPORTANT CLASSES
1. Translator
- It is a built-in class which takes two arguments.
- It returns an object for the translator
IMPORTANT METHODS
1. translate()
- It is a built-in instance method
- It takes only one argument which is string
- Return type: str
OPTIONS
1. from_lang
- This option is used to set the source language which is string
2. to_lang
- This option is used to set the target language which is string.
I. TRANSLATE APP
Module used : translate (Microsoft Provider)
Filename : Translate.py
Command to install : pip install translate
1. SOURCE CODE
# import the translate module
from translate import *
source_language=”english”
target_language=”german”
input_text=”Good Morning”
inp=Translator(from_lang=source_language, to_lang=target_language)
# translate process and print the result
res=inp.translate(input_text)
print(“—————————————“)
print(“\tTranslator App”)
print(“—————————————“)
print(source_language,”:”,input_text)
print(target_language,”:”,res)
print(“—————————————“)
2.1 INSTALLING TRANSLATE MODULE VIA PIP COMMAND
2.2 INSTALLING TRANSLATE MODULE VIA PIP COMMAND (-Continue)
3. OUTPUT
II. IMPLEMENTATION OF TEXT TRANSLATION USING TEXTBLOB
REQUIRED MODULE
- It is a built-in python library which is used for processing textual data.
IMPORTANT CLASSES
1. Textblob
• It is a built-in class which takes one argument
• It returns an object for the textblob class
IMPORTANT METHODS
1. translate()
- It is a built-in instance method
- It takes only one argument which is string
- Return type: str
2. detect_language()
- It is a built-in instance method
- It is used to automatically detect the language of the sentence in the input
- Return Type: str
IMPORTANT ARGUMENTS
1. to
- This argument is used to set the target language which is string
- It can be like this
- English ‘en’
- Hindi ‘hi’
- French ‘fr’
- Spanish ‘es’
- Bengali ‘bn’.
II. TRANSLATE APP
Module used : textblob
Filename : translate_textblob.py
Command to install : pip install textblob
1. SOURCE CODE
# import the textblob module
from textblob import *
source_language=”English”
target_language=”French”
input_text=”Good Morning”
tb=TextBlob(input_text)
# translate process
res=tb.translate(to=’fr’)
print(“—————————————“)
print(“\tTranslator App”)
print(“—————————————“)
print(source_language,”:”,input_text)
print(target_language,”:”,res)
print(“—————————————“)
2. INSTALLING TEXTBLOB MODULE VIA PIP COMMAND
3. OUTPUT
Other Tutorials
-
How to convert Word to Number in Bash Script
FacebookTweetPinLinkedInEmailShares0SharePrint In this bash tutorial, you will get convert word to number in bash script with examples.This is implemented using for loop, tr command, switch case in shell…
-
How to Count Word Frequency in Bash Script
FacebookTweetPinLinkedInEmailShares0SharePrint In this bash tutorial, you will get the program about how to count word frequency in bash script. This is done by using for loop,…
-
Bash Script – How to convert Number to Words
FacebookTweetPinLinkedInEmailShares0SharePrint In this tutorial, you will see how to convert numbers to words using bash script. This shell script can be done with the help of switch case…