How to Translate language in Python

If you have a list of multiple words and you want to convert them into multiple languages without a timeout and word restriction, then this blog will be beneficial for you.

There are various libraries that can translate from one language to another, but deep-translator is one that can be used for unlimited translation. Therefore, I am using the deep-translator library and translating from the English language to the Nepali language on the Jupyter Notebook. But you can convert to any available language. Let’s start the coding part step by step.

Step 1: Install Package (run the below command in Jupyter Notebook)
Open Jupyter Notebook and paste the below command into a notebook cell and click the shift + Enter button. This will run the command and installs the deep-translator library.

pip install deep-translator

Step 2: We are going to translate multiple texts. So to feed it to the library, I am going to create a dictionary for all words as shown below.

aa = {

“greeting”:”Hello !”,

“kSignInNavTitle”:”SIGN IN”,

“kSignInHeader”:”Please enter your detail to continue”,

“kEmailAddress”:”Email Address”,


“kForgotPassword”:”Forgot Password”,

“kSignIn”:”Sign In”,

“kNewUser”:”New to Super Invoice & Tax?”,

“kSignUp”:”Sign Up”,

“mEnterEmail”:”Please enter email!”,

“mEnterValidEmail”:”Please enter valid email!”,

“mEnterPassword”:”Please enter password!”,

Step 3: Now import the Google translator from deep translator and then create a loop that takes each value from the key and translates and prints. Before running the code please make sure the indentation is proper.

from deep_translator import GoogleTranslator
for i in aa.keys():
    translated = GoogleTranslator(source = 'auto', target='ne').translate(aa.get(i))
    print(i+':'+"'"+ translated+"',")

Step 4: You can see the same key and the value is in the translated form. You can edit the format of translated output as you need. You can see my output below.

kSignInNavTitle:’साइन इन गर्नुहोस्’,
kSignInHeader:’जारी राख्नको लागी कृपया तपाइँको विवरण प्रविष्ट गर्नुहोस्’,
kEmailAddress:’इ – मेल ठेगाना’,
kForgotPassword:’पासवर्ड भुल्नु भयो’,
kSignIn:’साइन इन गर्नुहोस्’,
kNewUser:’सुपर इनभ्वाइस र कर मा नयाँ?’,
kSignUp:’साइन अप’,
mEnterEmail:’कृपया ईमेल प्रविष्ट गर्नुहोस्!’,
mEnterValidEmail:’कृपया मान्य ईमेल प्रविष्ट गर्नुहोस्!’,
mEnterPassword:’कृपया पासवर्ड प्रविष्ट गर्नुहोस्!’,

Visual Example:
The actual Jupyter Notebook snap shot is attached below.

You can also check the official documentation for the deep translator.
Deep Translator Documentation Link

You need to use language code to convert the text to that language. You can get the language code here.

Leave a Reply

Your email address will not be published. Required fields are marked *