corrections

This commit is contained in:
rimach 2010-04-19 21:12:34 +02:00
parent ea64675d65
commit fe66e37a57
4 changed files with 4884 additions and 34 deletions

View File

@ -194,8 +194,8 @@ def main():
# Now create and actually run the application. # Now create and actually run the application.
app = OpenLP(qt_args) app = OpenLP(qt_args)
#i18n Set Language #i18n Set Language
language = LanguageManager.getLanguage() language = LanguageManager.get_language()
appTranslator = LanguageManager.getTranslator(language) appTranslator = LanguageManager.get_translator(language)
app.installTranslator(appTranslator) app.installTranslator(appTranslator)
sys.exit(app.run()) sys.exit(app.run())

View File

@ -262,14 +262,14 @@ class Ui_MainWindow(object):
self.AutoLanguageItem.setObjectName(u'AutoLanguageItem') self.AutoLanguageItem.setObjectName(u'AutoLanguageItem')
self.AutoLanguageItem.setCheckable(True) self.AutoLanguageItem.setCheckable(True)
self.LanguageGroup = QtGui.QActionGroup(MainWindow) self.LanguageGroup = QtGui.QActionGroup(MainWindow)
qmList = LanguageManager.getQmList() qmList = LanguageManager.get_qm_list()
savedLanguage = LanguageManager.getLanguage() savedLanguage = LanguageManager.get_language()
self.LanguageItem = {} self.LanguageItem = {}
for key in qmList.keys(): for key in qmList.keys():
self.LanguageItem[key] = QtGui.QAction(MainWindow) self.LanguageItem[key] = QtGui.QAction(MainWindow)
self.LanguageItem[key].setObjectName(key) self.LanguageItem[key].setObjectName(key)
self.LanguageItem[key].setCheckable(True) self.LanguageItem[key].setCheckable(True)
if LanguageManager.__AutoLanguage__ == True: if LanguageManager.AutoLanguage:
self.AutoLanguageItem.setChecked(True) self.AutoLanguageItem.setChecked(True)
self.LanguageGroup.setEnabled(False) self.LanguageGroup.setEnabled(False)
else: else:
@ -537,7 +537,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
QtCore.QObject.connect(self.AutoLanguageItem, QtCore.QObject.connect(self.AutoLanguageItem,
QtCore.SIGNAL(u'toggled(bool)'), QtCore.SIGNAL(u'toggled(bool)'),
self.setAutoLanguage) self.setAutoLanguage)
self.LanguageGroup.triggered.connect(LanguageManager.setLanguage) self.LanguageGroup.triggered.connect(LanguageManager.set_language)
#warning cyclic dependency #warning cyclic dependency
#RenderManager needs to call ThemeManager and #RenderManager needs to call ThemeManager and
#ThemeManager needs to call RenderManager #ThemeManager needs to call RenderManager
@ -582,8 +582,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
#i18n #i18n
def setAutoLanguage(self, value): def setAutoLanguage(self, value):
self.LanguageGroup.setEnabled(not value) self.LanguageGroup.setEnabled(not value)
LanguageManager.__AutoLanguage__ = value LanguageManager.AutoLanguage = value
LanguageManager.setLanguage(self.LanguageGroup.checkedAction()) LanguageManager.set_language(self.LanguageGroup.checkedAction())
def versionCheck(self, version): def versionCheck(self, version):
""" """

View File

