summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2010-01-29 15:17:40 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2010-03-22 13:19:14 (GMT)
commit44354dc9eebb1fa84529f965e92447b114eb881c (patch)
tree0c8d892011d6d85a26804643326c22eb12eebbc2 /util
parentc7febf61783c06f8fb68fa1ef26cc92d04ce2e98 (diff)
downloadQt-44354dc9eebb1fa84529f965e92447b114eb881c.zip
Qt-44354dc9eebb1fa84529f965e92447b114eb881c.tar.gz
Qt-44354dc9eebb1fa84529f965e92447b114eb881c.tar.bz2
Fixed reading draft data from CLDR.
When draft resolution is specified we should accept it and all values "above" it. For example if we are searching for a group separator with a "contributed" resolution, we should also accept data that is "approved". In theory we should only accept data with "contributed" or "approved" resolutions and should not trust other resolutions. However in order not to introduce data regressions to QLocale we will only handle drafts for new data. Reviewed-by: Frans Englich
Diffstat (limited to 'util')
-rwxr-xr-xutil/local_database/cldr2qlocalexml.py21
-rw-r--r--util/local_database/xpathlite.py27
2 files changed, 28 insertions, 20 deletions
diff --git a/util/local_database/cldr2qlocalexml.py b/util/local_database/cldr2qlocalexml.py
index 6f4ee25..71d14e8 100755
--- a/util/local_database/cldr2qlocalexml.py
+++ b/util/local_database/cldr2qlocalexml.py
@@ -99,16 +99,23 @@ def generateLocaleInfo(path):
language = enumdata.language_list[language_id][0]
country_id = enumdata.countryCodeToId(country_code)
- if country_id == -1:
- sys.stderr.write("unnknown country code \"" + country_code + "\"\n")
- return {}
- country = enumdata.country_list[country_id][0]
+ country = ""
+ if country_id != -1:
+ country = enumdata.country_list[country_id][0]
+
+ # So we say we accept only those values that have "contributed" or
+ # "approved" resolution. see http://www.unicode.org/cldr/process.html
+ # But we only respect the resolution for new datas for backward
+ # compatibility.
+ draft = DraftResolution.contributed
result = {}
result['language'] = language
result['country'] = country
result['language_code'] = language_code
result['country_code'] = country_code
+ result['script_code'] = script_code
+ result['variant_code'] = variant_code
result['language_id'] = language_id
result['country_id'] = country_id
result['decimal'] = findEntry(path, "numbers/symbols/decimal")
@@ -119,8 +126,8 @@ def generateLocaleInfo(path):
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=DraftResolution.approved)
- result['pm'] = findEntry(path, "dates/calendars/calendar[gregorian]/pm", draft=DraftResolution.approved)
+ result['am'] = findEntry(path, "dates/calendars/calendar[gregorian]/am", draft)
+ result['pm'] = findEntry(path, "dates/calendars/calendar[gregorian]/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")
@@ -315,7 +322,7 @@ for file in cldr_files:
sys.stderr.write("skipping file \"" + file + "\"\n")
continue
- locale_database[(l['language_id'], l['country_id'])] = l
+ locale_database[(l['language_id'], l['country_id'], l['script_code'], l['variant_code'])] = l
locale_keys = locale_database.keys()
locale_keys.sort()
diff --git a/util/local_database/xpathlite.py b/util/local_database/xpathlite.py
index 94bc23f..0f21a19 100644
--- a/util/local_database/xpathlite.py
+++ b/util/local_database/xpathlite.py
@@ -52,6 +52,11 @@ class DraftResolution:
provisional = 'provisional'
contributed = 'contributed'
approved = 'approved'
+ _values = { unconfirmed : 1, provisional : 2, contributed : 3, approved : 4 }
+ def __init__(self, resolution):
+ self.resolution = resolution
+ def toInt(self):
+ return DraftResolution._values[self.resolution]
class Error:
def __init__(self, msg):
@@ -71,10 +76,13 @@ def findChild(parent, tag_name, arg_value, draft=None):
if node.attributes['type'].nodeValue != arg_value:
continue
if draft:
- if node.attributes.has_key('draft'):
- if node.attributes['draft'].nodeValue != draft:
- continue
- elif draft != DraftResolution.approved:
+ if not node.attributes.has_key('draft'):
+ # if draft is not specified then it's approved
+ return node
+ value = node.attributes['draft'].nodeValue
+ value = DraftResolution(value).toInt()
+ exemplar = DraftResolution(draft).toInt()
+ if exemplar > value:
continue
return node
return False
@@ -90,9 +98,6 @@ def _findEntryInFile(file, path, draft=None, attribute=None):
elt = doc.documentElement
tag_spec_list = path.split("/")
last_entry = None
- if draft is not None:
- last_entry = tag_spec_list[-1]
- tag_spec_list = tag_spec_list[:-1]
for i in range(len(tag_spec_list)):
tag_spec = tag_spec_list[i]
tag_name = tag_spec
@@ -118,11 +123,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)
- if not elt:
- return ("", None)
- if last_entry is not None:
- elt = findChild(elt, last_entry, '', draft)
+ elt = findChild(elt, tag_name, arg_value, draft)
if not elt:
return ("", None)
if attribute is not None:
@@ -145,7 +146,7 @@ def findAlias(file):
def _findEntry(base, path, draft=None, attribute=None):
file = base
if base.endswith(".xml"):
- file = base
+ filename = base
base = base[:-4]
else:
file = base + ".xml"