Skip to content

Commit

Permalink
Fix language selection
Browse files Browse the repository at this point in the history
  • Loading branch information
LyubomirT committed Jul 27, 2024
1 parent 2962049 commit 19436c6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import sys

class Ui_MainWindow(object):
def __init__(self):
self.current_language = "English"
self.translations = {}

def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(600, 500)
Expand Down Expand Up @@ -93,14 +97,13 @@ def setupUi(self, MainWindow):
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
self.current_language = "English" # Default language
self.translations = {}
self.load_translations()

self.languageComboBox.currentTextChanged.connect(self.change_language)
self.update_ui_text()

def load_translations(self):
self.translations = {}
translations_dir = "translations"
for filename in os.listdir(translations_dir):
if filename.endswith(".json"):
Expand All @@ -109,11 +112,12 @@ def load_translations(self):
self.translations[language_code] = json.load(f)
self.languageComboBox.addItem(language_code)

def change_language(self, language):
self.current_language = language
def change_language(self):
self.current_language = self.languageComboBox.currentText()
self.update_ui_text()

def update_ui_text(self):
print(self.current_language)
translation = self.translations.get(self.current_language, self.translations["English"])
for item in translation["MainWindow"]:
component = getattr(self, item["component"], None)
Expand Down

0 comments on commit 19436c6

Please sign in to comment.