diff --git a/language_translator/AlTranslator.py b/language_translator/AlTranslator.py new file mode 100644 index 000000000..092a0b3ae --- /dev/null +++ b/language_translator/AlTranslator.py @@ -0,0 +1,102 @@ +from tkinter import Tk, Frame, SUNKEN, Label +from tkinter import ttk, Button, X, Text, WORD +from tkinter import font, END +from googletrans import Translator, LANGUAGES +from PIL import ImageTk, Image +import os + +cwd = os.path.dirname(os.path.realpath(__file__)) + + +class AlTranslator(): + + def __init__(self): + root = Tk(className=" ALTRANSLATOR ") + root.geometry("1080x400+820+615") + root.resizable(0, 0) + root.iconbitmap(os.path.join(cwd + '\\UI\\icons', 'altranslator.ico')) + root.config(bg='#ffffff') + root.overrideredirect(1) + + def callback(event): + root.geometry("400x130+1510+885") + + def showScreen(event): + root.deiconify() + root.overrideredirect(1) + + def screenAppear(event): + root.overrideredirect(1) + + def hideScreen(): + root.overrideredirect(0) + root.iconify() + + appHighlightFont = font.Font(family='OnePlus Sans Display', size=12, + weight='bold') + + titleBar = Frame(root, bg='#141414', relief=SUNKEN, bd=0) + icon = Image.open(os.path.join(cwd + '\\UI\\icons', + 'altranslator.ico')) + icon = icon.resize((30, 30), Image.ANTIALIAS) + icon = ImageTk.PhotoImage(icon) + iconLabel = Label(titleBar, image=icon) + iconLabel.photo = icon + iconLabel.config(bg='#141414') + iconLabel.grid(row=0, column=0, sticky="nsew") + titleLabel = Label(titleBar, text='ALTRANSLATOR', fg='#909090', + bg='#141414', font=appHighlightFont) + titleLabel.grid(row=0, column=1, sticky="nsew") + closeButton = Button(titleBar, text="x", bg='#141414', fg="#909090", + borderwidth=0, command=root.destroy, + font=appHighlightFont) + closeButton.grid(row=0, column=3, sticky="nsew") + minimizeButton = Button(titleBar, text="-", bg='#141414', fg="#909090", + borderwidth=0, command=hideScreen, + font=appHighlightFont) + minimizeButton.grid(row=0, column=2, sticky="nsew") + titleBar.grid_columnconfigure(0, weight=1) + titleBar.grid_columnconfigure(1, weight=20) + titleBar.grid_columnconfigure(2, weight=1) + titleBar.grid_columnconfigure(3, weight=1) + titleBar.pack(fill=X) + + inputText = Text(root, font=appHighlightFont, height=11, + wrap=WORD, padx=5, pady=5, width=40, fg='#4877bc') + inputText.place(x=20, y=100) + outputText = Text(root, font=appHighlightFont, height=11, wrap=WORD, + padx=5, pady=5, width=40, bg='#f8f9fb', fg='#4877bc') + outputText.place(x=610, y=100) + + language = list(LANGUAGES.values()) + srcLang = ttk.Combobox(root, values=language, width=22, + font=appHighlightFont) + srcLang.place(x=20, y=60) + srcLang.set('Source language') + destLang = ttk.Combobox(root, values=language, width=22, + font=appHighlightFont) + destLang.place(x=800, y=60) + destLang.set('Destination language') + + def gTranslate(): + translator = Translator() + translated = translator.translate(text=inputText.get(1.0, END), + src=srcLang.get().capitalize(), + dest=destLang.get().capitalize()) + outputText.delete(1.0, END) + outputText.insert(END, translated.text) + + trans_btn = Button(root, text='Translate', font=appHighlightFont, + pady=5, command=gTranslate, fg='#8e8d91', width=9, + bg='#ffffff', bd=0) + trans_btn.place(x=500, y=180) + + titleBar.bind("", callback) + titleBar.bind("", showScreen) + titleBar.bind("", screenAppear) + + root.mainloop() + + +if __name__ == "__main__": + AlTranslator() diff --git a/language_translator/Capture.PNG b/language_translator/Capture.PNG new file mode 100644 index 000000000..586463f46 Binary files /dev/null and b/language_translator/Capture.PNG differ diff --git a/language_translator/Installation Files/OnePlusSans.rar b/language_translator/Installation Files/OnePlusSans.rar new file mode 100644 index 000000000..3fb1f1701 Binary files /dev/null and b/language_translator/Installation Files/OnePlusSans.rar differ diff --git a/language_translator/README.md b/language_translator/README.md index bdb64abf9..ed4d9669e 100644 --- a/language_translator/README.md +++ b/language_translator/README.md @@ -1,19 +1,20 @@ -## USER GUIDE +# AlTranslator -## Setup and activate virtual environment : -For Unix based systems please execute the following command to create venv and install requirements. -``` -make init -source .venv/bin/activate -``` +A python script based GUI interface to translate text from one language to another. -### Pre-requisites -``` -1) Googletrans python library -$ pip install googletrans -``` -### How to run the script? -``` -$ python we-can-use-google-trans.py +## Installation + +Use the package manager [pip](https://pip.pypa.io/en/stable/) to install packages. + +```bash +pip install googletrans==3.1.0a0 +pip install Pillow ``` -Once done the script will prompt for input. + +## Usage + +![](Capture.PNG) + +1. First select both source and destination language. +2. Enter text in the field. +3. Click on Translate. \ No newline at end of file diff --git a/language_translator/UI/icons/altranslator.ico b/language_translator/UI/icons/altranslator.ico new file mode 100644 index 000000000..b5dbb4d97 Binary files /dev/null and b/language_translator/UI/icons/altranslator.ico differ diff --git a/language_translator/makefile b/language_translator/makefile deleted file mode 100644 index e78e53c81..000000000 --- a/language_translator/makefile +++ /dev/null @@ -1,9 +0,0 @@ -VENV ?= .venv -REQUIREMENTS_FILE ?= requirements.txt - -init: - python3 -m venv $(VENV) - $(VENV)/bin/python -m pip install --upgrade pip - if [ -f $(REQUIREMENTS_FILE) ]; \ - then $(VENV)/bin/python -m pip install -r $(REQUIREMENTS_FILE); \ - fi \ No newline at end of file diff --git a/language_translator/requirements.txt b/language_translator/requirements.txt index a993fdce8..81ca1b474 100644 --- a/language_translator/requirements.txt +++ b/language_translator/requirements.txt @@ -1 +1,2 @@ -googletrans \ No newline at end of file +googletrans==3.1.0a0 +Pillow \ No newline at end of file diff --git a/language_translator/we-can-use-google-trans.py b/language_translator/we-can-use-google-trans.py deleted file mode 100644 index f36991a4b..000000000 --- a/language_translator/we-can-use-google-trans.py +++ /dev/null @@ -1,15 +0,0 @@ -import googletrans -from googletrans import Translator - -# Get the list of languages from the google translate API -langList = googletrans.LANGUAGES -# Get the input from the user -inputSentence = input("Please enter a sentence to translate :\n") -translator = Translator() -# Detect the Language -sourceLang = translator.detect(inputSentence).lang -sourceLang = langList[sourceLang] -# Get the translation -translateString = translator.translate(inputSentence).text - -print("The language detected was: " + sourceLang + "\n" + "The translation is: " + translateString)