forked from openlp/openlp
* Fix theme deletion
* Naming fixes * Docstrings bzr-revno: 897
This commit is contained in:
commit
e4c340b4b9
@ -168,7 +168,7 @@ class Theme(object):
|
|||||||
theme_strings.append(u'_%s_' % (getattr(self, key)))
|
theme_strings.append(u'_%s_' % (getattr(self, key)))
|
||||||
return u''.join(theme_strings)
|
return u''.join(theme_strings)
|
||||||
|
|
||||||
def _set_from_XML(self, xml):
|
def _set_from_xml(self, xml):
|
||||||
"""
|
"""
|
||||||
Set theme class attributes with data from XML
|
Set theme class attributes with data from XML
|
||||||
|
|
||||||
|
@ -22,7 +22,10 @@
|
|||||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
"""
|
||||||
|
The :mod:`languagemanager` module provides all the translation settings and
|
||||||
|
language file loading for OpenLP.
|
||||||
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -42,50 +45,74 @@ class LanguageManager(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_translator(language):
|
def get_translator(language):
|
||||||
|
"""
|
||||||
|
Set up a translator to use in this instance of OpenLP
|
||||||
|
|
||||||
|
``language``
|
||||||
|
The language to load into the translator
|
||||||
|
"""
|
||||||
if LanguageManager.AutoLanguage:
|
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')
|
||||||
appTranslator = QtCore.QTranslator()
|
app_translator = QtCore.QTranslator()
|
||||||
if appTranslator.load("openlp_" + language, lang_Path):
|
if app_translator.load("openlp_" + language, lang_Path):
|
||||||
return appTranslator
|
return app_translator
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find_qm_files():
|
def find_qm_files():
|
||||||
|
"""
|
||||||
|
Find all available language files in this OpenLP install
|
||||||
|
"""
|
||||||
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"),
|
file_names = trans_dir.entryList(QtCore.QStringList("*.qm"),
|
||||||
QtCore.QDir.Files, QtCore.QDir.Name)
|
QtCore.QDir.Files, QtCore.QDir.Name)
|
||||||
for name in fileNames:
|
for name in file_names:
|
||||||
fileNames.replaceInStrings(name, trans_dir.filePath(name))
|
file_names.replaceInStrings(name, trans_dir.filePath(name))
|
||||||
return fileNames
|
return file_names
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def language_name(qmFile):
|
def language_name(qm_file):
|
||||||
|
"""
|
||||||
|
Load the language name from a language file
|
||||||
|
|
||||||
|
``qm_file``
|
||||||
|
The file to obtain the name from
|
||||||
|
"""
|
||||||
translator = QtCore.QTranslator()
|
translator = QtCore.QTranslator()
|
||||||
translator.load(qmFile)
|
translator.load(qm_file)
|
||||||
return translator.translate('MainWindow', 'English')
|
return translator.translate('MainWindow', 'English')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_language():
|
def get_language():
|
||||||
|
"""
|
||||||
|
Retrieve a saved language to use from settings
|
||||||
|
"""
|
||||||
settings = QtCore.QSettings(u'OpenLP', u'OpenLP')
|
settings = QtCore.QSettings(u'OpenLP', u'OpenLP')
|
||||||
language = unicode(settings.value(
|
language = unicode(settings.value(
|
||||||
u'general/language', QtCore.QVariant(u'[en]')).toString())
|
u'general/language', QtCore.QVariant(u'[en]')).toString())
|
||||||
log.info(u'Language file: \'%s\' Loaded from conf file' % language)
|
log.info(u'Language file: \'%s\' Loaded from conf file' % language)
|
||||||
regEx = QtCore.QRegExp("^\[(.*)\]")
|
reg_ex = QtCore.QRegExp("^\[(.*)\]")
|
||||||
if regEx.exactMatch(language):
|
if reg_ex.exactMatch(language):
|
||||||
LanguageManager.AutoLanguage = True
|
LanguageManager.AutoLanguage = True
|
||||||
language = regEx.cap(1)
|
language = reg_ex.cap(1)
|
||||||
return language
|
return language
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_language(action):
|
def set_language(action):
|
||||||
actionName = u'%s' % action.objectName()
|
"""
|
||||||
qmList = LanguageManager.get_qm_list()
|
Set the language to translate OpenLP into
|
||||||
|
|
||||||
|
``action``
|
||||||
|
The language menu option
|
||||||
|
"""
|
||||||
|
action_name = u'%s' % action.objectName()
|
||||||
|
qm_list = LanguageManager.get_qm_list()
|
||||||
if LanguageManager.AutoLanguage:
|
if LanguageManager.AutoLanguage:
|
||||||
language = u'[%s]' % qmList[actionName]
|
language = u'[%s]' % qm_list[action_name]
|
||||||
else:
|
else:
|
||||||
language = u'%s' % qmList[actionName]
|
language = u'%s' % qm_list[action_name]
|
||||||
QtCore.QSettings().setValue(
|
QtCore.QSettings().setValue(
|
||||||
u'general/language', QtCore.QVariant(language))
|
u'general/language', QtCore.QVariant(language))
|
||||||
log.info(u'Language file: \'%s\' written to conf file' % language)
|
log.info(u'Language file: \'%s\' written to conf file' % language)
|
||||||
@ -96,17 +123,23 @@ class LanguageManager(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def init_qm_list():
|
def init_qm_list():
|
||||||
|
"""
|
||||||
|
Initialise the list of available translations
|
||||||
|
"""
|
||||||
LanguageManager.__qmList__ = {}
|
LanguageManager.__qmList__ = {}
|
||||||
qmFiles = LanguageManager.find_qm_files()
|
qm_files = LanguageManager.find_qm_files()
|
||||||
for i, qmf in enumerate(qmFiles):
|
for i, qmf in enumerate(qm_files):
|
||||||
regEx = QtCore.QRegExp("^.*openlp_(.*).qm")
|
reg_ex = QtCore.QRegExp("^.*openlp_(.*).qm")
|
||||||
if regEx.exactMatch(qmf):
|
if reg_ex.exactMatch(qmf):
|
||||||
langName = regEx.cap(1)
|
lang_name = reg_ex.cap(1)
|
||||||
LanguageManager.__qmList__[u'%#2i %s' % (i+1,
|
LanguageManager.__qmList__[u'%#2i %s' % (i+1,
|
||||||
LanguageManager.language_name(qmf))] = langName
|
LanguageManager.language_name(qmf))] = lang_name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_qm_list():
|
def get_qm_list():
|
||||||
|
"""
|
||||||
|
Return the list of available translations
|
||||||
|
"""
|
||||||
if LanguageManager.__qmList__ is None:
|
if LanguageManager.__qmList__ is None:
|
||||||
LanguageManager.init_qm_list()
|
LanguageManager.init_qm_list()
|
||||||
return LanguageManager.__qmList__
|
return LanguageManager.__qmList__
|
||||||
|
@ -78,7 +78,7 @@ class CustomPlugin(Plugin):
|
|||||||
return about_text
|
return about_text
|
||||||
|
|
||||||
def can_delete_theme(self, theme):
|
def can_delete_theme(self, theme):
|
||||||
filter_string = u'theme_name=%s' % theme
|
filter_string = u'theme_name=\'%s\'' % theme
|
||||||
if not self.custommanager.get_all_objects_filtered(CustomSlide,
|
if not self.custommanager.get_all_objects_filtered(CustomSlide,
|
||||||
filter_string):
|
filter_string):
|
||||||
return True
|
return True
|
||||||
|
@ -199,7 +199,7 @@ class SongsPlugin(Plugin):
|
|||||||
return about_text
|
return about_text
|
||||||
|
|
||||||
def can_delete_theme(self, theme):
|
def can_delete_theme(self, theme):
|
||||||
filter_string = u'theme_name=%s' % theme
|
filter_string = u'theme_name=\'%s\'' % theme
|
||||||
if not self.manager.get_all_objects_filtered(Song, filter_string):
|
if not self.manager.get_all_objects_filtered(Song, filter_string):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user