Allow changing of language from within GuiConfig

This commit is contained in:
Et0h 2014-11-30 01:22:21 +00:00
parent dd51106be3
commit a338ebe95f
2 changed files with 49 additions and 7 deletions

View File

@ -2,7 +2,8 @@
from syncplay import constants
en = {
"LANGUAGE" : "English",
# Client notifications
"config-cleared-notification" : "Settings cleared. Changes will be saved when you store a valid configuration.",
@ -64,6 +65,7 @@ en = {
"more-info-notification" : "More info available at: {}", # projectURL
"gui-data-cleared-notification" : "Syncplay has cleared the path and window state data used by the GUI.",
"language-changed-msgbox-label" : "Language will be changed when you run Syncplay.",
"vlc-version-mismatch": "Warning: You are running VLC version {}, but Syncplay is designed to run on VLC {} and above.", # VLC version, VLC min version
"vlc-interface-version-mismatch": "Warning: You are running version {} of the Syncplay interface module for VLC, but Syncplay is designed to run with version {} and above.", # VLC interface version, VLC interface min version
@ -155,6 +157,7 @@ en = {
"showdifferentroomosd-label" : "Include events in other rooms",
"showslowdownosd-label" :"Include slowing down / reverting notification",
"showcontactinfo-label" : "Show contact info box",
"language-label" : "Language",
"showdurationnotification-label" : "Warn about media duration mismatches",
"basics-label" : "Basics",
"sync-label" : "Sync",
@ -252,6 +255,7 @@ en = {
"showbuttonlabels-tooltip" : "Show the text alongside the icons for buttons in the main UI.",
"showtooltips-tooltip" : "Show tooltip help messages when you mouseover an input element in Syncplay.",
"showdurationnotification-tooltip" : "Useful for when a segment in a multi-part file is missing, but can result in false positives.",
"language-tooltip" : u"Language to be used by Syncplay.",
"help-tooltip" : "Opens the Syncplay.pl user guide.",
"reset-tooltip" : "Reset all settings to the default configuration.",
@ -302,6 +306,8 @@ en = {
pl = {
"LANGUAGE" : "Polski", # (Polish)
# Client notifications
"connection-attempt-notification" : u"Próba połączenia z {}:{}", # Port, IP
"reconnection-attempt-notification" : u"Połączenie z serwerem zostało przerwane, ponowne łączenie",
@ -338,6 +344,7 @@ pl = {
}
ru = {
"LANGUAGE" : u"Русский", # (Russian)
# Client notifications
"config-cleared-notification" : u"Настройки сброшены. Изменения вступят в силу при сохранении корректной конфигурации.",
@ -603,6 +610,7 @@ ru = {
}
de = {
"LANGUAGE" : u"Deutsch", # (German)
# Client notifications
"relative-config-notification" : u"Relative Konfigurationsdatei(en) geladen: {}",
@ -794,22 +802,29 @@ de = {
"version-mismatch-server-error" : u"Verschiedene Versionen auf Client und Server",
"wrong-password-server-error" : u"Ungültiges Passwort"
}
messages = {
"en": en,
"pl": pl,
"ru": ru,
"de": de,
"current": None
"CURRENT": None
}
def getLanguages():
langList = {}
for lang in messages:
if lang != "CURRENT":
langList[lang] = getMessage("LANGUAGE", lang)
return langList
def setLanguage(lang):
messages["current"] = lang
messages["CURRENT"] = lang
def getMissingStrings():
missingStrings = ""
for lang in messages:
if lang != "en" and lang != "current":
if lang != "en" and lang != "CURRENT":
for message in messages["en"]:
if not messages[lang].has_key(message):
missingStrings = missingStrings + "({}) Missing: {}\n".format(lang, message)
@ -822,7 +837,7 @@ def getMessage(type_, locale=None):
if constants.SHOW_TOOLTIPS == False:
if "-tooltip" in type_:
return ""
lang = messages["current"]
lang = messages["CURRENT"]
if locale and messages.has_key(locale):
if messages[locale].has_key(type_):
return unicode(messages[locale][type_])

View File

@ -5,7 +5,7 @@ from syncplay.players.playerFactory import PlayerFactory
import os
import sys
from syncplay.messages import getMessage
from syncplay.messages import getMessage, getLanguages, setLanguage
from syncplay import constants
class GuiConfiguration:
@ -112,6 +112,9 @@ class ConfigDialog(QtGui.QDialog):
else:
self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage()))
def languageChanged(self):
setLanguage(unicode(self.languageCombobox.itemData(self.languageCombobox.currentIndex())))
QtGui.QMessageBox.information(self, "Syncplay", getMessage("language-changed-msgbox-label"))
def browsePlayerpath(self):
options = QtGui.QFileDialog.Options()
@ -194,6 +197,7 @@ class ConfigDialog(QtGui.QDialog):
else:
self.config['host'] = None
self.config['playerPath'] = unicode(self.executablepathCombobox.currentText())
self.config['language'] = unicode(self.languageCombobox.itemData(self.languageCombobox.currentIndex()))
if self.mediapathTextbox.text() == "":
self.config['file'] = None
elif os.path.isfile(os.path.abspath(self.mediapathTextbox.text())):
@ -572,6 +576,7 @@ class ConfigDialog(QtGui.QDialog):
self.displaySettingsGroup = QtGui.QGroupBox(getMessage("messages-other-title"))
self.displaySettingsLayout = QtGui.QVBoxLayout()
self.displaySettingsLayout.setAlignment(Qt.AlignTop)
self.displaySettingsFrame = QtGui.QFrame()
self.showDurationNotificationCheckbox = QCheckBox(getMessage("showdurationnotification-label"))
@ -582,6 +587,27 @@ class ConfigDialog(QtGui.QDialog):
self.showcontactinfoCheckbox.setObjectName("showContactInfo")
self.displaySettingsLayout.addWidget(self.showcontactinfoCheckbox)
self.languageFrame = QtGui.QFrame()
self.languageFrame.setContentsMargins(0,0,0,0)
self.languageLayout = QtGui.QHBoxLayout()
self.languageLayout.setSpacing(0)
self.languageLayout.setAlignment(Qt.AlignTop)
self.languageLabel = QLabel(getMessage("language-label"), self)
self.languageCombobox = QtGui.QComboBox(self)
self.languages = getLanguages()
for lang in self.languages:
self.languageCombobox.addItem(self.languages[lang], lang)
if lang == self.config['language']:
self.languageCombobox.setCurrentIndex(self.languageCombobox.count()-1)
self.languageCombobox.currentIndexChanged.connect(self.languageChanged)
self.languageLayout.addWidget(self.languageLabel)
self.languageLayout.addWidget(self.languageCombobox)
self.languageFrame.setLayout(self.languageLayout)
self.languageFrame.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
self.displaySettingsLayout.addWidget(self.languageFrame)
self.languageLabel.setObjectName("language")
self.languageCombobox.setObjectName("language")
self.displaySettingsGroup.setLayout(self.displaySettingsLayout)
self.displaySettingsLayout.setAlignment(Qt.AlignTop)
self.messageLayout.addWidget(self.displaySettingsGroup)
@ -720,6 +746,7 @@ class ConfigDialog(QtGui.QDialog):
self.ensureTabListIsVisible()
self.setFixedWidth(self.minimumSizeHint().width())
self.executablepathCombobox.setFixedWidth(self.mediapathTextbox.width())
self.languageLabel.setFixedWidth(self.languageLabel.width())
def clearGUIData(self, leaveMore=False):
settings = QSettings("Syncplay", "PlayerList")