Select Language at startup

This commit is contained in:
Tim Bentley 2011-02-27 09:53:47 +00:00
parent 289ce0de5f
commit f295ac5407
4 changed files with 41 additions and 12 deletions

View File

@ -276,8 +276,10 @@ def main():
if QtCore.QSettings().value( if QtCore.QSettings().value(
u'general/first time', QtCore.QVariant(True)).toBool(): u'general/first time', QtCore.QVariant(True)).toBool():
FirstTimeForm().exec_() FirstTimeForm().exec_()
pass
# i18n Set Language # i18n Set Language
language = LanguageManager.get_language() language = LanguageManager.get_language()
print language
appTranslator = LanguageManager.get_translator(language) appTranslator = LanguageManager.get_translator(language)
app.installTranslator(appTranslator) app.installTranslator(appTranslator)
if not options.no_error_form: if not options.no_error_form:

View File

@ -69,6 +69,8 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
else: else:
self.internetGroupBox.setVisible(False) self.internetGroupBox.setVisible(False)
self.noInternetLabel.setVisible(True) self.noInternetLabel.setVisible(True)
if LanguageManager.auto_language:
self.LanguageComboBox.setEnabled(False)
self.qmList = LanguageManager.get_qm_list() self.qmList = LanguageManager.get_qm_list()
for key in sorted(self.qmList.keys()): for key in sorted(self.qmList.keys()):
self.LanguageComboBox.addItem(key) self.LanguageComboBox.addItem(key)
@ -83,8 +85,14 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.__pluginStatus(self.customCheckBox, u'custom/status') self.__pluginStatus(self.customCheckBox, u'custom/status')
self.__pluginStatus(self.songUsageCheckBox, u'songusage/status') self.__pluginStatus(self.songUsageCheckBox, u'songusage/status')
self.__pluginStatus(self.alertCheckBox, u'alerts/status') self.__pluginStatus(self.alertCheckBox, u'alerts/status')
if self.autoLanguageCheckBox.checkState() == QtCore.Qt.Checked:
print self.qmList[unicode(self.LanguageComboBox.currentText())] LanguageManager.auto_language = True
LanguageManager.set_language(False, False)
else:
LanguageManager.auto_language = False
action = QtGui.QAction(None)
action.setObjectName(unicode(self.LanguageComboBox.currentText()))
LanguageManager.set_language(action, False)
return QtGui.QWizard.accept(self) return QtGui.QWizard.accept(self)
def __pluginStatus(self, field, tag): def __pluginStatus(self, field, tag):

View File

@ -99,16 +99,20 @@ class LanguageManager(object):
return language return language
@staticmethod @staticmethod
def set_language(action): def set_language(action, message=True):
""" """
Set the language to translate OpenLP into Set the language to translate OpenLP into
``action`` ``action``
The language menu option The language menu option
``message``
Display the message option
""" """
language = u'en' language = u'en'
if action: if action:
action_name = u'%s' % action.objectName() action_name = u'%s' % action.objectName()
print action_name
qm_list = LanguageManager.get_qm_list() qm_list = LanguageManager.get_qm_list()
language = u'%s' % qm_list[action_name] language = u'%s' % qm_list[action_name]
if LanguageManager.auto_language: if LanguageManager.auto_language:
@ -116,10 +120,11 @@ class LanguageManager(object):
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)
QtGui.QMessageBox.information(None, if message:
translate('OpenLP.LanguageManager', 'Language'), QtGui.QMessageBox.information(None,
translate('OpenLP.LanguageManager', translate('OpenLP.LanguageManager', 'Language'),
'Please restart OpenLP to use your new language setting.')) translate('OpenLP.LanguageManager',
'Please restart OpenLP to use your new language setting.'))
@staticmethod @staticmethod
def init_qm_list(): def init_qm_list():

View File

@ -300,8 +300,8 @@ p, li { white-space: pre-wrap; }
<rect> <rect>
<x>20</x> <x>20</x>
<y>20</y> <y>20</y>
<width>252</width> <width>491</width>
<height>88</height> <height>113</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
@ -339,15 +339,29 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="3" column="0">
<widget class="QLabel" name="languageLabel"> <widget class="QLabel" name="languageLabel">
<property name="text"> <property name="text">
<string>Select default language</string> <string>Select default language</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="3" column="1">
<widget class="QComboBox" name="LanguageComboBox"/> <widget class="QComboBox" name="LanguageComboBox">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="autoLanguageCheckBox">
<property name="text">
<string>Auto Language</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>