From da93d1d8b469d62bb8533d7b172364811ddb1a22 Mon Sep 17 00:00:00 2001 From: sendiulo Date: Sat, 24 Aug 2013 09:07:46 +0200 Subject: [PATCH] Combobox for language selection. Unfortunately, I didn't manage to automatically provide all the languages that are available as *.qm files. By now we have to manually set the combobox items and the list for the languages in the bitmessageqt/__init__.py --- src/bitmessageqt/__init__.py | 72 ++++++------ src/bitmessageqt/settings.py | 100 ++++++++++------- src/bitmessageqt/settings.ui | 105 ++++++++++++------ src/helper_startup.py | 10 +- src/translations/bitmessage_en_pirate.ts | 2 +- ...tmessage_fr.pro~HEAD => bitmessage_fr.pro} | 0 6 files changed, 176 insertions(+), 113 deletions(-) rename src/translations/{bitmessage_fr.pro~HEAD => bitmessage_fr.pro} (100%) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 1cb13e34..06010f7c 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2031,10 +2031,10 @@ class MyForm(QtGui.QMainWindow): self.settingsDialogInstance.ui.checkBoxStartInTray.isChecked())) shared.config.set('bitmessagesettings', 'willinglysendtomobile', str( self.settingsDialogInstance.ui.checkBoxWillinglySendToMobile.isChecked())) - shared.config.set('bitmessagesettings', 'overridelocale', str( - self.settingsDialogInstance.ui.checkBoxOverrideLocale.isChecked())) - shared.config.set('bitmessagesettings', 'userlocale', str( - self.settingsDialogInstance.ui.lineEditUserLocale.text())) + + lang_ind = int(self.settingsDialogInstance.ui.languageComboBox.currentIndex()) + shared.config.set('bitmessagesettings', 'userlocale', languages[lang_ind]) + if int(shared.config.get('bitmessagesettings', 'port')) != int(self.settingsDialogInstance.ui.lineEditTCPPort.text()): if not shared.safeConfigGetBoolean('bitmessagesettings', 'dontconnect'): QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( @@ -3045,10 +3045,13 @@ class settingsDialog(QtGui.QDialog): shared.config.getboolean('bitmessagesettings', 'startintray')) self.ui.checkBoxWillinglySendToMobile.setChecked( shared.safeConfigGetBoolean('bitmessagesettings', 'willinglysendtomobile')) - self.ui.checkBoxOverrideLocale.setChecked( - shared.safeConfigGetBoolean('bitmessagesettings', 'overridelocale')) - self.ui.lineEditUserLocale.setText(str( - shared.config.get('bitmessagesettings', 'userlocale'))) + + global languages + languages = ['system','en','eo','fr','de','es','ru','en_pirate'] + + user_countrycode = str(shared.config.get('bitmessagesettings', 'userlocale')) + self.ui.languageComboBox.setCurrentIndex(languages.index(user_countrycode)) + if shared.appdata == '': self.ui.checkBoxPortableMode.setChecked(True) if 'darwin' in sys.platform: @@ -3413,40 +3416,45 @@ def run(): app = QtGui.QApplication(sys.argv) translator = QtCore.QTranslator() - local_countrycode = str(locale.getdefaultlocale()[0]) - locale_lang = local_countrycode[0:2] + locale_countrycode = str(locale.getdefaultlocale()[0]) + locale_lang = locale_countrycode[0:2] user_countrycode = str(shared.config.get('bitmessagesettings', 'userlocale')) user_lang = user_countrycode[0:2] translation_path = "translations/bitmessage_" - if shared.config.getboolean('bitmessagesettings', 'overridelocale') == True: - # try the userinput if "overwridelanguage" is checked + if shared.config.get('bitmessagesettings', 'userlocale') == 'system': + # try to detect the users locale otherwise fallback to English try: - # check if the user input is a valid translation file - # this would also capture weird "countrycodes" like "en_pirate" or just "pirate" + # try the users full locale, e.g. 'en_US': + # since we usually only provide languages, not localozations + # this will usually fail + translator.load(translation_path + locale_countrycode) + except: + try: + # try the users locale language, e.g. 'en': + # since we usually only provide languages, not localozations + # this will usually succeed + translator.load(translation_path + locale_lang) + except: + # as English is already the default language, we don't + # need to do anything. No need to translate. + pass + else: + try: + # check if the user input is a valid translation file: + # since user_countrycode will be usually set by the combobox + # it will usually just be a language code translator.load(translation_path + user_countrycode) except: try: - # check if the user lang is a valid translation file - # in some cases this won't make sense, e.g. trying "pi" from "pirate" + # check if the user lang is a valid translation file: + # this is only needed if the user manually set his 'userlocale' + # in the keys.dat to a countrycode (e.g. 'de_CH') translator.load(translation_path + user_lang) except: - # The above is not compatible with all versions of OSX. - # Don't have language either, default to 'Merica USA! USA! - translator.load("translations/bitmessage_en_US") # Default to english. - else: - # try the userinput if "overridelanguage" is checked - try: - # check if the user input is a valid translation file - translator.load(translation_path + local_countrycode) - except: - try: - # check if the user lang is a valid translation file - translator.load(translation_path + locale_lang) - except: - # The above is not compatible with all versions of OSX. - # Don't have language either, default to 'Merica USA! USA! - translator.load("translations/bitmessage_en_US") # Default to english. + # as English is already the default language, we don't + # need to do anything. No need to translate. + pass QtGui.QApplication.installTranslator(translator) app.setStyleSheet("QStatusBar::item { border: 0px solid black }") diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index 8d2cf677..bd7d0240 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -2,8 +2,8 @@ # Form implementation generated from reading ui file 'settings.ui' # -# Created: Wed Aug 14 18:31:34 2013 -# by: PyQt4 UI code generator 4.10 +# Created: Sat Aug 24 08:28:46 2013 +# by: PyQt4 UI code generator 4.10.2 # # WARNING! All changes made in this file will be lost! @@ -41,63 +41,66 @@ class Ui_settingsDialog(object): self.tabUserInterface.setObjectName(_fromUtf8("tabUserInterface")) self.gridLayout_5 = QtGui.QGridLayout(self.tabUserInterface) self.gridLayout_5.setObjectName(_fromUtf8("gridLayout_5")) - self.labelSettingsNote = QtGui.QLabel(self.tabUserInterface) - self.labelSettingsNote.setText(_fromUtf8("")) - self.labelSettingsNote.setWordWrap(True) - self.labelSettingsNote.setObjectName(_fromUtf8("labelSettingsNote")) - self.gridLayout_5.addWidget(self.labelSettingsNote, 7, 0, 1, 1) - spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) - self.gridLayout_5.addItem(spacerItem, 8, 0, 1, 1) - self.checkBoxStartInTray = QtGui.QCheckBox(self.tabUserInterface) - self.checkBoxStartInTray.setObjectName(_fromUtf8("checkBoxStartInTray")) - self.gridLayout_5.addWidget(self.checkBoxStartInTray, 1, 0, 1, 1) - self.checkBoxShowTrayNotifications = QtGui.QCheckBox(self.tabUserInterface) - self.checkBoxShowTrayNotifications.setObjectName(_fromUtf8("checkBoxShowTrayNotifications")) - self.gridLayout_5.addWidget(self.checkBoxShowTrayNotifications, 3, 0, 1, 1) self.checkBoxMinimizeToTray = QtGui.QCheckBox(self.tabUserInterface) self.checkBoxMinimizeToTray.setChecked(True) self.checkBoxMinimizeToTray.setObjectName(_fromUtf8("checkBoxMinimizeToTray")) self.gridLayout_5.addWidget(self.checkBoxMinimizeToTray, 2, 0, 1, 1) - self.label_7 = QtGui.QLabel(self.tabUserInterface) - self.label_7.setWordWrap(True) - self.label_7.setObjectName(_fromUtf8("label_7")) - self.gridLayout_5.addWidget(self.label_7, 5, 0, 1, 1) + spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) + self.gridLayout_5.addItem(spacerItem, 10, 0, 1, 1) self.checkBoxStartOnLogon = QtGui.QCheckBox(self.tabUserInterface) self.checkBoxStartOnLogon.setObjectName(_fromUtf8("checkBoxStartOnLogon")) self.gridLayout_5.addWidget(self.checkBoxStartOnLogon, 0, 0, 1, 1) + self.checkBoxShowTrayNotifications = QtGui.QCheckBox(self.tabUserInterface) + self.checkBoxShowTrayNotifications.setObjectName(_fromUtf8("checkBoxShowTrayNotifications")) + self.gridLayout_5.addWidget(self.checkBoxShowTrayNotifications, 3, 0, 1, 1) self.checkBoxPortableMode = QtGui.QCheckBox(self.tabUserInterface) self.checkBoxPortableMode.setObjectName(_fromUtf8("checkBoxPortableMode")) self.gridLayout_5.addWidget(self.checkBoxPortableMode, 4, 0, 1, 1) + self.checkBoxStartInTray = QtGui.QCheckBox(self.tabUserInterface) + self.checkBoxStartInTray.setObjectName(_fromUtf8("checkBoxStartInTray")) + self.gridLayout_5.addWidget(self.checkBoxStartInTray, 1, 0, 1, 1) + self.PortableModeDescription = QtGui.QLabel(self.tabUserInterface) + self.PortableModeDescription.setWordWrap(True) + self.PortableModeDescription.setObjectName(_fromUtf8("PortableModeDescription")) + self.gridLayout_5.addWidget(self.PortableModeDescription, 5, 0, 1, 2) self.checkBoxWillinglySendToMobile = QtGui.QCheckBox(self.tabUserInterface) self.checkBoxWillinglySendToMobile.setObjectName(_fromUtf8("checkBoxWillinglySendToMobile")) - self.gridLayout_5.addWidget(self.checkBoxWillinglySendToMobile, 6, 0, 1, 1) - self.checkBoxOverrideLocale = QtGui.QCheckBox(self.tabUserInterface) - self.checkBoxOverrideLocale.setObjectName(_fromUtf8("checkBoxOverrideLocale")) - self.gridLayout_5.addWidget(self.checkBoxOverrideLocale, 7, 0, 1, 1) - self.lineEditUserLocale = QtGui.QLineEdit(self.tabUserInterface) - self.lineEditUserLocale.setObjectName(_fromUtf8("lineEditUserLocale")) - self.lineEditUserLocale.setMaximumSize(QtCore.QSize(70, 16777215)) - self.lineEditUserLocale.setEnabled(False) - self.gridLayout_5.addWidget(self.lineEditUserLocale, 7, 1, 1, 1) + self.gridLayout_5.addWidget(self.checkBoxWillinglySendToMobile, 6, 0, 1, 2) + self.groupBox = QtGui.QGroupBox(self.tabUserInterface) + self.groupBox.setObjectName(_fromUtf8("groupBox")) + self.horizontalLayout_2 = QtGui.QHBoxLayout(self.groupBox) + self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2")) + self.languageComboBox = QtGui.QComboBox(self.groupBox) + self.languageComboBox.setObjectName(_fromUtf8("languageComboBox")) + self.languageComboBox.addItem(_fromUtf8("")) + self.languageComboBox.addItem(_fromUtf8("")) + self.languageComboBox.addItem(_fromUtf8("")) + self.languageComboBox.addItem(_fromUtf8("")) + self.languageComboBox.addItem(_fromUtf8("")) + self.languageComboBox.addItem(_fromUtf8("")) + self.languageComboBox.addItem(_fromUtf8("")) + self.languageComboBox.addItem(_fromUtf8("")) + self.horizontalLayout_2.addWidget(self.languageComboBox) + self.gridLayout_5.addWidget(self.groupBox, 10, 1, 1, 1) self.tabWidgetSettings.addTab(self.tabUserInterface, _fromUtf8("")) self.tabNetworkSettings = QtGui.QWidget() self.tabNetworkSettings.setObjectName(_fromUtf8("tabNetworkSettings")) self.gridLayout_4 = QtGui.QGridLayout(self.tabNetworkSettings) self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4")) - self.groupBox = QtGui.QGroupBox(self.tabNetworkSettings) - self.groupBox.setObjectName(_fromUtf8("groupBox")) - self.gridLayout_3 = QtGui.QGridLayout(self.groupBox) + self.groupBox1 = QtGui.QGroupBox(self.tabNetworkSettings) + self.groupBox1.setObjectName(_fromUtf8("groupBox1")) + self.gridLayout_3 = QtGui.QGridLayout(self.groupBox1) self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3")) spacerItem1 = QtGui.QSpacerItem(125, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout_3.addItem(spacerItem1, 0, 0, 1, 1) - self.label = QtGui.QLabel(self.groupBox) + self.label = QtGui.QLabel(self.groupBox1) self.label.setObjectName(_fromUtf8("label")) self.gridLayout_3.addWidget(self.label, 0, 1, 1, 1) - self.lineEditTCPPort = QtGui.QLineEdit(self.groupBox) + self.lineEditTCPPort = QtGui.QLineEdit(self.groupBox1) self.lineEditTCPPort.setMaximumSize(QtCore.QSize(70, 16777215)) self.lineEditTCPPort.setObjectName(_fromUtf8("lineEditTCPPort")) self.gridLayout_3.addWidget(self.lineEditTCPPort, 0, 2, 1, 1) - self.gridLayout_4.addWidget(self.groupBox, 0, 0, 1, 1) + self.gridLayout_4.addWidget(self.groupBox1, 0, 0, 1, 1) self.groupBox_2 = QtGui.QGroupBox(self.tabNetworkSettings) self.groupBox_2.setObjectName(_fromUtf8("groupBox_2")) self.gridLayout_2 = QtGui.QGridLayout(self.groupBox_2) @@ -313,7 +316,6 @@ class Ui_settingsDialog(object): self.tabWidgetSettings.setCurrentIndex(0) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), settingsDialog.accept) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), settingsDialog.reject) - QtCore.QObject.connect(self.checkBoxOverrideLocale, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.lineEditUserLocale.setEnabled) QtCore.QObject.connect(self.checkBoxAuthentication, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.lineEditSocksUsername.setEnabled) QtCore.QObject.connect(self.checkBoxAuthentication, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.lineEditSocksPassword.setEnabled) QtCore.QMetaObject.connectSlotsByName(settingsDialog) @@ -333,16 +335,24 @@ class Ui_settingsDialog(object): def retranslateUi(self, settingsDialog): settingsDialog.setWindowTitle(_translate("settingsDialog", "Settings", None)) - self.checkBoxStartInTray.setText(_translate("settingsDialog", "Start Bitmessage in the tray (don\'t show main window)", None)) - self.checkBoxShowTrayNotifications.setText(_translate("settingsDialog", "Show notification when message received", None)) self.checkBoxMinimizeToTray.setText(_translate("settingsDialog", "Minimize to tray", None)) - self.label_7.setText(_translate("settingsDialog", "In Portable Mode, messages and config files are stored in the same directory as the program rather than the normal application-data folder. This makes it convenient to run Bitmessage from a USB thumb drive.", None)) self.checkBoxStartOnLogon.setText(_translate("settingsDialog", "Start Bitmessage on user login", None)) + self.checkBoxShowTrayNotifications.setText(_translate("settingsDialog", "Show notification when message received", None)) self.checkBoxPortableMode.setText(_translate("settingsDialog", "Run in Portable Mode", None)) + self.checkBoxStartInTray.setText(_translate("settingsDialog", "Start Bitmessage in the tray (don\'t show main window)", None)) + self.PortableModeDescription.setText(_translate("settingsDialog", "In Portable Mode, messages and config files are stored in the same directory as the program rather than the normal application-data folder. This makes it convenient to run Bitmessage from a USB thumb drive.", None)) self.checkBoxWillinglySendToMobile.setText(_translate("settingsDialog", "Willingly include unencrypted destination address when sending to a mobile device", None)) - self.checkBoxOverrideLocale.setText(_translate("settingsDialog", "Override automatic language localization (use countycode or language code, e.g. 'en_US' or 'en'):", None)) + self.groupBox.setTitle(_translate("settingsDialog", "Interface Language", None)) + self.languageComboBox.setItemText(0, _translate("settingsDialog", "System Settings", "system")) + self.languageComboBox.setItemText(1, _translate("settingsDialog", "English", "en")) + self.languageComboBox.setItemText(2, _translate("settingsDialog", "Esperanto", "eo")) + self.languageComboBox.setItemText(3, _translate("settingsDialog", "French", "fr")) + self.languageComboBox.setItemText(4, _translate("settingsDialog", "German", "de")) + self.languageComboBox.setItemText(5, _translate("settingsDialog", "Spanish", "es")) + self.languageComboBox.setItemText(6, _translate("settingsDialog", "Russian", "ru")) + self.languageComboBox.setItemText(7, _translate("settingsDialog", "Pirate English", "en_pirate")) self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabUserInterface), _translate("settingsDialog", "User Interface", None)) - self.groupBox.setTitle(_translate("settingsDialog", "Listening port", None)) + self.groupBox1.setTitle(_translate("settingsDialog", "Listening port", None)) self.label.setText(_translate("settingsDialog", "Listen for connections on port:", None)) self.groupBox_2.setTitle(_translate("settingsDialog", "Proxy server / Tor", None)) self.label_2.setText(_translate("settingsDialog", "Type:", None)) @@ -377,3 +387,13 @@ class Ui_settingsDialog(object): self.radioButtonNamecoinNmcontrol.setText(_translate("settingsDialog", "NMControl", None)) self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabNamecoin), _translate("settingsDialog", "Namecoin integration", None)) + +if __name__ == "__main__": + import sys + app = QtGui.QApplication(sys.argv) + settingsDialog = QtGui.QDialog() + ui = Ui_settingsDialog() + ui.setupUi(settingsDialog) + settingsDialog.show() + sys.exit(app.exec_()) + diff --git a/src/bitmessageqt/settings.ui b/src/bitmessageqt/settings.ui index 0ca22088..abacd30f 100644 --- a/src/bitmessageqt/settings.ui +++ b/src/bitmessageqt/settings.ui @@ -37,17 +37,17 @@ User Interface - - + + - + Minimize to tray - + true - + Qt::Vertical @@ -60,10 +60,10 @@ - - + + - Start Bitmessage in the tray (don't show main window) + Start Bitmessage on user login @@ -74,18 +74,22 @@ - - + + - Minimize to tray - - - true + Run in Portable Mode - - + + + + Start Bitmessage in the tray (don't show main window) + + + + + In Portable Mode, messages and config files are stored in the same directory as the program rather than the normal application-data folder. This makes it convenient to run Bitmessage from a USB thumb drive. @@ -94,27 +98,66 @@ - - - - Start Bitmessage on user login - - - - - - - Run in Portable Mode - - - - + Willingly include unencrypted destination address when sending to a mobile device + + + + Interface Language + + + + + + + System Settings + + + + + English + + + + + Esperanto + + + + + French + + + + + German + + + + + Spanish + + + + + Russian + + + + + Pirate English + + + + + + + diff --git a/src/helper_startup.py b/src/helper_startup.py index 67ae8d8c..24dc0156 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -70,15 +70,7 @@ def loadConfig(): shared.config.set( 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', '0') shared.config.set('bitmessagesettings', 'dontconnect', 'true') - shared.config.set('bitmessagesettings', 'overridelocale', 'false') - try: - # this should set the userdefined locale to the default locale - # like this, the user will know his default locale - shared.config.set('bitmessagesettings', 'userlocale', str(locale.getdefaultlocale()[0])) - except: - # if we cannot determine the default locale let's default to english - # they user might use this as an country code - shared.config.set('bitmessagesettings', 'userlocale', 'en_US') + shared.config.set('bitmessagesettings', 'userlocale', 'system') ensureNamecoinOptions() if storeConfigFilesInSameDirectoryAsProgramByDefault: diff --git a/src/translations/bitmessage_en_pirate.ts b/src/translations/bitmessage_en_pirate.ts index a0311eba..496b7d64 100644 --- a/src/translations/bitmessage_en_pirate.ts +++ b/src/translations/bitmessage_en_pirate.ts @@ -1,6 +1,6 @@ - + MainWindow diff --git a/src/translations/bitmessage_fr.pro~HEAD b/src/translations/bitmessage_fr.pro similarity index 100% rename from src/translations/bitmessage_fr.pro~HEAD rename to src/translations/bitmessage_fr.pro