[orca] Fix for bug 654789 - Orca is not localizing key sequences when presenting them to the user



commit 65dbaa53abb9fabd9dca58b876a324be79a661e2
Author: Joanmarie Diggs <joanmarie diggs gmail com>
Date:   Sun Jul 17 14:17:38 2011 -0400

    Fix for bug 654789 - Orca is not localizing key sequences when presenting them to the user

 src/orca/keynames.py         |   30 ++++++++++++++++++++++++++++++
 src/orca/script_utilities.py |    4 ++++
 2 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/src/orca/keynames.py b/src/orca/keynames.py
index 1271734..e322503 100644
--- a/src/orca/keynames.py
+++ b/src/orca/keynames.py
@@ -29,6 +29,7 @@ __license__   = "LGPL"
 import chnames
 
 from orca_i18n import _ # for gettext support
+from orca_i18n import C_
 
 # __keynames is a dictionary where the keys represent a UTF-8
 # string for a keyboard key and the values represent the common
@@ -36,6 +37,18 @@ from orca_i18n import _ # for gettext support
 #
 __keynames = {}
 
+# Translators: this is how someone would speak the name of the shift key
+#
+__keynames["Shift"]        = C_("keyboard", "Shift")
+
+# Translators: this is how someone would speak the name of the alt key
+#
+__keynames["Alt"]          = C_("keyboard", "Alt")
+
+# Translators: this is how someone would speak the name of the shift key
+#
+__keynames["Control"]      = C_("keyboard", "Control")
+
 # Translators: this is how someone would speak the name of the left shift key
 #
 __keynames["Shift_L"]      = _("left shift")
@@ -301,3 +314,20 @@ def getKeyName(key):
         return __keynames[key]
     except:
         return chnames.getCharacterName(key)
+
+def localizeKeySequence(keys):
+    """Given a sequence of keys, such as 'Shift Control A', localize the
+    full sequence.
+
+    Arguments:
+    - keys: the key sequence to localize
+
+    Returns a string representing the localized version to present to the
+    user
+    """
+
+    keyList = keys.split()
+    for key in keyList:
+        keys = keys.replace(key, getKeyName(key))
+
+    return keys
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 1b82972..194cfec 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -33,6 +33,7 @@ import pyatspi
 import re
 
 import debug
+import keynames
 import input_event
 import mouse_review
 import orca_state
@@ -2726,6 +2727,7 @@ class Utilities:
         fullShortcut = fullShortcut.replace("<","")
         fullShortcut = fullShortcut.replace(">"," ")
         fullShortcut = fullShortcut.replace(":"," ").strip()
+        fullShortcut = keynames.localizeKeySequence(fullShortcut)
 
         # If the accelerator or mnemonic strings includes a Space,
         # make sure we speak it.
@@ -2736,6 +2738,7 @@ class Utilities:
             mnemonic += _("space")
         mnemonic = mnemonic.replace("<","")
         mnemonic = mnemonic.replace(">"," ").strip()
+        mnemonic = keynames.localizeKeySequence(mnemonic)
 
         if accelerator.endswith(" "):
             # Translators: this is the spoken word for the space character
@@ -2743,6 +2746,7 @@ class Utilities:
             accelerator += _("space")
         accelerator = accelerator.replace("<","")
         accelerator = accelerator.replace(">"," ").strip()
+        accelerator = keynames.localizeKeySequence(accelerator)
 
         debug.println(debug.LEVEL_FINEST, "script_utilities.getKeyBinding: " \
                       + repr([mnemonic, fullShortcut, accelerator]))



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