Enable user-set loclization. There is a checkbox in the settings to switch this on and off. The text field in the settings can be filled with the appropriate language code.

I've set it to degrade to language codes in both the user-set locale and the imported default locale, e.g. if there is no 'en_US' then use 'en' (like grant olsons commit).
This commit is contained in:
sendiulo 2013-08-21 16:08:22 +02:00
parent 7772484da9
commit a6b946f5be
3 changed files with 63 additions and 7 deletions

View File

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

View File

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

View File

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