Merge pull request #736 from digital-dreamer/translate-without-restart

Change interface language without restart
This commit is contained in:
Jonathan Warren 2014-12-25 21:35:22 -05:00
commit 4aded87837

View File

@ -155,6 +155,17 @@ def avatarize(address):
# If no avatar is found
return identiconize(address)
def change_translation(locale):
global qtranslator
qtranslator = QtCore.QTranslator()
translationpath = os.path.join(
getattr(sys, '_MEIPASS', sys.path[0]),
'translations',
'bitmessage_' + locale
)
qtranslator.load(translationpath)
QtGui.QApplication.installTranslator(qtranslator)
class MyForm(QtGui.QMainWindow):
@ -1423,6 +1434,8 @@ class MyForm(QtGui.QMainWindow):
self.click_actionSettings()
def changeEvent(self, event):
if event.type() == QtCore.QEvent.LanguageChange:
self.ui.retranslateUi(self)
if event.type() == QtCore.QEvent.WindowStateChange:
if self.windowState() & QtCore.Qt.WindowMinimized:
self.actionShow.setChecked(False)
@ -2279,6 +2292,7 @@ class MyForm(QtGui.QMainWindow):
lang_ind = int(self.settingsDialogInstance.ui.languageComboBox.currentIndex())
if not languages[lang_ind] == 'other':
shared.config.set('bitmessagesettings', 'userlocale', languages[lang_ind])
change_translation(languages[lang_ind])
if int(shared.config.get('bitmessagesettings', 'port')) != int(self.settingsDialogInstance.ui.lineEditTCPPort.text()):
if not shared.safeConfigGetBoolean('bitmessagesettings', 'dontconnect'):
@ -3837,16 +3851,7 @@ class UISignaler(QThread):
def run():
app = QtGui.QApplication(sys.argv)
translator = QtCore.QTranslator()
translationpath = os.path.join(
getattr(sys, '_MEIPASS', sys.path[0]),
'translations',
'bitmessage_' + l10n.getTranslationLanguage()
)
translator.load(translationpath)
QtGui.QApplication.installTranslator(translator)
change_translation(l10n.getTranslationLanguage())
app.setStyleSheet("QStatusBar::item { border: 0px solid black }")
myapp = MyForm()