diff --git a/src/freeseer/frontend/configtool/configtool.py b/src/freeseer/frontend/configtool/configtool.py index 348fb582..34997220 100644 --- a/src/freeseer/frontend/configtool/configtool.py +++ b/src/freeseer/frontend/configtool/configtool.py @@ -55,11 +55,10 @@ class ConfigToolApp(FreeseerApp): ''' def __init__(self, profile, config): - FreeseerApp.__init__(self) + super(ConfigToolApp, self).__init__(config) # Load Config Stuff self.profile = profile - self.config = config icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/freeseer/logo.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) diff --git a/src/freeseer/frontend/qtcommon/FreeseerApp.py b/src/freeseer/frontend/qtcommon/FreeseerApp.py index fa64dbb9..495d1596 100644 --- a/src/freeseer/frontend/qtcommon/FreeseerApp.py +++ b/src/freeseer/frontend/qtcommon/FreeseerApp.py @@ -54,8 +54,9 @@ class FreeseerApp(QMainWindow): - def __init__(self): + def __init__(self, config): super(FreeseerApp, self).__init__() + self.config = config self.icon = QIcon() self.icon.addPixmap(QPixmap(_fromUtf8(":/freeseer/logo.png")), QIcon.Normal, QIcon.Off) self.setWindowIcon(self.icon) @@ -182,6 +183,3 @@ def setupLanguageMenu(self): languageAction.setData(language) self.menuLanguage.addAction(languageAction) self.langActionGroup.addAction(languageAction) - - if self.current_language == str(language).strip("tr_").rstrip(".qm"): - languageAction.setChecked(True) diff --git a/src/freeseer/frontend/record/record.py b/src/freeseer/frontend/record/record.py index a66cb395..bdebf434 100644 --- a/src/freeseer/frontend/record/record.py +++ b/src/freeseer/frontend/record/record.py @@ -54,10 +54,9 @@ class RecordApp(FreeseerApp): """Freeseer's main GUI class.""" def __init__(self, profile, config): - FreeseerApp.__init__(self) + super(RecordApp, self).__init__(config) self.db = profile.get_database() - self.config = config self.controller = RecordingController(profile, self.db, self.config) self.recently_recorded_video = None diff --git a/src/freeseer/frontend/reporteditor/reporteditor.py b/src/freeseer/frontend/reporteditor/reporteditor.py index c34ace45..1c14f127 100644 --- a/src/freeseer/frontend/reporteditor/reporteditor.py +++ b/src/freeseer/frontend/reporteditor/reporteditor.py @@ -55,9 +55,8 @@ class ReportEditorApp(FreeseerApp): ''' def __init__(self, config, db): - FreeseerApp.__init__(self) + super(ReportEditorApp, self).__init__(config) - self.config = config self.db = db icon = QIcon() diff --git a/src/freeseer/frontend/talkeditor/talkeditor.py b/src/freeseer/frontend/talkeditor/talkeditor.py index a548abd0..8bfb68e8 100644 --- a/src/freeseer/frontend/talkeditor/talkeditor.py +++ b/src/freeseer/frontend/talkeditor/talkeditor.py @@ -59,9 +59,8 @@ class TalkEditorApp(FreeseerApp): '''Freeseer talk database editor main gui class''' def __init__(self, config, db): - FreeseerApp.__init__(self) + super(TalkEditorApp, self).__init__(config) - self.config = config self.db = db icon = QIcon() diff --git a/src/freeseer/settings.py b/src/freeseer/settings.py index 987fc18a..042c76f4 100644 --- a/src/freeseer/settings.py +++ b/src/freeseer/settings.py @@ -24,6 +24,8 @@ import os +from PyQt4.QtCore import QLocale + from freeseer.framework.config.core import Config from freeseer.framework.config.profile import ProfileManager import freeseer.framework.config.options as options @@ -36,6 +38,26 @@ profile_manager = ProfileManager(os.path.join(configdir, 'profiles')) +def detect_system_language(): + """Detect the system language""" + + current_language = 'tr_{}'.format(QLocale.system().name()) + tr_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), + 'frontend', + 'qtcommon', + 'languages') + tr_file_with_country = os.path.join(tr_path, + '{}.ts'.format(current_language)) + tr_file_language_only = os.path.join(tr_path, + '{}.ts'.format(current_language[:-3])) + if os.path.isfile(tr_file_with_country): + return '{}.qm'.format(current_language) + elif os.path.isfile(tr_file_language_only): + return '{}.qm'.format(current_language[:-3]) + else: + return 'tr_en_US.qm' + + class FreeseerConfig(Config): """General Freeseer profile settings.""" @@ -51,4 +73,4 @@ class FreeseerConfig(Config): record_to_stream_plugin = options.StringOption('RTMP Streaming') audio_feedback = options.BooleanOption(False) video_preview = options.BooleanOption(True) - default_language = options.StringOption('tr_en_US.qm') + default_language = options.StringOption(detect_system_language()) diff --git a/src/freeseer/tests/test_settings.py b/src/freeseer/tests/test_settings.py new file mode 100644 index 00000000..0aabc7ed --- /dev/null +++ b/src/freeseer/tests/test_settings.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# freeseer - vga/presentation capture software +# +# Copyright (C) 2014 Free and Open Source Software Learning Centre +# http://fosslc.org +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# For support, questions, suggestions or any other inquiries, visit: +# http://wiki.github.com/Freeseer/freeseer/ + +import pytest + +from PyQt4.QtCore import QLocale + +from freeseer.settings import detect_system_language + + +class TestSettings: + """ Test Class for settings.py unit test""" + + def test_detect_system_language_translation_found(self, monkeypatch): + """Tests detect_system_language() returns the appropriate translation filename for the system language.""" + locales = ("ar_EG", "de_DE", "en_US", "fr_CA", + "ja", "nl_NL", "sv_SE", "zh_CN", "zh_HK") + for locale in locales: + monkeypatch.setattr(QLocale, "name", + lambda x: locale) + assert detect_system_language() == "tr_{}.qm".format(locale) + + def test_detect_system_language_translation_not_found(self, monkeypatch): + """Tests detect_system_language() returns default if no translation found for system language.""" + monkeypatch.setattr(QLocale, "name", + lambda x: "fr_FR") + assert detect_system_language() == "tr_en_US.qm"