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
This commit is contained in:
sendiulo 2013-08-24 09:07:46 +02:00
parent 383cc59991
commit da93d1d8b4
6 changed files with 176 additions and 113 deletions

View File

@ -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 }")

View File

@ -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_())

View File

@ -37,17 +37,17 @@
<string>User Interface</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="7" column="0">
<widget class="QLabel" name="labelSettingsNote">
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxMinimizeToTray">
<property name="text">
<string/>
<string>Minimize to tray</string>
</property>
<property name="wordWrap">
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="8" column="0">
<item row="10" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -60,10 +60,10 @@
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBoxStartInTray">
<item row="0" column="0">
<widget class="QCheckBox" name="checkBoxStartOnLogon">
<property name="text">
<string>Start Bitmessage in the tray (don't show main window)</string>
<string>Start Bitmessage on user login</string>
</property>
</widget>
</item>
@ -74,18 +74,22 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxMinimizeToTray">
<item row="4" column="0">
<widget class="QCheckBox" name="checkBoxPortableMode">
<property name="text">
<string>Minimize to tray</string>
</property>
<property name="checked">
<bool>true</bool>
<string>Run in Portable Mode</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_7">
<item row="1" column="0">
<widget class="QCheckBox" name="checkBoxStartInTray">
<property name="text">
<string>Start Bitmessage in the tray (don't show main window)</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="PortableModeDescription">
<property name="text">
<string>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.</string>
</property>
@ -94,27 +98,66 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkBoxStartOnLogon">
<property name="text">
<string>Start Bitmessage on user login</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="checkBoxPortableMode">
<property name="text">
<string>Run in Portable Mode</string>
</property>
</widget>
</item>
<item row="6" column="0">
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxWillinglySendToMobile">
<property name="text">
<string>Willingly include unencrypted destination address when sending to a mobile device</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Interface Language</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QComboBox" name="languageComboBox">
<item>
<property name="text">
<string comment="system">System Settings</string>
</property>
</item>
<item>
<property name="text">
<string comment="en">English</string>
</property>
</item>
<item>
<property name="text">
<string comment="eo">Esperanto</string>
</property>
</item>
<item>
<property name="text">
<string comment="fr">French</string>
</property>
</item>
<item>
<property name="text">
<string comment="de">German</string>
</property>
</item>
<item>
<property name="text">
<string comment="es">Spanish</string>
</property>
</item>
<item>
<property name="text">
<string comment="ru">Russian</string>
</property>
</item>
<item>
<property name="text">
<string comment="en_pirate">Pirate English</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabNetworkSettings">

View File

@ -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:

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="en_US" sourcelanguage="en">
<TS version="2.0" language="en_pirate" sourcelanguage="en">
<context>
<name>MainWindow</name>
<message>