summaryrefslogtreecommitdiffstats
path: root/util/locale_database/xpathlite.py
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2019-05-08 15:20:30 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2019-05-20 20:42:11 +0200
commitb7d8169f02c43f2726eae46e20b8ccb6e8b18ee4 (patch)
tree26261c13f50322e6d8b3716743835121d93ba23b /util/locale_database/xpathlite.py
parent248b6756da0d31c58672c0e356c3ec16e9088234 (diff)
Suggest name, when available, for unknown codes
When parsing the CLDR data, we only handle language, script and territory (which we call country) codes if they are known to our enumdata.py tables. When reporting the rest as unknown, in the content of an actual locale definition (not the likely subtag data), check whether en.xml can resolve the code for us; if it can, report the full name it provides, as a hint to whoever's running the script that an update to enumdata.py may be in order. Change-Id: I9ca1d6922a91d45bc436f4b622e5557261897d7f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'util/locale_database/xpathlite.py')
-rw-r--r--util/locale_database/xpathlite.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/util/locale_database/xpathlite.py b/util/locale_database/xpathlite.py
index 218135d7a7..97efaaab41 100644
--- a/util/locale_database/xpathlite.py
+++ b/util/locale_database/xpathlite.py
@@ -78,14 +78,38 @@ def findChild(parent, tag_name, arg_name=None, arg_value=None, draft=None):
return node
return False
+def codeMapsFromFile(file):
+ """Extract mappings of language, script and country codes to names.
+
+ The file shall typically be common/main/en.xml, which contains a
+ localeDisplayNames element with children languages, scripts and
+ territories; each element in each of these has a code as its type
+ attribute and its name as element content. This returns a mapping
+ withe keys 'language', 'script' and 'country', each of which
+ has, as value, a mapping of the relevant codes to names.
+ """
+ parent = findChild(findChild(parseDoc(file), 'ldml'), 'localeDisplayNames')
+ keys, result = {'languages': 'language', 'scripts': 'script', 'territories': 'country'}, {}
+ for src, dst in keys.items():
+ child = findChild(parent, src)
+ data = result[dst] = {}
+ for elt in child.childNodes:
+ if elt.attributes and elt.attributes.has_key('type'):
+ key, value = elt.attributes['type'].value, elt.childNodes[0].wholeText
+ # Don't over-write previously-read data for an alt form:
+ if elt.attributes.has_key('alt') and data.has_key(key):
+ continue
+ data[key] = value
+
+ return result
+
def findTagsInFile(file, path):
doc = parseDoc(file)
elt = doc.documentElement
tag_spec_list = path.split("/")
last_entry = None
- for i in range(len(tag_spec_list)):
- tag_spec = tag_spec_list[i]
+ for tag_spec in tag_spec_list:
tag_name = tag_spec
arg_name = 'type'
arg_value = ''