Add configuration option to select the user interface language. Fixes #4194

This commit is contained in:
Philipp Wolfer
2009-01-24 20:26:23 +01:00
parent b677d094d7
commit a38a4fc938
5 changed files with 106 additions and 16 deletions

View File

@@ -301,3 +301,39 @@ RELEASE_COUNTRIES = {
u'XW': N_('[Worldwide]'),
u'YU': N_('Yugoslavia (historical, 1918-1992)'),
}
# List of available user interface languages
UI_LANGUAGES = [
(u'ca', u'Català', N_(u'Catalan')),
(u'cs', u'Čeština', N_(u'Czech')),
(u'cy', u'Cymraeg', N_(u'Welsh')),
(u'da', u'Dansk', N_(u'Danish')),
(u'de', u'Deutsch', N_(u'German')),
(u'en', u'English', N_(u'English')),
(u'en_CA', u'English (Canada)', N_(u'English (Canada)')),
(u'en_GB', u'English (UK)', N_(u'English (UK)')),
(u'es', u'Español', N_(u'Spanish')),
(u'fa', u'فارسی', N_(u'Persian')),
(u'fi', u'Suomi', N_(u'Finnish')),
(u'fr', u'Français', N_(u'French')),
(u'fy', u'Frysk', N_(u'Frisian')),
(u'he', u'עברית', N_(u'Hebrew')),
(u'hu', u'Magyar', N_(u'Hungarian')),
(u'is', u'Íslenska', N_(u'Islandic')),
(u'it', u'Italiano', N_(u'Italian')),
(u'kn', u'ಕನ್ನಡ ', N_(u'Kannada')),
(u'ko', u'한국어', N_(u'Korean')),
(u'lt', u'Lietuvių', N_(u'Lithuanian')),
(u'nb', u'Norsk bokmål', N_(u'Norwegian Bokmal')),
(u'nl', u'Nederlands', N_(u'Dutch')),
(u'pl', u'Polski', N_(u'Polish')),
(u'pt', u'Português', N_(u'Portuguese')),
(u'pt_BR', u'Português do Brasil', N_(u'Brazilian Portuguese')),
(u'ro', u'Română', N_(u'Romanian')),
(u'ru', u'Pyccĸий', N_(u'Russian')),
(u'sco', u'Scots leid', N_(u'Scots')),
(u'sk', u'Slovenčina', N_(u'Slovak')),
(u'sl', u'Slovenščina', N_(u'Slovenian')),
(u'sv', u'Svenska', N_(u'Swedish')),
(u'zh_CN', u'中文', N_(u'Chinese')),
]

View File

@@ -204,6 +204,9 @@ class Tagger(QtGui.QApplication):
def setup_gettext(self, localedir):
"""Setup locales, load translations, install gettext functions."""
if self.config.setting["ui_language"]:
os.environ['LANGUAGE'] = ''
os.environ['LANG'] = self.config.setting["ui_language"]
if sys.platform == "win32":
try:
locale.setlocale(locale.LC_ALL, os.environ["LANG"])

View File

@@ -17,9 +17,12 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from picard.config import BoolOption
from PyQt4 import QtCore, QtGui
from picard.config import BoolOption, TextOption
from picard.ui.options import OptionsPage, register_options_page
from picard.ui.ui_options_interface import Ui_InterfaceOptionsPage
from picard.const import UI_LANGUAGES
import operator
class InterfaceOptionsPage(OptionsPage):
@@ -34,23 +37,39 @@ class InterfaceOptionsPage(OptionsPage):
BoolOption("setting", "toolbar_show_labels", True),
BoolOption("setting", "toolbar_multiselect", False),
BoolOption("setting", "use_adv_search_syntax", False),
TextOption("setting", "ui_language", u""),
]
def __init__(self, parent=None):
super(InterfaceOptionsPage, self).__init__(parent)
self.ui = Ui_InterfaceOptionsPage()
self.ui.setupUi(self)
self.ui.ui_language.addItem(_('System default'), QtCore.QVariant(''))
language_list = [(l[0], l[1], _(l[2])) for l in UI_LANGUAGES]
for lang_code, native, translation in sorted(language_list, key=operator.itemgetter(2)):
if native and native != translation:
name = u'%s (%s)' % (translation, native)
else:
name = translation
self.ui.ui_language.addItem(name, QtCore.QVariant(lang_code))
def load(self):
self.ui.toolbar_show_labels.setChecked(self.config.setting["toolbar_show_labels"])
self.ui.toolbar_multiselect.setChecked(self.config.setting["toolbar_multiselect"])
self.ui.use_adv_search_syntax.setChecked(self.config.setting["use_adv_search_syntax"])
current_ui_language = QtCore.QVariant(self.config.setting["ui_language"])
self.ui.ui_language.setCurrentIndex(self.ui.ui_language.findData(current_ui_language))
def save(self):
self.config.setting["toolbar_show_labels"] = self.ui.toolbar_show_labels.isChecked()
self.config.setting["toolbar_multiselect"] = self.ui.toolbar_multiselect.isChecked()
self.config.setting["use_adv_search_syntax"] = self.ui.use_adv_search_syntax.isChecked()
self.tagger.window.update_toolbar_style()
new_language = self.ui.ui_language.itemData(self.ui.ui_language.currentIndex()).toString()
if new_language != self.config.setting["ui_language"]:
self.config.setting["ui_language"] = self.ui.ui_language.itemData(self.ui.ui_language.currentIndex()).toString()
dialog = QtGui.QMessageBox(QtGui.QMessageBox.Information, _('Language changed'), _('You have changed the interface language. You have to restart Picard in order for the change to take effect.'), QtGui.QMessageBox.Ok, self)
dialog.exec_()
register_options_page(InterfaceOptionsPage)

