[orca] Move some of the language-switching code to where it really belongs



commit b0bbe8c94711eb00b99343166385cf840f84578f
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Sun Feb 24 16:07:09 2013 -0500

    Move some of the language-switching code to where it really belongs

 src/orca/orca_i18n.py.in     |   17 +++++++++++++++++
 src/orca/scripts/default.py  |   16 +---------------
 src/orca/settings_manager.py |   15 ++++++++++++++-
 3 files changed, 32 insertions(+), 16 deletions(-)
---
diff --git a/src/orca/orca_i18n.py.in b/src/orca/orca_i18n.py.in
index b71787e..88ef423 100644
--- a/src/orca/orca_i18n.py.in
+++ b/src/orca/orca_i18n.py.in
@@ -70,3 +70,20 @@ def setModuleLocale(moduleName, newLocale=None):
     module = sys.modules.get(moduleName)
     if module:
         imp.reload(module)
+
+def setLocaleForMessages(newLocale=None):
+    modules = ['orca.tutorialgenerator', 'orca.messages']
+    for module in modules:
+        setModuleLocale(module, newLocale)
+
+def setLocaleForNames(newLocale=None):
+    modules = ['orca.chnames', 'orca.keynames', 'orca.phonnames',
+               'orca.text_attribute_names']
+    for module in modules:
+        setModuleLocale(module, newLocale)
+
+def setLocaleForGUI(newLocale=None):
+    modules = ['orca.orca_gtkbuilder', 'orca.orca_gui_prefs',
+               'orca.app_gui_prefs']
+    for module in modules:
+        setModuleLocale(module, newLocale)
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index 14db35b..e0b00f1 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -48,7 +48,6 @@ import orca.messages as messages
 import orca.outline as outline
 import orca.orca as orca
 import orca.orca_gui_commandlist as commandlist
-import orca.orca_i18n as orca_i18n
 import orca.orca_state as orca_state
 import orca.phonnames as phonnames
 import orca.script as script
@@ -2080,20 +2079,7 @@ class Script(script.Script):
         except IndexError:
             name, profileID = profiles[0]
 
-        oldVoiceLocale = _settingsManager.getVoiceLocale('default')
-        _settingsManager.setProfile(profileID)
-        newVoiceLocale = _settingsManager.getVoiceLocale('default')
-
-        # Once we sort out all of the language changing details, this
-        # code probably should go somewhere else.
-        if oldVoiceLocale != newVoiceLocale:
-            modules = ['orca.chnames', 'orca.keynames', 'orca.phonnames',
-                       'orca.text_attribute_names', 'orca.tutorialgenerator',
-                       'orca.orca_gtkbuilder', 'orca.orca_gui_prefs',
-                       'orca.app_gui_prefs', 'orca.messages']
-            for module in modules:
-                orca_i18n.setModuleLocale(module, newVoiceLocale)
-
+        _settingsManager.setProfile(profileID, updateLocale=True)
         self.presentMessage(messages.PROFILE_CHANGED % name, name)
         return True
 
diff --git a/src/orca/settings_manager.py b/src/orca/settings_manager.py
index 61bc82d..cf3b045 100644
--- a/src/orca/settings_manager.py
+++ b/src/orca/settings_manager.py
@@ -34,6 +34,7 @@ import os
 from gi.repository import Gio, GLib
 
 from . import debug
+from . import orca_i18n
 from . import script_manager
 from . import settings
 from . import pronunciation_dict
@@ -366,15 +367,27 @@ class SettingsManager(object):
     def getProfile(self):
         return self.profile
 
-    def setProfile(self, profile='default'):
+    def setProfile(self, profile='default', updateLocale=False):
         """Set a specific profile as the active one.
         Also the settings from that profile will be loading
         and updated the current settings with them."""
+
+        oldVoiceLocale = self.getVoiceLocale('default')
+
         self.profile = profile
         self._loadProfileSettings(profile)
         self._mergeSettings()
         self._setSettingsRuntime(self.general)
 
+        if not updateLocale:
+            return
+
+        newVoiceLocale = self.getVoiceLocale('default')
+        if oldVoiceLocale != newVoiceLocale:
+            orca_i18n.setLocaleForNames(newVoiceLocale)
+            orca_i18n.setLocaleForMessages(newVoiceLocale)
+            orca_i18n.setLocaleForGUI(newVoiceLocale)
+
     def getPreferences(self, profile='default'):
         general = self.getGeneralSettings(profile)
         pronunciations = self.getPronunciations(profile)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]