2016-04-15 12:12:49 +02:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
|
2017-02-22 09:34:54 +01:00
|
|
|
from bmconfigparser import BMConfigParser
|
2017-01-11 17:00:00 +01:00
|
|
|
import paths
|
2016-04-15 12:12:49 +02:00
|
|
|
|
|
|
|
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()
|
2017-01-11 17:00:00 +01:00
|
|
|
localesPath = os.path.join (paths.codePath(), 'translations')
|
2016-04-15 12:12:49 +02:00
|
|
|
configuredLocale = "system"
|
|
|
|
try:
|
2017-01-11 14:27:19 +01:00
|
|
|
configuredLocale = BMConfigParser().get('bitmessagesettings', 'userlocale', "system")
|
2016-04-15 12:12:49 +02:00
|
|
|
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()):
|
|
|
|
if self.itemData(i) == configuredLocale:
|
|
|
|
self.setCurrentIndex(i)
|
|
|
|
break
|