View File

@@ -2,8 +2,8 @@
# Form implementation generated from reading ui file 'ui/options_interface.ui'
#
# Created: Fri Mar 28 08:55:16 2008
# by: PyQt4 UI code generator 4.3
# Created: Sat Jan 24 18:12:02 2009
# by: PyQt4 UI code generator 4.4.3
#
# WARNING! All changes made in this file will be lost!
@@ -12,32 +12,36 @@ from PyQt4 import QtCore, QtGui
class Ui_InterfaceOptionsPage(object):
def setupUi(self, InterfaceOptionsPage):
InterfaceOptionsPage.setObjectName("InterfaceOptionsPage")
InterfaceOptionsPage.resize(QtCore.QSize(QtCore.QRect(0,0,276,196).size()).expandedTo(InterfaceOptionsPage.minimumSizeHint()))
InterfaceOptionsPage.resize(287, 200)
self.vboxlayout = QtGui.QVBoxLayout(InterfaceOptionsPage)
self.vboxlayout.setObjectName("vboxlayout")
self.groupBox_2 = QtGui.QGroupBox(InterfaceOptionsPage)
self.groupBox_2.setObjectName("groupBox_2")
self.vboxlayout1 = QtGui.QVBoxLayout(self.groupBox_2)
self.vboxlayout1.setObjectName("vboxlayout1")
self.toolbar_show_labels = QtGui.QCheckBox(self.groupBox_2)
self.toolbar_show_labels.setObjectName("toolbar_show_labels")
self.vboxlayout1.addWidget(self.toolbar_show_labels)
self.toolbar_multiselect = QtGui.QCheckBox(self.groupBox_2)
self.toolbar_multiselect.setObjectName("toolbar_multiselect")
self.vboxlayout1.addWidget(self.toolbar_multiselect)
self.use_adv_search_syntax = QtGui.QCheckBox(self.groupBox_2)
self.use_adv_search_syntax.setObjectName("use_adv_search_syntax")
self.vboxlayout1.addWidget(self.use_adv_search_syntax)
self.label = QtGui.QLabel(self.groupBox_2)
self.label.setObjectName("label")
self.vboxlayout1.addWidget(self.label)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.ui_language = QtGui.QComboBox(self.groupBox_2)
self.ui_language.setObjectName("ui_language")
self.horizontalLayout.addWidget(self.ui_language)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.vboxlayout1.addLayout(self.horizontalLayout)
self.vboxlayout.addWidget(self.groupBox_2)
spacerItem = QtGui.QSpacerItem(220,61,QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Expanding)
self.vboxlayout.addItem(spacerItem)
spacerItem1 = QtGui.QSpacerItem(220, 61, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.vboxlayout.addItem(spacerItem1)
self.retranslateUi(InterfaceOptionsPage)
QtCore.QMetaObject.connectSlotsByName(InterfaceOptionsPage)
@@ -47,4 +51,5 @@ class Ui_InterfaceOptionsPage(object):
self.toolbar_show_labels.setText(_("Show text labels under icons"))
self.toolbar_multiselect.setText(_("Allow selection of multiple directories"))
self.use_adv_search_syntax.setText(_("Use advanced query syntax"))
self.label.setText(_("User interface language:"))

View File

@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>276</width>
<height>196</height>
<width>287</width>
<height>200</height>
</rect>
</property>
<layout class="QVBoxLayout" >
@@ -37,6 +37,33 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>User interface language:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QComboBox" name="ui_language" />
</item>
<item>
<spacer name="horizontalSpacer" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@@ -45,7 +72,7 @@
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>220</width>
<height>61</height>