Peter Surda
fd4329bee0
The language combo box is generated dynamically from the list of available translations in the translations directory. This allows the users to add their own translations without having to change the code.
41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
import glob
|
|
import os
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
from debug import logger
|
|
from shared import codePath, config
|
|
|
|
class LanguageBox(QtGui.QComboBox):
|
|
languageName = {"system": "System Settings", "eo": "Esperanto", "en_pirate": "Pirate English"}
|
|
def __init__(self, parent = None):
|
|
super(QtGui.QComboBox, self).__init__(parent)
|
|
self.populate()
|
|
|
|
def populate(self):
|
|
self.languages = []
|
|
self.clear()
|
|
localesPath = os.path.join (codePath(), 'translations')
|
|
configuredLocale = "system"
|
|
try:
|
|
configuredLocale = config.get('bitmessagesettings', 'userlocale', "system")
|
|
except:
|
|
pass
|
|
self.addItem(QtGui.QApplication.translate("settingsDialog", "System Settings", "system"), "system")
|
|
self.setCurrentIndex(0)
|
|
self.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
|
|
for translationFile in sorted(glob.glob(os.path.join(localesPath, "bitmessage_*.qm"))):
|
|
localeShort = os.path.split(translationFile)[1].split("_", 1)[1][:-3]
|
|
locale = QtCore.QLocale(QtCore.QString(localeShort))
|
|
if localeShort in LanguageBox.languageName:
|
|
self.addItem(LanguageBox.languageName[localeShort], localeShort)
|
|
elif locale.nativeLanguageName() == "":
|
|
self.addItem(localeShort, localeShort)
|
|
else:
|
|
self.addItem(locale.nativeLanguageName(), localeShort)
|
|
for i in range(self.count()):
|
|
logger.debug("Checking locale %s at %i", str(self.itemData(i).toString()), i)
|
|
if self.itemData(i) == configuredLocale:
|
|
logger.debug("Matching locale %s at %i", configuredLocale, i)
|
|
self.setCurrentIndex(i)
|
|
break
|