diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2010-03-19 14:15:45 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2010-03-22 13:21:36 (GMT) |
commit | 15d64b6e8c5ce98cb8c1061c007afe7f19751226 (patch) | |
tree | a60e41f10e104a66c398275510e0ceaebd8bc435 /util/local_database | |
parent | 44354dc9eebb1fa84529f965e92447b114eb881c (diff) | |
download | Qt-15d64b6e8c5ce98cb8c1061c007afe7f19751226.zip Qt-15d64b6e8c5ce98cb8c1061c007afe7f19751226.tar.gz Qt-15d64b6e8c5ce98cb8c1061c007afe7f19751226.tar.bz2 |
Improved CLDR parser.
Added support for "defaultNumberingSystem" element to get the right numeric
information (decimal point, group separator, zero digit etc).
Also fixed xpaths to the AM/PM text for CLDR 1.8.0
Reviewed-by: trustme
Diffstat (limited to 'util/local_database')
-rwxr-xr-x | util/local_database/cldr2qlocalexml.py | 36 | ||||
-rw-r--r-- | util/local_database/xpathlite.py | 20 |
2 files changed, 39 insertions, 17 deletions
diff --git a/util/local_database/cldr2qlocalexml.py b/util/local_database/cldr2qlocalexml.py index 71d14e8..ede7763 100755 --- a/util/local_database/cldr2qlocalexml.py +++ b/util/local_database/cldr2qlocalexml.py @@ -102,6 +102,9 @@ def generateLocaleInfo(path): country = "" if country_id != -1: country = enumdata.country_list[country_id][0] + if country == "": + sys.stderr.write("unnknown country code \"" + country_code + "\"\n") + return {} # So we say we accept only those values that have "contributed" or # "approved" resolution. see http://www.unicode.org/cldr/process.html @@ -118,16 +121,29 @@ def generateLocaleInfo(path): result['variant_code'] = variant_code result['language_id'] = language_id result['country_id'] = country_id - result['decimal'] = findEntry(path, "numbers/symbols/decimal") - result['group'] = findEntry(path, "numbers/symbols/group") - result['list'] = findEntry(path, "numbers/symbols/list") - result['percent'] = findEntry(path, "numbers/symbols/percentSign") - result['zero'] = findEntry(path, "numbers/symbols/nativeZeroDigit") - result['minus'] = findEntry(path, "numbers/symbols/minusSign") - result['plus'] = findEntry(path, "numbers/symbols/plusSign") - result['exp'] = findEntry(path, "numbers/symbols/exponential").lower() - result['am'] = findEntry(path, "dates/calendars/calendar[gregorian]/am", draft) - result['pm'] = findEntry(path, "dates/calendars/calendar[gregorian]/pm", draft) + + numberingSystem = None + try: + numbering_system = findEntry(path, "numbers/defaultNumberingSystem") + except: + pass + def get_number_in_system(path, xpath, numbering_system): + if numbering_system: + try: + return findEntry(path, xpath + "[numberSystem=" + numbering_system + "]") + except xpathlite.Error: + pass + return findEntry(path, xpath) + result['decimal'] = get_number_in_system(path, "numbers/symbols/decimal", numbering_system) + result['group'] = get_number_in_system(path, "numbers/symbols/group", numbering_system) + result['list'] = get_number_in_system(path, "numbers/symbols/list", numbering_system) + result['percent'] = get_number_in_system(path, "numbers/symbols/percentSign", numbering_system) + result['zero'] = get_number_in_system(path, "numbers/symbols/nativeZeroDigit", numbering_system) + result['minus'] = get_number_in_system(path, "numbers/symbols/minusSign", numbering_system) + result['plus'] = get_number_in_system(path, "numbers/symbols/plusSign", numbering_system) + result['exp'] = get_number_in_system(path, "numbers/symbols/exponential", numbering_system).lower() + result['am'] = findEntry(path, "dates/calendars/calendar[gregorian]/dayPeriods/dayPeriodContext[format]/dayPeriodWidth[wide]/dayPeriod[am]", draft) + result['pm'] = findEntry(path, "dates/calendars/calendar[gregorian]/dayPeriods/dayPeriodContext[format]/dayPeriodWidth[wide]/dayPeriod[pm]", draft) result['longDateFormat'] = findEntry(path, "dates/calendars/calendar[gregorian]/dateFormats/dateFormatLength[full]/dateFormat/pattern") result['shortDateFormat'] = findEntry(path, "dates/calendars/calendar[gregorian]/dateFormats/dateFormatLength[short]/dateFormat/pattern") result['longTimeFormat'] = findEntry(path, "dates/calendars/calendar[gregorian]/timeFormats/timeFormatLength[full]/timeFormat/pattern") diff --git a/util/local_database/xpathlite.py b/util/local_database/xpathlite.py index 0f21a19..7d569f3 100644 --- a/util/local_database/xpathlite.py +++ b/util/local_database/xpathlite.py @@ -64,16 +64,16 @@ class Error: def __str__(self): return self.msg -def findChild(parent, tag_name, arg_value, draft=None): +def findChild(parent, tag_name, arg_name=None, arg_value=None, draft=None): for node in parent.childNodes: if node.nodeType != node.ELEMENT_NODE: continue if node.nodeName != tag_name: continue if arg_value: - if not node.attributes.has_key('type'): + if not node.attributes.has_key(arg_name): continue - if node.attributes['type'].nodeValue != arg_value: + if node.attributes[arg_name].nodeValue != arg_value: continue if draft: if not node.attributes.has_key('draft'): @@ -101,12 +101,18 @@ def _findEntryInFile(file, path, draft=None, attribute=None): for i in range(len(tag_spec_list)): tag_spec = tag_spec_list[i] tag_name = tag_spec + arg_name = 'type' arg_value = '' left_bracket = tag_spec.find('[') if left_bracket != -1: tag_name = tag_spec[:left_bracket] - arg_value = tag_spec[left_bracket+1:-1] - alias = findChild(elt, 'alias', None) + arg_value = tag_spec[left_bracket+1:-1].split("=") + if len(arg_value) == 2: + arg_name = arg_value[0] + arg_value = arg_value[1] + else: + arg_value = arg_value[0] + alias = findChild(elt, 'alias') if alias and alias.attributes['source'].nodeValue == 'locale': path = alias.attributes['path'].nodeValue aliaspath = tag_spec_list[:i] + path.split("/") @@ -123,7 +129,7 @@ def _findEntryInFile(file, path, draft=None, attribute=None): aliaspath = "/".join(aliaspath) # "locale" aliases are special - we need to start lookup from scratch return (None, aliaspath) - elt = findChild(elt, tag_name, arg_value, draft) + elt = findChild(elt, tag_name, arg_name, arg_value, draft) if not elt: return ("", None) if attribute is not None: @@ -136,7 +142,7 @@ def findAlias(file): if not doc_cache.has_key(file): return False doc = doc_cache[file] - alias_elt = findChild(doc.documentElement, "alias", "") + alias_elt = findChild(doc.documentElement, "alias") if not alias_elt: return False if not alias_elt.attributes.has_key('source'): |