Skip to content

Commit

Permalink
chore: Update .gitignore and language selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
LyubomirT committed Jul 27, 2024
1 parent 003154a commit 28f5c79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ simulator.py
Virtual/
output/
dist/
dist.zip
dist.zip
language.txt
16 changes: 14 additions & 2 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

class Ui_MainWindow(object):
def __init__(self):
self.current_language = "English"
if os.path.exists("language.txt"):
with open("language.txt", "r", encoding="utf-8") as f:
self.current_language = f.read()
else:
self.current_language = "English"
self.translations = {}

def setupUi(self, MainWindow):
Expand Down Expand Up @@ -83,7 +87,7 @@ def setupUi(self, MainWindow):

self.languageComboBox = QtWidgets.QComboBox(self.horizontalLayoutWidget)
self.languageComboBox.setObjectName("languageComboBox")
self.languageComboBox.currentTextChanged.connect(self.change_language)
self.languageComboBox.currentTextChanged.connect(lambda hakka: self.change_language)
self.settingsLayout.addWidget(self.languageComboBox)

self.lightModeCheckBox = QtWidgets.QCheckBox(self.horizontalLayoutWidget)
Expand All @@ -97,6 +101,11 @@ def setupUi(self, MainWindow):

self.load_translations()

self.update_ui_text()

# set the current language of the dropdown to the saved language
self.languageComboBox.setCurrentText(self.current_language)

def load_translations(self):
self.translations = {}
translations_dir = "translations"
Expand All @@ -110,8 +119,11 @@ def load_translations(self):
def change_language(self):
self.current_language = self.languageComboBox.currentText()
print(f"Changed language to {self.current_language}")
with open("language.txt", "w", encoding="utf-8") as f:
f.write(self.current_language)
self.update_ui_text()


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

0 comments on commit 28f5c79

Please sign in to comment.