From a38a4fc938d4262191d7c965ead396b014e4ff77 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Sat, 24 Jan 2009 20:26:23 +0100 Subject: [PATCH] Add configuration option to select the user interface language. Fixes #4194 --- picard/const.py | 36 +++++++++++++++++++++++++++++++ picard/tagger.py | 3 +++ picard/ui/options/interface.py | 21 +++++++++++++++++- picard/ui/ui_options_interface.py | 29 ++++++++++++++----------- ui/options_interface.ui | 33 +++++++++++++++++++++++++--- 5 files changed, 106 insertions(+), 16 deletions(-) diff --git a/picard/const.py b/picard/const.py index 4f0759272..f233d101a 100644 --- a/picard/const.py +++ b/picard/const.py @@ -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')), +] diff --git a/picard/tagger.py b/picard/tagger.py index 5ed269ef2..a8c9bbb9c 100644 --- a/picard/tagger.py +++ b/picard/tagger.py @@ -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"]) diff --git a/picard/ui/options/interface.py b/picard/ui/options/interface.py index 68dd939f3..401a74183 100644 --- a/picard/ui/options/interface.py +++ b/picard/ui/options/interface.py @@ -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) diff --git a/picard/ui/ui_options_interface.py b/picard/ui/ui_options_interface.py index 4867a17ef..e504c661f 100644 --- a/picard/ui/ui_options_interface.py +++ b/picard/ui/ui_options_interface.py @@ -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:")) diff --git a/ui/options_interface.ui b/ui/options_interface.ui index c78701ac6..295c295e6 100644 --- a/ui/options_interface.ui +++ b/ui/options_interface.ui @@ -5,8 +5,8 @@ 0 0 - 276 - 196 + 287 + 200 @@ -37,6 +37,33 @@ + + + + User interface language: + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -45,7 +72,7 @@ Qt::Vertical - + 220 61