Textblob has many useful tricks up its sleeve. Generally it’s a very useful Language Processing library that can be used with Python.
You can install it simply by executing the codes below in your Anaconda Command prompt consecutively:
conda install -c conda-forge textblob
python -m textblob.download_corpora
- Book translation
As usual, let’s import the library that we’re going to use:
Tutorial Provided by
Textblob in application
Now let’s create a user input that asks the user to enter a text:
f1 = input("Please enter the text you want to translate")
blob = textblob.TextBlob(f1) print(blob.translate(to="en"))
Here is the full code:
import textblob f1 = input("Please enter the text you want to translate") blob = textblob.TextBlob(f1) print(blob.translate(to="en"))
Failure is the mother of success
Another cool thing about this library is that, the language of the text being entered is auto detected.
Additionally you can tweak the code so that it translates a file instead of userinput.
import textblob f1=r'C://Users/xx/Desktop/book.txt' str = open(f1,"r") str = str.read() blob = textblob.TextBlob(str) print(blob.translate(to="en"))
Textblob uses Google Translate as its translation engine and makes translations as easy as opening the browser and navigating to Google Translate manually and maybe even more fun.