[orca] Change the locale of character names when the profile language changes



commit 9d51576e3b76e959ac5df61221ec9080286e90a1
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Mon Feb 18 14:01:52 2013 -0500

    Change the locale of character names when the profile language changes

 src/orca/acss.py             |    4 ++++
 src/orca/orca_i18n.py.in     |   21 +++++++++++++++++++--
 src/orca/scripts/default.py  |   11 +++++++++++
 src/orca/settings_manager.py |    5 +++++
 4 files changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/src/orca/acss.py b/src/orca/acss.py
index fafd7ba..dd18767 100644
--- a/src/orca/acss.py
+++ b/src/orca/acss.py
@@ -101,3 +101,7 @@ class ACSS(dict):
                 _name += "%s-%s:" % (k, self[k])
         _name = _name[:-1]
         return _name
+
+    def getLocale(self):
+        family = self.get(ACSS.FAMILY, {})
+        return family.get('locale')
diff --git a/src/orca/orca_i18n.py.in b/src/orca/orca_i18n.py.in
index 4c4a578..3c54e77 100644
--- a/src/orca/orca_i18n.py.in
+++ b/src/orca/orca_i18n.py.in
@@ -23,8 +23,10 @@ maps to the gettext.gettext function.  This function will accept a
 string and return a localized string for that string.
 """
 
-import os       # to get localdir path
-import gettext  # to get gettext (i18n) support
+import gettext
+import imp
+import os
+import sys
 
 # Alias gettext.gettext to _ and gettext.ngettext to ngettext
 #
@@ -50,3 +52,18 @@ def C_(ctx, s):
         # no translation found, return input string
         return s
     return translated
+
+def setModuleLocale(moduleName, newLocale=None):
+    global _, ngettext
+
+    if not newLocale:
+        _ = gettext.gettext
+        ngettext = gettext.ngettext
+    else:
+        translation = gettext.translation('orca', languages=[newLocale])
+        _ = translation.gettext
+        ngettext = translation.ngettext
+
+    module = sys.modules.get(moduleName)
+    if module:
+        imp.reload(module)
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index 16999a6..8154ef0 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -45,6 +45,7 @@ import orca.input_event as input_event
 import orca.keybindings as keybindings
 import orca.outline as outline
 import orca.orca as orca
+import orca.orca_i18n as orca_i18n
 import orca.orca_state as orca_state
 import orca.phonnames as phonnames
 import orca.script as script
@@ -2829,7 +2830,17 @@ 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']
+            for module in modules:
+                orca_i18n.setModuleLocale(module, newVoiceLocale)
+
         # Translators: This is a detailed message which will be presented
         # as the user cycles amongst his/her saved profiles. A "profile"
         # is a collection of settings which apply to a given task, such
diff --git a/src/orca/settings_manager.py b/src/orca/settings_manager.py
index 1891a02..055233f 100644
--- a/src/orca/settings_manager.py
+++ b/src/orca/settings_manager.py
@@ -272,6 +272,11 @@ class SettingsManager(object):
     def getSetting(self, settingName):
         return getattr(settings, settingName)
 
+    def getVoiceLocale(self, voice='default'):
+        voices = self.getSetting('voices')
+        v = voices.get(voice, {})
+        return v.getLocale()
+
     def _getGeneral(self, profile=None):
         """Get from the active backend the general settings for
         the current profile"""


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