From 5122989d70eaeca891121ac1281cf3dbc04282c3 Mon Sep 17 00:00:00 2001 From: Et0h Date: Tue, 2 Dec 2014 21:07:17 +0000 Subject: [PATCH] Re-work language check; add "Automatic" as default language --- syncplay/messages.py | 8 +++++++- syncplay/ui/ConfigurationGetter.py | 5 ++++- syncplay/ui/GuiConfiguration.py | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/syncplay/messages.py b/syncplay/messages.py index 8aaa354..c3a13a2 100755 --- a/syncplay/messages.py +++ b/syncplay/messages.py @@ -167,6 +167,7 @@ en = { "showslowdownosd-label" :"Include slowing down / reverting notification", "showcontactinfo-label" : "Show contact info box", "language-label" : "Language", + "automatic-language" : "Automatic", "showdurationnotification-label" : "Warn about media duration mismatches", "basics-label" : "Basics", "sync-label" : "Sync", @@ -515,6 +516,7 @@ ru = { "showslowdownosd-label" : u"Показывать уведомления о замедлении/перемотке", "showcontactinfo-label" : u"Отображать контактную информацию разработчиков", "language-label" : u"Language", # TODO: Translate ito Russian + "automatic-language" : "Automatic", # TODO: Translate ito Russian "showdurationnotification-label" : u"Предупреждать о несовпадении продолжительности видео", "basics-label" : u"Основное", "sync-label" : u"Синхронизация", @@ -821,6 +823,7 @@ de = { "showslowdownosd-label" : u"Zeige Verlangsamungs/Zurücksetzungs-Benachrichtigung", "showcontactinfo-label" : u"Zeige Kontaktinformationen", "language-label" : u"Sprache", + "automatic-language" : "Automatic", # TODO: Translate into German (Automatisch?) "showdurationnotification-label" : u"Zeige Warnung wegen unterschiedlicher Dauer", "basics-label" : u"Basics", "sync-label" : u"Synchronisation", @@ -1007,6 +1010,9 @@ def getInitialLanguage(): initialLanguage = constants.FALLBACK_INITIAL_LANGUAGE return initialLanguage +def isValidLanguage(language): + return messages.has_key(language) + def getMessage(type_, locale=None): if constants.SHOW_BUTTON_LABELS == False: if "-guibuttonlabel" in type_: @@ -1015,7 +1021,7 @@ def getMessage(type_, locale=None): if "-tooltip" in type_: return "" - if not messages.has_key(messages["CURRENT"]): + if not isValidLanguage(messages["CURRENT"]): setLanguage(getInitialLanguage()) lang = messages["CURRENT"] diff --git a/syncplay/ui/ConfigurationGetter.py b/syncplay/ui/ConfigurationGetter.py index fb7d710..9feec05 100755 --- a/syncplay/ui/ConfigurationGetter.py +++ b/syncplay/ui/ConfigurationGetter.py @@ -3,7 +3,7 @@ import argparse import os import sys from syncplay import constants, utils, version, milestone -from syncplay.messages import getMessage, setLanguage +from syncplay.messages import getMessage, setLanguage, isValidLanguage from syncplay.players.playerFactory import PlayerFactory import codecs try: @@ -116,6 +116,9 @@ class ConfigurationGetter(object): self._config['language'] = language raise InvalidConfigValue("*"+getMessage("config-cleared-notification")) + if not isValidLanguage(self._config['language']): + self._config['language'] = "" + def _isPortValid(varToTest): try: if varToTest == "" or varToTest is None: diff --git a/syncplay/ui/GuiConfiguration.py b/syncplay/ui/GuiConfiguration.py index bb783fc..c5a9b0d 100644 --- a/syncplay/ui/GuiConfiguration.py +++ b/syncplay/ui/GuiConfiguration.py @@ -5,7 +5,7 @@ from syncplay.players.playerFactory import PlayerFactory import os import sys -from syncplay.messages import getMessage, getLanguages, setLanguage, getInitialLanguage +from syncplay.messages import getMessage, getLanguages, setLanguage, isValidLanguage from syncplay import constants class GuiConfiguration: @@ -629,9 +629,9 @@ class ConfigDialog(QtGui.QDialog): self.languageLabel = QLabel(getMessage("language-label"), self) self.languageCombobox = QtGui.QComboBox(self) + self.languageCombobox.addItem(getMessage("automatic-language")) + self.languages = getLanguages() - if self.languages.has_key(self.config['language']) == False: - self.config['language'] = getInitialLanguage() for lang in self.languages: self.languageCombobox.addItem(self.languages[lang], lang) if lang == self.config['language']: