From 5144f65cf7f742a12b225222efaf30de029a5022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Climent?= Date: Fri, 7 Oct 2022 22:05:06 +0200 Subject: [PATCH] Implement the basic engine + replace strings in __init__ and mainWindow modules (#67) --- wingetui/__init__.py | 61 ++++++++-------- .../__pycache__/lang_tools.cpython-310.pyc | Bin 0 -> 1486 bytes wingetui/lang/lang_ca.json | 3 + wingetui/lang/lang_en.json | 3 + wingetui/lang/lang_tools.py | 66 ++++++++++++++++++ wingetui/lang/translated_percentage.py | 7 ++ wingetui/languages.py | 13 ++++ wingetui/mainWindow.py | 51 +++++--------- wingetui/tools.py | 34 +++++++-- 9 files changed, 166 insertions(+), 72 deletions(-) create mode 100644 wingetui/lang/__pycache__/lang_tools.cpython-310.pyc create mode 100644 wingetui/lang/lang_ca.json create mode 100644 wingetui/lang/lang_en.json create mode 100644 wingetui/lang/lang_tools.py create mode 100644 wingetui/lang/translated_percentage.py create mode 100644 wingetui/languages.py diff --git a/wingetui/__init__.py b/wingetui/__init__.py index 0dd25cc40..153f48e09 100644 --- a/wingetui/__init__.py +++ b/wingetui/__init__.py @@ -9,12 +9,11 @@ import wingetHelpers, scoopHelpers from mainWindow import * from tools import * + from tools import _ import globals from blurwindow import GlobalBlur, ExtendFrameIntoClientArea - debugging = True - if hasattr(Qt, 'AA_EnableHighDpiScaling'): QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) if hasattr(Qt, 'AA_UseHighDpiPixmaps'): @@ -51,7 +50,7 @@ def __init__(self): titlewidget.addStretch() self.popup.layout().addLayout(titlewidget) self.popup.layout().addStretch() - self.loadingText = QLabel("Loading WingetUI...") + self.loadingText = QLabel(_("Loading WingetUI...")) self.loadingText.setStyleSheet(f"font-family: \"Segoe UI Variable Text\"; color: {'white' if isDark() else 'black'};font-size: 12px;") self.popup.layout().addWidget(self.loadingText) ApplyMenuBlur(self.popup.winId().__int__(), self.popup) @@ -104,7 +103,7 @@ def __init__(self): self.kill.connect(lambda: (self.popup.hide(), sys.exit(0))) self.callInMain.connect(lambda f: f()) Thread(target=self.loadStuffThread, daemon=True).start() - self.loadingText.setText("Checking for other running instances...") + self.loadingText.setText(_("Checking for other running instances...")) except Exception as e: raise e @@ -137,7 +136,7 @@ def loadStuffThread(self): except Exception as e: print(e) finally: - self.callInMain.emit(lambda: self.loadingText.setText(f"Loading UI components...")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Loading UI components..."))) self.callInMain.emit(lambda: self.loadingText.repaint()) self.callInMain.emit(self.loadMainUI) print(globals.componentStatus) @@ -150,22 +149,22 @@ def checkForRunningInstances(self): try: timestamps = [float(file.replace(os.path.join(os.path.join(os.path.expanduser("~"), ".wingetui"), "WingetUI_"), "")) for file in glob.glob(os.path.join(os.path.join(os.path.expanduser("~"), ".wingetui"), "WingetUI_*"))] # get a list with the timestamps validTimestamps = [timestamp for timestamp in timestamps if timestamp < self.nowTime] - self.callInMain.emit(lambda: self.loadingText.setText(f"Evaluating found instace(s)...")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Checking found instace(s)..."))) print("Found lock file(s), reactivating...") for tst in validTimestamps: setSettings("RaiseWindow_"+str(tst), True) if validTimestamps != [] and timestamps != [self.nowTime]: for i in range(16): time.sleep(0.1) - self.callInMain.emit(lambda: self.loadingText.setText(f"Sent handshake. Waiting for instance listener's answer... ({int(i/15*100)}%)")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Sent handshake. Waiting for instance listener's answer... ({0}%)").format(int(i/15*100)))) for tst in validTimestamps: if not getSettings("RaiseWindow_"+str(tst), cache = False): print(f"Instance {tst} responded, quitting...") - self.callInMain.emit(lambda: self.loadingText.setText(f"Instance {tst} responded, quitting...")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Instance {0} responded, quitting...").format(tst))) setSettings(self.lockFileName, False) self.kill.emit() sys.exit(0) - self.callInMain.emit(lambda: self.loadingText.setText(f"Starting daemons...")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Starting daemons..."))) print("Reactivation signal ignored: RaiseWindow_"+str(validTimestamps)) for tst in validTimestamps: setSettings("RaiseWindow_"+str(tst), False) @@ -176,41 +175,41 @@ def checkForRunningInstances(self): def detectWinget(self): try: - self.callInMain.emit(lambda: self.loadingText.setText(f"Locating winget...")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Locating winget..."))) o = subprocess.run(f"{wingetHelpers.winget} -v", shell=True, stdout=subprocess.PIPE) print(o.stdout) print(o.stderr) globals.componentStatus["wingetFound"] = o.returncode == 0 globals.componentStatus["wingetVersion"] = o.stdout.decode('utf-8').replace("\n", "") - self.callInMain.emit(lambda: self.loadingText.setText(f"Winget found: {globals.componentStatus['wingetFound']}")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Winget found: {0}").format(globals.componentStatus['wingetFound']))) except Exception as e: print(e) self.loadStatus += 1 print("updating winget") try: if not getSettings("DisableUpdateIndexes"): - self.callInMain.emit(lambda: self.loadingText.setText(f"Updating winget sources...")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Updating winget sources..."))) o = subprocess.run(f"{wingetHelpers.winget} source update --name winget", shell=True, stdout=subprocess.PIPE) - self.callInMain.emit(lambda: self.loadingText.setText(f"Updated winget sources")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Updated winget sources"))) except Exception as e: print(e) self.loadStatus += 1 def detectScoop(self): try: - self.callInMain.emit(lambda: self.loadingText.setText(f"Locating scoop...")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Locating scoop..."))) o = subprocess.run(f"powershell -Command scoop -v", shell=True, stdout=subprocess.PIPE) print(o.stdout) print(o.stderr) globals.componentStatus["scoopFound"] = o.returncode == 0 globals.componentStatus["scoopVersion"] = o.stdout.decode('utf-8').split("\n")[1] - self.callInMain.emit(lambda: self.loadingText.setText(f"Scoop found: {globals.componentStatus['scoopFound']}")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Scoop found: {0}").format(globals.componentStatus['scoopFound']))) except Exception as e: print(e) self.loadStatus += 1 try: if not getSettings("DisableUpdateIndexes"): - self.callInMain.emit(lambda: self.loadingText.setText(f"Clearing scoop cache...")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Clearing scoop cache..."))) p = subprocess.Popen(f"powershell -Command scoop cache rm *", shell=True, stdout=subprocess.PIPE) if(getSettings("EnableScoopCleanup")): p2 = subprocess.Popen(f"powershell -Command scoop cleanup --all", shell=True, stdout=subprocess.PIPE) @@ -220,9 +219,9 @@ def detectScoop(self): print(e) try: if not getSettings("DisableUpdateIndexes"): - self.callInMain.emit(lambda: self.loadingText.setText(f"Updating scoop sources...")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Updating scoop sources..."))) o = subprocess.run(f"powershell -Command scoop update", shell=True, stdout=subprocess.PIPE) - self.callInMain.emit(lambda: self.loadingText.setText(f"Updated scoop sources")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Updated scoop sources"))) except Exception as e: print(e) self.loadStatus += 1 @@ -230,11 +229,11 @@ def detectScoop(self): def detectSudo(self): global sudoLocation try: - self.callInMain.emit(lambda: self.loadingText.setText(f"Locating sudo...")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Locating sudo..."))) o = subprocess.run(f"{sudoPath} -v", shell=True, stdout=subprocess.PIPE) globals.componentStatus["sudoFound"] = o.returncode == 0 globals.componentStatus["sudoVersion"] = o.stdout.decode('utf-8').split("\n")[0] - self.callInMain.emit(lambda: self.loadingText.setText(f"Sudo found: {globals.componentStatus['sudoFound']}")) + self.callInMain.emit(lambda: self.loadingText.setText(_("Sudo found: {0}").format(globals.componentStatus['sudoFound']))) except Exception as e: print(e) self.loadStatus += 1 @@ -251,58 +250,58 @@ def loadMainUI(self): menu = QMenu("WingetUI") globals.trayMenu = menu - self.infoAction = QAction(f"WingetUI version {versionName}",menu) + self.infoAction = QAction(_("WingetUI version {0}").format(versionName), menu) self.infoAction.setIcon(QIcon(getMedia("info"))) self.infoAction.setEnabled(False) menu.addAction(self.infoAction) - self.showAction = QAction("Show WingetUI",menu) + self.showAction = QAction(_("Show WingetUI"), menu) self.showAction.setIcon(QIcon(getMedia("menu_show"))) menu.addAction(self.showAction) self.trayIcon.setContextMenu(menu) menu.addSeparator() - self.dAction = QAction("Available updates",menu) + self.dAction = QAction(_("Available updates"), menu) self.dAction.setIcon(QIcon(getMedia("menu_updates"))) self.dAction.setEnabled(False) menu.addAction(self.dAction) - self.updatesMenu = menu.addMenu("0 updates found") + self.updatesMenu = menu.addMenu(_("0 updates found")) self.updatesMenu.menuAction().setIcon(QIcon(getMedia("list"))) self.updatesMenu.setParent(menu) globals.trayMenuUpdatesList = self.updatesMenu menu.addMenu(self.updatesMenu) - globals.updatesHeader = QAction("App Name \tInstalled Version \t → \t New version", menu) + globals.updatesHeader = QAction(_("App Name \tInstalled Version \t → \t New version"), menu) globals.updatesHeader.setEnabled(False) globals.updatesHeader.setIcon(QIcon(getMedia("version"))) self.updatesMenu.addAction(globals.updatesHeader) - self.uaAction = QAction("Update all", menu) + self.uaAction = QAction(_("Update all"), menu) self.uaAction.setIcon(QIcon(getMedia("menu_installall"))) menu.addAction(self.uaAction) menu.addSeparator() - self.iAction = QAction("Installed packages",menu) + self.iAction = QAction(_("Installed packages"),menu) self.iAction.setIcon(QIcon(getMedia("menu_uninstall"))) self.iAction.setEnabled(False) menu.addAction(self.iAction) - self.installedMenu = menu.addMenu("0 packages found") + self.installedMenu = menu.addMenu(_("0 packages found")) self.installedMenu.menuAction().setIcon(QIcon(getMedia("list"))) self.installedMenu.setParent(menu) globals.trayMenuInstalledList = self.installedMenu menu.addMenu(self.installedMenu) menu.addSeparator() - globals.installedHeader = QAction("App Name\tInstalled Version", menu) + globals.installedHeader = QAction(_("App Name\tInstalled Version"), menu) globals.installedHeader.setIcon(QIcon(getMedia("version"))) globals.installedHeader.setEnabled(False) self.installedMenu.addAction(globals.installedHeader) self.quitAction = QAction(menu) self.quitAction.setIcon(QIcon(getMedia("menu_close"))) - self.quitAction.setText("Quit") + self.quitAction.setText(_("Quit")) self.quitAction.triggered.connect(lambda: (self.quit(), sys.exit(0))) menu.addAction(self.quitAction) @@ -334,7 +333,7 @@ def applyMenuStyle(): self.showAction.triggered.connect(self.window.showWindow) self.uaAction.triggered.connect(self.window.updates.upgradeAllAction.trigger) showWindow = self.showAction.trigger - self.loadingText.setText(f"Latest details...") + self.loadingText.setText(_("Latest details...")) if not self.isDaemon: self.window.show() if(self.window.isAdmin()): diff --git a/wingetui/lang/__pycache__/lang_tools.cpython-310.pyc b/wingetui/lang/__pycache__/lang_tools.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..da73a4f5c42e3a000238cc22d60e16ecb2e494d7 GIT binary patch literal 1486 zcmYjRTW{P%6!sjCy_?M@Y0?|L04}tYrQIaG@le{TG!%h=C`y7NSwSmz&t%tGuf5F7 zCe(6XDF1**S}A$pfxo~b{EK4bKst$0knW49?<(``(u<^zkBI`pgL{czMZbT=|~ncN)z2;*(fuMH*j-bT^+^ zx~sJ42T7E6hEYchCn;|((h)g=W>9M1Zs(J?(@qkrF1em+4cAmqtVP2_8)!!cL~6W& zZY?aA;?`ma!^n7fx3#=din;lQms3V_VYw8y77Yx0c`ffY--%M)TwdAJRda6MKqL() z>U&4gj-*F(krU}Ka

;7=?g6Nw3Wbp>u~ONJvtZpoxSquto_n*Kg)N#1rDomb1%~4s0YlCAM%Zm@3tP<_xT0e zuHi_*sdKIH2uBN_u>PR3L!72QHa=!`9N!)-*bXD^Ow3D0HzCR#8KzoBsY)U(a6!nn zNHuXLKT!nlKjlwQ1k3v=WEAp z2y2m&*YQSYNK;D*o;wkuV0+K5fsKTtk$T9 zhyNe5HQ1k1o}p_PS7|9-t5sXAwKx&2mhlIXq`R2Oz0Y7#tO@e8h4EtgJd^}mFtrzc zo5oO!q8|;69}NZ~MZ?##IBitQGs00RBJ2zMP?T|zNXTtzShYAG^@ZVfEW_=6zH;Pc z>i)2K_v-3OoOXo%@ZIK;&ZJn~EX`rOYU@g9=`2gs^x&>JN{JstvWMAbx-=XNGO5e+ zW~rAtNl<6t0^?7{y#wqBJH%?V53zt`4dm;TFyE+}N=D7-N3eUridB>NPWgP~Im!vg z?9ukmP+nIy$yXMaGd}}YC}67B`WX%ral;ZuB?NUl1_uVre+*SCOZ^elID>yVz!UDm zW6t3p?!hDO!$V$yzj+n@;v?`UufZRD6n^J*_>GUjuY4SS;S=yPKL9`RN%#?__BvL7 Hs2~3i7%-oW literal 0 HcmV?d00001 diff --git a/wingetui/lang/lang_ca.json b/wingetui/lang/lang_ca.json new file mode 100644 index 000000000..544b7b4dd --- /dev/null +++ b/wingetui/lang/lang_ca.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/wingetui/lang/lang_en.json b/wingetui/lang/lang_en.json new file mode 100644 index 000000000..544b7b4dd --- /dev/null +++ b/wingetui/lang/lang_en.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/wingetui/lang/lang_tools.py b/wingetui/lang/lang_tools.py new file mode 100644 index 000000000..8c8b5e383 --- /dev/null +++ b/wingetui/lang/lang_tools.py @@ -0,0 +1,66 @@ +from os.path import exists +from pathlib import Path + + +languageReference = { + "default": "System language", + "ca" : "Catalan - Català", + "en" : "English - English", +} + + +languageRemap = { + "pt-PT": "pt_PT", + "pt-BR": "pt_BR", + "uk": "ua", + "zh-Hant-TW": "zh_TW", + "zh-Hans-CN": "zh_CN", +} + + +# ISO 3166-1 +languageFlagsRemap = { + "ar": "sa", + "bs": "ba", + "ca": "ad", + "cs": "cz", + "da": "dk", + "en": "gb", + "el": "gr", + "et": "ee", + "fa": "ir", + "he": "il", + "ja": "jp", + "ko": "kr", + "nb": "no", + "nn": "no", + "pt_BR": "br", + "pt_PT": "pt", + "si": "lk", + "zh_CN": "cn", + "zh_TW": "tw", + "vi": "vn", + "sr": "rs", + "sv": "se", +} + + +def getMarkdownSupportLangs(): + from translated_percentage import untranslatedPercentage + + readmeLangs = [ + "| Language | Translated | |", + "| :-- | :-- | --- |", + ] + + dir = str(Path(__file__).parent) + for lang, langName in languageReference.items(): + if (not exists(f"{dir}/lang_{lang}.json")): continue + perc = untranslatedPercentage[lang] if (lang in untranslatedPercentage) else "100%" + if (perc == "0%"): continue + langName = languageReference[lang] if (lang in languageReference) else lang + flag = languageFlagsRemap[lang] if (lang in languageFlagsRemap) else lang + readmeLangs.append(f"| {langName} | {perc} | |") + readmeLangs.append("") + + return "\n".join(readmeLangs) diff --git a/wingetui/lang/translated_percentage.py b/wingetui/lang/translated_percentage.py new file mode 100644 index 000000000..d7448aaae --- /dev/null +++ b/wingetui/lang/translated_percentage.py @@ -0,0 +1,7 @@ +# Autogenerated file, do not modify it!!! +# The following list includes ONLY non-full translated files. + +untranslatedPercentage = { + "en": "107.28%", + "ca": "42069%", +} \ No newline at end of file diff --git a/wingetui/languages.py b/wingetui/languages.py new file mode 100644 index 000000000..aa10e3d99 --- /dev/null +++ b/wingetui/languages.py @@ -0,0 +1,13 @@ +from lang.lang_tools import languageReference + +lang = {} +englang = {} +languages = {} # will be auto-generated + +## auto-generate map of files +for key in languageReference.keys(): + if (key != "default"): + languages[key] = f"lang_{key}.json" + +debugLang = False + diff --git a/wingetui/mainWindow.py b/wingetui/mainWindow.py index 6a9b732fa..d72fb8268 100644 --- a/wingetui/mainWindow.py +++ b/wingetui/mainWindow.py @@ -6,6 +6,7 @@ import globals +from tools import _ from uiSections import * from storeEngine import * @@ -23,7 +24,7 @@ def __init__(self): super().__init__() self.isWinDark = isDark() self.callInMain.connect(lambda f: f()) - self.setWindowTitle("WingetUI: A Graphical User interface to manage Winget and Scoop packages") + self.setWindowTitle("WingetUI") self.setMinimumSize(700, 560) self.setObjectName("micawin") self.setWindowIcon(QIcon(realpath+"/resources/icon.png")) @@ -73,40 +74,22 @@ def loadWidgets(self) -> None: self.discover = DiscoverSoftwareSection() self.discover.setStyleSheet("QGroupBox{border-radius: 5px;}") globals.discover = self.discover - self.widgets[self.discover] = self.addTab(self.discover, "Discover packages") + self.widgets[self.discover] = self.addTab(self.discover, _("Discover packages")) self.updates = UpdateSoftwareSection() self.updates.setStyleSheet("QGroupBox{border-radius: 5px;}") globals.updates = self.updates - self.widgets[self.updates] = self.addTab(self.updates, "Software updates") + self.widgets[self.updates] = self.addTab(self.updates, _("Software updates")) self.uninstall = UninstallSoftwareSection() self.uninstall.setStyleSheet("QGroupBox{border-radius: 5px;}") globals.uninstall = self.uninstall - self.widgets[self.uninstall] = self.addTab(self.uninstall, "Installed packages") + self.widgets[self.uninstall] = self.addTab(self.uninstall, _("Installed packages")) self.settingsSection = SettingsSection() - self.widgets[self.settingsSection] = self.addTab(self.settingsSection, "WingetUI Settings", addToMenu=True, actionIcon="settings") + self.widgets[self.settingsSection] = self.addTab(self.settingsSection, _("WingetUI Settings"), addToMenu=True, actionIcon="settings") self.aboutSection = AboutSection() - self.widgets[self.aboutSection] = self.addTab(self.aboutSection, "About WingetUI", addToMenu=True, actionIcon="info") + self.widgets[self.aboutSection] = self.addTab(self.aboutSection, _("About WingetUI"), addToMenu=True, actionIcon="info") self.aboutSection = DebuggingSection() - self.widgets[self.aboutSection] = self.addTab(self.aboutSection, "WingetUI log", addToMenu=True, actionIcon="buggy") + self.widgets[self.aboutSection] = self.addTab(self.aboutSection, _("WingetUI log"), addToMenu=True, actionIcon="buggy") - class Text(QPlainTextEdit): - def __init__(self): - super().__init__() - self.setPlainText("click to show log") - - def mousePressEvent(self, e: QMouseEvent) -> None: - self.setPlainText(buffer.getvalue()) - self.appendPlainText(errbuffer.getvalue()) - return super().mousePressEvent(e) - - def showEvent(self, e: QShowEvent) -> None: - self.setPlainText(buffer.getvalue()) - self.appendPlainText(errbuffer.getvalue()) - return super().showEvent(e) - - p = Text() - p.setReadOnly(True) - #self.addTab(p, "Debugging log", addToMenu=True) self.buttonLayout.addWidget(QWidget(), stretch=1) vl = QVBoxLayout() hl = QHBoxLayout() @@ -198,11 +181,11 @@ def addTab(self, widget: QWidget, label: str, addToMenu: bool = False, actionIco def warnAboutAdmin(self): self.err = ErrorMessage(self) errorData = { - "titlebarTitle": f"WingetUI", - "mainTitle": f"Administrator privileges", - "mainText": f"It looks like you ran WingetUI as administrator, which is not recommended. You can still use the program, but we hightly recommend not running WingetUI with administrator privileges. Click on \"Show details\" to see why.", - "buttonTitle": "Ok", - "errorDetails": "There are two main reasons to not run WingetUI as administrator:\n The first one is that the scoop package manager might cause problems with some commands when ran with administrator rights.\n The second one is that running WingetUI as administrator means that any package that you download will be ran as administrator (and this is not safe).\n Remeber that if you need to install a specific package as administrator, you can always right-click tyhe item -> Install/Update/Uninstall as administrator.", + "titlebarTitle": _("WingetUI"), + "mainTitle": _("Administrator privileges"), + "mainText": _("It looks like you ran WingetUI as administrator, which is not recommended. You can still use the program, but we hightly recommend not running WingetUI with administrator privileges. Click on \"Show details\" to see why."), + "buttonTitle": _("Ok"), + "errorDetails": _("There are two main reasons to not run WingetUI as administrator:\n The first one is that the scoop package manager might cause problems with some commands when ran with administrator rights.\n The second one is that running WingetUI as administrator means that any package that you download will be ran as administrator (and this is not safe).\n Remeber that if you need to install a specific package as administrator, you can always right-click tyhe item -> Install/Update/Uninstall as administrator."), "icon": QIcon(getMedia("infocolor")), } self.err.showErrorMessage(errorData, showNotification=False) @@ -220,11 +203,11 @@ def closeEvent(self, event): event.accept() if(globals.pending_programs != []): if getSettings("DisablesystemTray"): - if(tools.MessageBox.question(self, "Warning", "There is an installation in progress. If you close WingetUI, the installation may fail and have unexpected results. Do you still want to close the application?", tools.MessageBox.No | tools.MessageBox.Yes, tools.MessageBox.No) == tools.MessageBox.Yes): + if(tools.MessageBox.question(self, _("Warning"), _("There is an installation in progress. If you close WingetUI, the installation may fail and have unexpected results. Do you still want to quit WingetUI?"), tools.MessageBox.No | tools.MessageBox.Yes, tools.MessageBox.No) == tools.MessageBox.Yes): if globals.updatesAvailable: self.hide() globals.canUpdate = True - globals.trayIcon.showMessage("Updating WingetUI", "WingetUI is being updated. When finished, WingetUI will restart itself", QIcon(getMedia("notif_info"))) + globals.trayIcon.showMessage(_("Updating WingetUI"), _("WingetUI is being updated. When finished, WingetUI will restart itself"), QIcon(getMedia("notif_info"))) event.ignore() else: event.accept() @@ -236,7 +219,7 @@ def closeEvent(self, event): if globals.updatesAvailable: self.hide() globals.canUpdate = True - globals.trayIcon.showMessage("Updating WingetUI", "WingetUI is being updated. When finished, WingetUI will restart itself", QIcon(getMedia("notif_info"))) + globals.trayIcon.showMessage(_("Updating WingetUI"), _("WingetUI is being updated. When finished, WingetUI will restart itself"), QIcon(getMedia("notif_info"))) event.ignore() else: self.hide() @@ -246,7 +229,7 @@ def closeEvent(self, event): if globals.updatesAvailable: self.hide() globals.canUpdate = True - globals.trayIcon.showMessage("Updating WingetUI", "WingetUI is being updated. When finished, WingetUI will restart itself", QIcon(getMedia("notif_info"))) + globals.trayIcon.showMessage(_("Updating WingetUI"), _("WingetUI is being updated. When finished, WingetUI will restart itself"), QIcon(getMedia("notif_info"))) event.ignore() else: if getSettings("DisablesystemTray"): diff --git a/wingetui/tools.py b/wingetui/tools.py index 711df7056..0a1d21bba 100644 --- a/wingetui/tools.py +++ b/wingetui/tools.py @@ -10,6 +10,7 @@ from win32mica import ApplyMica, MICAMODE from urllib.request import urlopen from versions import * +from languages import * import globals @@ -19,6 +20,10 @@ old_stderr = sys.stderr buffer = io.StringIO() errbuffer = io.StringIO() +settingsCache = {} +installersWidget = None +updatesAvailable = False + if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): sys.stdout = buffer = io.StringIO() sys.stderr = errbuffer = io.StringIO() @@ -28,6 +33,12 @@ else: realpath = '/'.join(sys.argv[0].replace("\\", "/").split("/")[:-1]) +if not os.path.isdir(os.path.join(os.path.expanduser("~"), ".wingetui")): + try: + os.makedirs(os.path.join(os.path.expanduser("~"), ".wingetui")) + except: + pass + def cprint(*args) -> None: print(*args, file=old_stdout) @@ -38,15 +49,24 @@ def report(exception) -> None: # Exception reporter cprint("🔴 "+line) print(f"🔴 Note this traceback was caught by reporter and has been added to the log ({exception})") -settingsCache = {} -installersWidget = None -updatesAvailable = False +def _(s): # Translate function + global lang + return "-"*len(s) + try: + t = lang[s] + return (t+"✅[Found]✅" if debugLang else t) if t else f"{s}⚠️[UntranslatedString]⚠️" if debugLang else eng_(s) + except KeyError: + if debugLang: print(s) + return f"{eng_(s)}🔴[MissingString]🔴" if debugLang else eng_(s) -if not os.path.isdir(os.path.join(os.path.expanduser("~"), ".wingetui")): +def eng_(s): # English translate function try: - os.makedirs(os.path.join(os.path.expanduser("~"), ".wingetui")) - except: - pass + t = englang[s] + return t if t else s + except KeyError: + if debugLang: + print(s) + return s def getSettings(s: str, cache = True): global settingsCache