diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 378989e0..1cb13e34 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2031,6 +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())) 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( @@ -3041,6 +3045,10 @@ 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'))) if shared.appdata == '': self.ui.checkBoxPortableMode.setChecked(True) if 'darwin' in sys.platform: @@ -3404,13 +3412,41 @@ else: def run(): app = QtGui.QApplication(sys.argv) translator = QtCore.QTranslator() - - try: - translator.load("translations/bitmessage_" + str(locale.getdefaultlocale()[0])) - #translator.load("translations/bitmessage_fr_BE") # test French - except: - # The above is not compatible with all versions of OSX. - translator.load("translations/bitmessage_en_US") # Default to english. + + local_countrycode = str(locale.getdefaultlocale()[0]) + locale_lang = local_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 + try: + # check if the user input is a valid translation file + # this would also capture weird "countrycodes" like "en_pirate" or just "pirate" + 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" + 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. 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 87e8ba7b..8d2cf677 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -71,6 +71,14 @@ class Ui_settingsDialog(object): 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.tabWidgetSettings.addTab(self.tabUserInterface, _fromUtf8("")) self.tabNetworkSettings = QtGui.QWidget() self.tabNetworkSettings.setObjectName(_fromUtf8("tabNetworkSettings")) @@ -305,6 +313,7 @@ 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) @@ -331,6 +340,7 @@ class Ui_settingsDialog(object): self.checkBoxStartOnLogon.setText(_translate("settingsDialog", "Start Bitmessage on user login", None)) self.checkBoxPortableMode.setText(_translate("settingsDialog", "Run in Portable Mode", 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.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabUserInterface), _translate("settingsDialog", "User Interface", None)) self.groupBox.setTitle(_translate("settingsDialog", "Listening port", None)) self.label.setText(_translate("settingsDialog", "Listen for connections on port:", None)) diff --git a/src/helper_startup.py b/src/helper_startup.py index 256dbcaa..67ae8d8c 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -2,6 +2,7 @@ import shared import ConfigParser import sys import os +import locale from namecoin import ensureNamecoinOptions @@ -69,6 +70,15 @@ 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') ensureNamecoinOptions() if storeConfigFilesInSameDirectoryAsProgramByDefault: