Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Fix #476 Auto language changing when first launch
Browse files Browse the repository at this point in the history
- Freeseer will now scan the System language for the first time.
If there is translation for the location, the interface language
will be set to that language by default. Otherwise en_US will be used.
- Unit test for this function is also added..
  • Loading branch information
Cryspia committed Nov 7, 2014
1 parent d93c4b0 commit 2fd1954
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/freeseer/frontend/configtool/configtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions src/freeseer/frontend/qtcommon/FreeseerApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
3 changes: 1 addition & 2 deletions src/freeseer/frontend/record/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/freeseer/frontend/reporteditor/reporteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions src/freeseer/frontend/talkeditor/talkeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 18 additions & 1 deletion src/freeseer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +38,21 @@
profile_manager = ProfileManager(os.path.join(configdir, 'profiles'))


def detect_system_language():
"""Detect the system language"""

translation = 'tr_{}'.format(QLocale.system().name())
translation_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'frontend', 'qtcommon', 'languages')
translation_country_language = os.path.join(translation_path, '{}.ts'.format(translation))
translation_language = os.path.join(translation_path, '{}.ts'.format(translation.split('-')[0]))
if os.path.isfile(translation_country_language):
return '{}.qm'.format(translation)
elif os.path.isfile(translation_language):
return '{}.qm'.format(translation.split('-')[0])
else:
return 'tr_en_US.qm'


class FreeseerConfig(Config):
"""General Freeseer profile settings."""

Expand All @@ -51,4 +68,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())
43 changes: 43 additions & 0 deletions src/freeseer/tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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 <http://www.gnu.org/licenses/>.

# For support, questions, suggestions or any other inquiries, visit:
# http://wiki.github.com/Freeseer/freeseer/

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"

0 comments on commit 2fd1954

Please sign in to comment.