0% found this document useful (0 votes)
5 views4 pages

Code

This document provides a guide to creating a basic language translator app using Python and Tkinter in Visual Studio Code, allowing translations between English, Shona, and Ndebele with predefined dictionaries. It includes sample code for the app and instructions on how to run it in VS Code. Additionally, it suggests expanding the translation dictionary or integrating with a cloud-based API for more comprehensive language support.

Uploaded by

benjigomiwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Code

This document provides a guide to creating a basic language translator app using Python and Tkinter in Visual Studio Code, allowing translations between English, Shona, and Ndebele with predefined dictionaries. It includes sample code for the app and instructions on how to run it in VS Code. Additionally, it suggests expanding the translation dictionary or integrating with a cloud-based API for more comprehensive language support.

Uploaded by

benjigomiwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Here's a basic language translator app in Visual Studio Code using Python and a simple GUI with Tkinter.

This example allows


translation between English, Shona, and Ndebele using predefined dictionaries, as no public translation API covers Shona and
Ndebele reliably for free.
1. Create a Python file in VS Code (e.g., translator.py ) and paste the
following code:
import tkinter as tk
from tkinter import ttk

# Sample translations
translations = {
'hello': {'Shona': 'mhoro', 'Ndebele': 'sawubona'},
'thank you': {'Shona': 'ndatenda', 'Ndebele': 'ngiyabonga'},
'how are you': {'Shona': 'wakadini zvako', 'Ndebele': 'unjani'},
'goodbye': {'Shona': 'sarai zvakanaka', 'Ndebele': 'hamba kahle'}
}

languages = ['English', 'Shona', 'Ndebele']

def translate():
input_text = input_entry.get().lower()
source_lang = source_lang_var.get()
target_lang = target_lang_var.get()

result = "Translation not found."

for eng, trans in translations.items():


if source_lang == "English" and input_text == eng:
result = trans.get(target_lang, "Translation not available.")
break
elif source_lang != "English":
for word, t in translations.items():
if t.get(source_lang, "") == input_text:
if target_lang == "English":
result = word
else:
result = t.get(target_lang, "Translation not available.")
break

result_label.config(text=result)

# GUI setup
window = tk.Tk()
window.title("Language Translator (English - Shona - Ndebele)")
window.geometry("400x250")

tk.Label(window, text="Enter Text:").pack(pady=5)


input_entry = tk.Entry(window, width=40)
input_entry.pack()

tk.Label(window, text="From:").pack(pady=5)
source_lang_var = tk.StringVar(value="English")
source_lang_menu = ttk.Combobox(window, textvariable=source_lang_var, values=languages, state="read
only")
source_lang_menu.pack()

tk.Label(window, text="To:").pack(pady=5)
target_lang_var = tk.StringVar(value="Shona")
target_lang_menu = ttk.Combobox(window, textvariable=target_lang_var, values=languages, state="read
only")
target_lang_menu.pack()

tk.Button(window, text="Translate", command=translate).pack(pady=10)


result_label = tk.Label(window, text="", font=("Helvetica", 14))
result_label.pack(pady=10)

window.mainloop()

2. How to Run in VS Code:


1. Make sure you have Python installed.
2. Open the folder in VS Code.
3. Create and save the above code as translator.py .
4. Run it with the Python: Run Python File option or in the terminal using:

python translator.py

Notes:
You can expand the translations dictionary with more phrases.
For full language support, consider integrating with a cloud-based API (like Google Translate) for English and use custom
logic for Shona and Ndebele.

Let me know if you want an advanced version with online translation or a mobile/web interface.

You might also like