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

Commit

Permalink
Modify the code according to the code review. This version is not yet…
Browse files Browse the repository at this point in the history
… functional because of some bug.
  • Loading branch information
Cryspia committed Oct 13, 2014
1 parent 2b35cec commit 4b4a271
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/freeseer/frontend/configtool/configtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions src/freeseer/frontend/qtcommon/FreeseerApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
2 changes: 1 addition & 1 deletion src/freeseer/frontend/record/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/freeseer/frontend/reporteditor/reporteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ReportEditorApp(FreeseerApp):
'''

def __init__(self, config, db):
FreeseerApp.__init__(self, config)
super(ReportEditorApp, self).__init__(config)

self.db = db

Expand Down
2 changes: 1 addition & 1 deletion src/freeseer/frontend/talkeditor/talkeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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

Expand Down
32 changes: 30 additions & 2 deletions src/freeseer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 4b4a271

Please sign in to comment.