OSDN Git Service

characterProcessing.getCharacterDescription:
authorMichael Curran <mick@kulgan.net>
Wed, 6 Apr 2011 04:25:22 +0000 (14:25 +1000)
committerMichael Curran <mick@kulgan.net>
Wed, 6 Apr 2011 04:25:22 +0000 (14:25 +1000)
* If locale data cannot be found for a particular locale and its not english, fall back to English by calling getCharacterDescription this time with 'en'.
* If a character description can not be found in the locale data for a given locale, and its not english, fall back to English by calling getCharacterDescription with 'en'.
* If a character description can not be found in the english locale, instead look up the name in the unicode database. The unicode database is only available in english, however I think it is a useful fall back when there is nothing else to say.
* Finally if absolutely nothing can be found, then None is returned, which means that NVDA will just use the character itself.

source/characterProcessing.py

index 703c855..c064504 100644 (file)
@@ -93,7 +93,21 @@ def getCharacterDescription(locale,character):
        @return:  the found description for the given character\r
        @rtype: string\r
        """\r
-       l=_charDescLocaleDataMap.fetchLocaleData(locale)\r
+       try:\r
+               l=_charDescLocaleDataMap.fetchLocaleData(locale)\r
+       except LookupError:\r
+               if not locale.startswith('en'):\r
+                       return getCharacterDescription('en',character)\r
+               raise LookupError("en")\r
        desc=l.getCharacterDescription(character)\r
+       if not desc:\r
+               if not locale.startswith('en'):\r
+                       desc=getCharacterDescription('en',character)\r
+               else:\r
+                       import unicodedata\r
+                       try:\r
+                               desc=unicodedata.name(character)\r
+                       except ValueError:\r
+                               return None\r
        return desc\r
  
\ No newline at end of file