how to build a simple language translator using python


how to build a simple language translator using python

python language translator using Google Translate API – with the help of translator Instantly Translate phrases from one language to another.

Translation enables communication between people from different regions and country. so in this article we will see how to build a simple language translator using python.

Project Pre-requirement

To create this project, we need to use of

  1. Python- mostly recommended 3.8
  2. Tkinter- Tkinter is one of the standard GUI Python library.
  3. googletrans libraries – googletrans is a module which to translate text.

We also need to import LANGUAGES from googletrans which lists all supported languages in a Python dictionary.

use following command to install library

pip install tkinter
pip install googletrans

Following Steps to create simple Translator using python

  • Import required modules
  • Create a display window
  • Create input and output text widget box
  • Define Combobox to select a different language
  • Define required function
  • Create a translate responsive button

1. Need to import module

use following command like

from tkinter import *
from tkinter import ttk
from googletrans import Translator, LANGUAGES

2. Create a simple Display windows

You need to use this command

root = Tk()
root.geometry('1080x400')

root.resizable(0,0)
root.config(bg = 'ghost white')
root.title("sachinp--Language Translator")

Label(root, text = "LANGUAGE TRANSLATOR", font = "arial 20 bold", bg='white smoke').pack()

Label(root,text ="Project Gurukul", font = 'arial 15 bold', bg ='white smoke' , width = '20').pack(side = 'bottom')

3. Create input and output text widget box

Label(root,text ="Enter Text", font = 'arial 13 bold', bg ='white smoke').place(x=200,y=60)

Input_text = Text(root,font = 'arial 10', height = 11, wrap = WORD, padx=5, pady=5, width = 60)
Input_text.place(x=30,y = 100)

Label(root,text ="Output", font = 'arial 13 bold', bg ='white smoke').place(x=780,y=60)

Output_text = Text(root,font = 'arial 10', height = 11, wrap = WORD, padx=5, pady= 5, width =60)
Output_text.place(x = 600 , y = 100)

4. Define Combobox to select a different language

we know that google translator shows different languages to translate so we also provide this feature using this commands

Also read : How to trace mobile number using python

language = list(LANGUAGES.values())

src_lang = ttk.Combobox(root, values= language, width =22)
src_lang.place(x=20,y=60)
src_lang.set('choose input language')

dest_lang = ttk.Combobox(root, values= language, width =22)
dest_lang.place(x=890,y=60)
dest_lang.set('choose output language')

5. Define required function

def Translate():
    translator = Translator()
    translated=translator.translate(text= Input_text.get(1.0, END) , src = src_lang.get(), dest = dest_lang.get())

    Output_text.delete(1.0, END)
    Output_text.insert(END, translated.text)

6. Create a translate responsive button

trans_btn = Button(root, text = 'Translate',font = 'arial 12 bold',pady = 5,command = Translate , bg = 'royal blue1', activebackground = 'sky blue')

trans_btn.place(x = 490, y= 180 )

root.mainloop()

Yaaaa|| your project is ready to translate any text from one language to another. the output is look like

how to build a simple language translator using python
how to build a simple language translator using python

Summary :

In this article we saw how to build a simple language translator using python so about this article you have any query then free to ask me.

Also read :

  1. How to automate facebook post using python
  2. How to make mp3 player using python
how to build a simple language translator using python

I am Mr. Sachin pagar Embedded system engineer, the founder of Pythonslearning, a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Have any Question or Comment?

Leave a Reply

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