@ -25,22 +25,23 @@
import logging import logging
from logging import FileHandler
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
import os import os
from openlp.core.utils import AppLocation, ConfigHelper from openlp.core.utils import AppLocation, ConfigHelper
#from openlp.core.ui import MainWindow
#import i18n_rc log = logging.getLogger()
class LanguageManager(object): class LanguageManager(object):
""" """
Helper for Language selection Helper for Language selection
""" """
__qmList__ = None __qmList__ = None
__AutoLanguage__ = None AutoLanguage = False
@staticmethod @staticmethod
def getTranslator(language): def get_translator(language):
if LanguageManager.__AutoLanguage__ is True: if LanguageManager.AutoLanguage :
language = QtCore.QLocale.system().name() language = QtCore.QLocale.system().name()
lang_Path = AppLocation.get_directory(AppLocation.AppDir) lang_Path = AppLocation.get_directory(AppLocation.AppDir)
lang_Path = os.path.join(lang_Path, u'resources', u'i18n') lang_Path = os.path.join(lang_Path, u'resources', u'i18n')
@ -49,7 +50,7 @@ class LanguageManager(object):
return appTranslator return appTranslator
@staticmethod @staticmethod
def findQmFiles(): def find_qm_files():
trans_dir = AppLocation.get_directory(AppLocation.AppDir) trans_dir = AppLocation.get_directory(AppLocation.AppDir)
trans_dir = QtCore.QDir(os.path.join(trans_dir, u'resources', u'i18n')) trans_dir = QtCore.QDir(os.path.join(trans_dir, u'resources', u'i18n'))
fileNames = trans_dir.entryList(QtCore.QStringList("*.qm"), fileNames = trans_dir.entryList(QtCore.QStringList("*.qm"),
@ -59,48 +60,49 @@ class LanguageManager(object):
return fileNames return fileNames
@staticmethod @staticmethod
def languageName(qmFile): def language_name(qmFile):
translator = QtCore.QTranslator() translator = QtCore.QTranslator()
translator.load(qmFile) translator.load(qmFile)
return translator.translate(u'MainWindow', u'English') return translator.translate(u'MainWindow', u'English')
@staticmethod @staticmethod
def getLanguage(): def get_language():
language = ConfigHelper.get_registry().get_value(u'general', u'language', u'[en]') language = ConfigHelper.get_registry().get_value(u'general',
print "getLanguage %s" % language u'language', u'[en]')
log.info(u'Language file: \'%s\' Loaded from conf file' % language)
regEx = QtCore.QRegExp("^\[(.*)\]") regEx = QtCore.QRegExp("^\[(.*)\]")
if regEx.exactMatch(language): if regEx.exactMatch(language):
LanguageManager.__AutoLanguage__ = True LanguageManager.AutoLanguage = True
language = regEx.cap(1) language = regEx.cap(1)
return language return language
@staticmethod @staticmethod
def setLanguage(action): def set_language(action):
actionName = u'%s' % action.objectName() actionName = u'%s' % action.objectName()
qmList = LanguageManager.getQmList() qmList = LanguageManager.get_qm_list()
if LanguageManager.__AutoLanguage__ == True: if LanguageManager.AutoLanguage :
language = u'[%s]' % qmList[actionName] language = u'[%s]' % qmList[actionName]
else: else:
language = u'%s' % qmList[actionName] language = u'%s' % qmList[actionName]
print "setLanguage: %s" % language log.info(u'Language file: \'%s\' written to conf file' % language)
ConfigHelper.set_config(u'general', u'language', language) ConfigHelper.set_config(u'general', u'language', language)
QtGui.QMessageBox.information(None, QtGui.QMessageBox.information(None,
u'Language', u'After restart new Language settings will be used.') u'Language',
u'After restart new Language settings will be used.')
@staticmethod @staticmethod
def initQmList(): def init_qm_list():
LanguageManager.__qmList__ = {} LanguageManager.__qmList__ = {}
qmFiles = LanguageManager.findQmFiles() qmFiles = LanguageManager.find_qm_files()
for i, qmf in enumerate(qmFiles): for i, qmf in enumerate(qmFiles):
regEx = QtCore.QRegExp("^.*openlp_(.*).qm") regEx = QtCore.QRegExp("^.*openlp_(.*).qm")
if regEx.exactMatch(qmf): if regEx.exactMatch(qmf):
langName = regEx.cap(1) langName = regEx.cap(1)
LanguageManager.__qmList__[u'%i %s' % (i, LanguageManager.languageName(qmf))] = langName LanguageManager.__qmList__[u'%i %s' % (i,
LanguageManager.language_name(qmf))] = langName
@staticmethod @staticmethod
def getQmList(): def get_qm_list():
if LanguageManager.__qmList__ == None: if LanguageManager.__qmList__ == None:
LanguageManager.initQmList() LanguageManager.init_qm_list()
return LanguageManager.__qmList__ return LanguageManager.__qmList__

4848
resources/i18n/openlp_en.ts Normal file

File diff suppressed because it is too large Load Diff