From 4a137f4b7b53a1b896da01f7d091f3a4ebea6051 Mon Sep 17 00:00:00 2001 From: Kaiyuan Li Date: Mon, 13 Oct 2014 01:22:10 -0700 Subject: [PATCH] Modify the code according to the code review. This version is not yet functional because of some bug. --- .../frontend/configtool/configtool.py | 2 +- src/freeseer/frontend/qtcommon/FreeseerApp.py | 16 ---------- src/freeseer/frontend/record/record.py | 2 +- .../frontend/reporteditor/reporteditor.py | 2 +- .../frontend/talkeditor/talkeditor.py | 2 +- src/freeseer/settings.py | 32 +++++++++++++++++-- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/freeseer/frontend/configtool/configtool.py b/src/freeseer/frontend/configtool/configtool.py index e8b31a54..34997220 100644 --- a/src/freeseer/frontend/configtool/configtool.py +++ b/src/freeseer/frontend/configtool/configtool.py @@ -55,7 +55,7 @@ class ConfigToolApp(FreeseerApp): ''' def __init__(self, profile, config): - FreeseerApp.__init__(self, config) + super(ConfigToolApp, self).__init__(config) # Load Config Stuff self.profile = profile diff --git a/src/freeseer/frontend/qtcommon/FreeseerApp.py b/src/freeseer/frontend/qtcommon/FreeseerApp.py index dfa78721..495d1596 100644 --- a/src/freeseer/frontend/qtcommon/FreeseerApp.py +++ b/src/freeseer/frontend/qtcommon/FreeseerApp.py @@ -168,7 +168,6 @@ def retranslateFreeseerApp(self): def setupLanguageMenu(self): self.languages = QDir(":/languages").entryList() - languageDetected = False if self.current_language is None: self.current_language = QLocale.system().name() # Retrieve Current Locale from the operating system. log.debug("Detected user's locale as %s" % self.current_language) @@ -184,18 +183,3 @@ def setupLanguageMenu(self): languageAction.setData(language) self.menuLanguage.addAction(languageAction) self.langActionGroup.addAction(languageAction) - - #Auto language changing. - #Ignore the location, only use the language to do the matching. - if self.config.default_language[3:5] == str(language)[3:5]: - languageDetected = True - #Additional case for Simplified Chinese & Traditional Chinese. - #Traditional Chinese has higher priority - if (self.config.default_language[3:5] != "zh" or - str(language) == "tr_zh_HK.qm" and - self.config.default_language != "tr_zh_CN.qm"): - self.config.default_language = str(language) - - #For the system language not included, using English for default. - if not languageDetected: - self.config.default_language = "tr_en_US.qm" diff --git a/src/freeseer/frontend/record/record.py b/src/freeseer/frontend/record/record.py index 850ae0f0..48e1be53 100644 --- a/src/freeseer/frontend/record/record.py +++ b/src/freeseer/frontend/record/record.py @@ -53,7 +53,7 @@ class RecordApp(FreeseerApp): """Freeseer's main GUI class.""" def __init__(self, profile, config): - FreeseerApp.__init__(self, config) + super(RecordApp, self).__init__(config) self.db = profile.get_database() self.controller = RecordingController(profile, self.db, self.config) diff --git a/src/freeseer/frontend/reporteditor/reporteditor.py b/src/freeseer/frontend/reporteditor/reporteditor.py index 2a3f72b6..1c14f127 100644 --- a/src/freeseer/frontend/reporteditor/reporteditor.py +++ b/src/freeseer/frontend/reporteditor/reporteditor.py @@ -55,7 +55,7 @@ class ReportEditorApp(FreeseerApp): ''' def __init__(self, config, db): - FreeseerApp.__init__(self, config) + super(ReportEditorApp, self).__init__(config) self.db = db diff --git a/src/freeseer/frontend/talkeditor/talkeditor.py b/src/freeseer/frontend/talkeditor/talkeditor.py index 63ee2b8c..8bfb68e8 100644 --- a/src/freeseer/frontend/talkeditor/talkeditor.py +++ b/src/freeseer/frontend/talkeditor/talkeditor.py @@ -59,7 +59,7 @@ class TalkEditorApp(FreeseerApp): '''Freeseer talk database editor main gui class''' def __init__(self, config, db): - FreeseerApp.__init__(self, config) + super(TalkEditorApp, self).__init__(config) self.db = db diff --git a/src/freeseer/settings.py b/src/freeseer/settings.py index 100b94e6..cc58a230 100644 --- a/src/freeseer/settings.py +++ b/src/freeseer/settings.py @@ -24,9 +24,11 @@ import os +from PyQt4.QtCore import QDir +from PyQt4.QtCore import QLocale + from freeseer.framework.config.core import Config from freeseer.framework.config.profile import ProfileManager -from PyQt4.QtCore import QLocale import freeseer.framework.config.options as options # TODO: change to config_dir when all the pull requests from UCOSP Fall 2013 are merged in @@ -65,4 +67,30 @@ 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_' + str(QLocale.system().name()) + '.qm') + + def __AutoLanguageChanging(): + """Detect the local language and change the program language""" + + language_folder = QDir(":/frontend/qtcommon/languages").entryList() + language_detected = False + current_language = options.StringOption('tr_{}.qm'.format(str(QLocale.system().name()))) + + for language in language_folder: + #Auto language changing. + #Ignore the location, only use the language to do the matching. + if current_language[3:5] == str(language)[3:5]: + language_detected = True + #Additional case for Simplified Chinese & Traditional Chinese. + #Traditional Chinese has higher priority + if (current_language[3:5] != "zh" or + str(language) == "tr_zh_HK.qm" and + current_language != "tr_zh_CN.qm"): + current_language = str(language) + + #For the system language not included, using English for default. + if not language_detected: + current_language = "tr_en_US.qm" + + return current_language + + default_language = __AutoLanguageChanging()