Nagstamon/QUI/__init__.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Nagstamon/QUI/__init__.py b/Nagstamon/QUI/__init__.py index e9fb314c..efde1156 100644 --- a/Nagstamon/QUI/__init__.py +++ b/Nagstamon/QUI/__init__.py @@ -34,6 +34,15 @@ from urllib.parse import quote # for details of imports look into qt.py from .qt import * +# i18n +import locale +from PyQt5 import QtCore +import sysconfig + +translator = QtCore.QTranslator() +print('Localization loaded: ' + ,translator.load(locale.getlocale()[0] + '.qm', sysconfig.get_path('purelib')+'/Nagstamon/translate')) + from Nagstamon.Config import (Action, AppInfo, BOOLPOOL, @@ -112,6 +121,7 @@ if QT_VERSION_MAJOR < 6: # global application instance APP = QApplication(sys.argv) +APP.installTranslator(translator) # fixed shortened and lowered color names for cells, also used by statusbar label snippets COLORS = OrderedDict([('DOWN', 'color_down_'), @@ -416,7 +426,7 @@ class SystemTrayIcon(QSystemTrayIcon): self.current_icon = self.icons[worst_status] del (worst_status) else: - self.setIcon(self.icons['ERROR']) + self.setIcon(self.icons['CRITICAL']) @Slot() def flash(self): @@ -2038,10 +2048,13 @@ class StatusWindow(QWidget): """ # compile message from status counts message = '' + num_state=0 + translated_state=[self.tr('DOWN'), self.tr('UNREACHABLE'), self.tr('DISASTER'), self.tr('CRITICAL'), self.tr('HIGH'), self.tr('AVERAGE'), self.tr('WARNING'), self.tr('INFORMATION'), self.tr('UNKNOWN')] for state in ['DOWN', 'UNREACHABLE', 'DISASTER', 'CRITICAL', 'HIGH', 'AVERAGE', 'WARNING', 'INFORMATION', 'UNKNOWN']: if current_status_count[state] > 0: - message += '{0} {1} '.format(str(current_status_count[state]), state) + message += '{0} {1} '.format(str(current_status_count[state]), translated_state[num_state]) + num_state=num_state+1 if not message == '': # due to mysterious DBus-Crashes @@ -2414,6 +2427,15 @@ class StatusBar(QWidget): self.labels_invert.connect(self.color_labels[state].invert) self.labels_reset.connect(self.color_labels[state].reset) + # i18n + num_state=0 + + translated_state=[self.tr('DOWN'), self.tr('UNREACHABLE'), self.tr('CRITICAL'), self.tr('WARNING'), self.tr('UNKNOWN')] + translated_state=[self.tr('DOWN'), self.tr('UNREACHABLE'), self.tr('DISASTER'), self.tr('CRITICAL'), self.tr('HIGH'), self.tr('AVERAGE'), self.tr('WARNING'), self.tr('INFORMATION'), self.tr('UNKNOWN')] + for state in ['DOWN', 'UNREACHABLE', 'DISASTER', 'CRITICAL', 'HIGH', 'AVERAGE', 'WARNING', 'INFORMATION', 'UNKNOWN']: + COLOR_STATE_NAMES[state][True]=translated_state[num_state] + num_state=num_state+1 + # label for error message(s) self.label_message = StatusBarLabel('error', parent=parent) self.labels_invert.connect(self.label_message.invert) @@ -4059,7 +4081,7 @@ class TreeView(QTreeView): self.server.has_error = True # tell statusbar there is some error to display - self.show_error.emit('ERROR') + self.show_error.emit(self.tr('ERROR')) # reset counter for this thread self.server.thread_counter = 0