From 03e34cc43fcafcd25dd13bd5b9cf52a83884dc56 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 18 Jun 2016 23:50:12 +0300 Subject: [PATCH] translation settings improvements --- src/main.py | 6 +++--- src/menu.py | 13 ++++++------- src/profile.py | 5 ++++- src/settings.py | 10 +++++----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main.py b/src/main.py index 7d102a1..029362c 100644 --- a/src/main.py +++ b/src/main.py @@ -76,8 +76,8 @@ class Toxygen(object): current_locale = QtCore.QLocale() curr_lang = current_locale.languageToString(current_locale.language()) langs = Settings.supported_languages() - if curr_lang in map(lambda x: x[0], langs): - lang_path = filter(lambda x: x[0] == curr_lang, langs)[0][1] + if curr_lang in langs: + lang_path = langs[curr_lang] translator = QtCore.QTranslator() translator.load(curr_directory() + '/translations/' + lang_path) app.installTranslator(translator) @@ -130,7 +130,7 @@ class Toxygen(object): else: settings.set_active_profile() - lang = filter(lambda x: x[0] == settings['language'], Settings.supported_languages())[0] + lang = Settings.supported_languages()[settings['language']] translator = QtCore.QTranslator() translator.load(curr_directory() + '/translations/' + lang[1]) app.installTranslator(translator) diff --git a/src/menu.py b/src/menu.py index b5aecf5..eed6a4c 100644 --- a/src/menu.py +++ b/src/menu.py @@ -532,11 +532,10 @@ class InterfaceSettings(CenteredWidget): self.lang_choose = QtGui.QComboBox(self) self.lang_choose.setGeometry(QtCore.QRect(30, 110, 160, 30)) supported = Settings.supported_languages() - for elem in supported: - self.lang_choose.addItem(elem[0]) - lang = settings['language'] - index = map(lambda x: x[0], supported).index(lang) - self.lang_choose.setCurrentIndex(index) + for key in supported: + self.lang_choose.insertItem(0, key) + if settings['language'] == key: + self.lang_choose.setCurrentIndex(0) self.lang = QtGui.QLabel(self) self.lang.setGeometry(QtCore.QRect(30, 80, 121, 20)) self.lang.setFont(font) @@ -596,8 +595,8 @@ class InterfaceSettings(CenteredWidget): language = self.lang_choose.currentText() if settings['language'] != language: settings['language'] = language - index = self.lang_choose.currentIndex() - path = Settings.supported_languages()[index][1] + text = self.lang_choose.currentText() + path = Settings.supported_languages()[text] app = QtGui.QApplication.instance() app.removeTranslator(app.translator) app.translator.load(curr_directory() + '/translations/' + path) diff --git a/src/profile.py b/src/profile.py index 2bef97c..57f1679 100644 --- a/src/profile.py +++ b/src/profile.py @@ -163,7 +163,10 @@ class Profile(contact.Contact, Singleton): self._screen.typing.setVisible(False) if value is not None: if self._active_friend + 1: - self._friends[self._active_friend].curr_text = self._screen.messageEdit.toPlainText() + try: + self._friends[self._active_friend].curr_text = self._screen.messageEdit.toPlainText() + except: + pass self._active_friend = value friend = self._friends[value] self._friends[value].reset_messages() diff --git a/src/settings.py b/src/settings.py index d79e9f4..c3fd3d5 100644 --- a/src/settings.py +++ b/src/settings.py @@ -125,11 +125,11 @@ class Settings(Singleton, dict): @staticmethod def supported_languages(): - return [ - ('English', 'en_EN'), - ('Russian', 'ru_RU'), - ('French', 'fr_FR') - ] + return { + 'English': 'en_EN', + 'Russian': 'ru_RU', + 'French': 'fr_FR' + } def upgrade(self): default = Settings.get_default_settings()