Mercurial > babel > old > mirror
annotate scripts/import_cldr.py @ 389:47321cbc3ac1
Some refactoring in plural.py
author | aronacher |
---|---|
date | Mon, 14 Jul 2008 12:48:21 +0000 |
parents | 88e3589ca8df |
children | 34c0a25b1ed7 |
rev | line source |
---|---|
3 | 1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- | |
3 # | |
4 # Copyright (C) 2007 Edgewall Software | |
5 # All rights reserved. | |
6 # | |
7 # This software is licensed as described in the file COPYING, which | |
8 # you should have received as part of this distribution. The terms | |
9 # are also available at http://babel.edgewall.org/wiki/License. | |
10 # | |
11 # This software consists of voluntary contributions made by many | |
12 # individuals. For the exact contribution history, see the revision | |
13 # history and logs, available at http://babel.edgewall.org/log/. | |
14 | |
15 import copy | |
16 from optparse import OptionParser | |
17 import os | |
18 import pickle | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
19 import re |
3 | 20 import sys |
21 try: | |
22 from xml.etree.ElementTree import parse | |
23 except ImportError: | |
24 from elementtree.ElementTree import parse | |
25 | |
67
ad48b95af0d9
Add Babel soruce path to CLDR import script automatically for asmodai ;-).
cmlenz
parents:
36
diff
changeset
|
26 # Make sure we're using Babel source, and not some previously installed version |
ad48b95af0d9
Add Babel soruce path to CLDR import script automatically for asmodai ;-).
cmlenz
parents:
36
diff
changeset
|
27 sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), '..')) |
ad48b95af0d9
Add Babel soruce path to CLDR import script automatically for asmodai ;-).
cmlenz
parents:
36
diff
changeset
|
28 |
11 | 29 from babel import dates, numbers |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
30 from babel.localedata import Alias |
3 | 31 |
17 | 32 weekdays = {'mon': 0, 'tue': 1, 'wed': 2, 'thu': 3, 'fri': 4, 'sat': 5, |
33 'sun': 6} | |
10
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
34 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
35 try: |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
36 any |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
37 except NameError: |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
38 def any(iterable): |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
39 return filter(None, list(iterable)) |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
40 |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
41 |
3 | 42 def _text(elem): |
43 buf = [elem.text or ''] | |
44 for child in elem: | |
45 buf.append(_text(child)) | |
46 buf.append(elem.tail or '') | |
47 return u''.join(filter(None, buf)).strip() | |
48 | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
49 |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
50 NAME_RE = re.compile(r"^\w+$") |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
51 TYPE_ATTR_RE = re.compile(r"^\w+\[@type='(.*?)'\]$") |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
52 |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
53 NAME_MAP = { |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
54 'dateFormats': 'date_formats', |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
55 'dateTimeFormats': 'datetime_formats', |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
56 'eraAbbr': 'abbreviated', |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
57 'eraNames': 'wide', |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
58 'eraNarrow': 'narrow', |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
59 'timeFormats': 'time_formats' |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
60 } |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
61 |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
62 def _translate_alias(ctxt, path): |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
63 parts = path.split('/') |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
64 keys = ctxt[:] |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
65 for part in parts: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
66 if part == '..': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
67 keys.pop() |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
68 else: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
69 match = TYPE_ATTR_RE.match(part) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
70 if match: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
71 keys.append(match.group(1)) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
72 else: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
73 assert NAME_RE.match(part) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
74 keys.append(NAME_MAP.get(part, part)) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
75 return keys |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
76 |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
77 |
3 | 78 def main(): |
79 parser = OptionParser(usage='%prog path/to/cldr') | |
80 options, args = parser.parse_args() | |
81 if len(args) != 1: | |
82 parser.error('incorrect number of arguments') | |
83 | |
84 srcdir = args[0] | |
85 destdir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), | |
235
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
86 '..', 'babel') |
3 | 87 |
10
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
88 sup = parse(os.path.join(srcdir, 'supplemental', 'supplementalData.xml')) |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
89 |
347
c22f292731be
Update to CLDR 1.5.1, which split out the metazone mappings into a separate supplemental file.
cmlenz
parents:
235
diff
changeset
|
90 # Import global data from the supplemental files |
235
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
91 global_data = {} |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
92 |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
93 territory_zones = global_data.setdefault('territory_zones', {}) |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
94 zone_aliases = global_data.setdefault('zone_aliases', {}) |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
95 zone_territories = global_data.setdefault('zone_territories', {}) |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
96 for elem in sup.findall('//timezoneData/zoneFormatting/zoneItem'): |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
97 tzid = elem.attrib['type'] |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
98 territory_zones.setdefault(elem.attrib['territory'], []).append(tzid) |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
99 zone_territories[tzid] = elem.attrib['territory'] |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
100 if 'aliases' in elem.attrib: |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
101 for alias in elem.attrib['aliases'].split(): |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
102 zone_aliases[alias] = tzid |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
103 |
347
c22f292731be
Update to CLDR 1.5.1, which split out the metazone mappings into a separate supplemental file.
cmlenz
parents:
235
diff
changeset
|
104 # Import Metazone mapping |
c22f292731be
Update to CLDR 1.5.1, which split out the metazone mappings into a separate supplemental file.
cmlenz
parents:
235
diff
changeset
|
105 meta_zones = global_data.setdefault('meta_zones', {}) |
c22f292731be
Update to CLDR 1.5.1, which split out the metazone mappings into a separate supplemental file.
cmlenz
parents:
235
diff
changeset
|
106 tzsup = parse(os.path.join(srcdir, 'supplemental', 'metazoneInfo.xml')) |
c22f292731be
Update to CLDR 1.5.1, which split out the metazone mappings into a separate supplemental file.
cmlenz
parents:
235
diff
changeset
|
107 for elem in tzsup.findall('//timezone'): |
c22f292731be
Update to CLDR 1.5.1, which split out the metazone mappings into a separate supplemental file.
cmlenz
parents:
235
diff
changeset
|
108 for child in elem.findall('usesMetazone'): |
c22f292731be
Update to CLDR 1.5.1, which split out the metazone mappings into a separate supplemental file.
cmlenz
parents:
235
diff
changeset
|
109 if 'to' not in child.attrib: # FIXME: support old mappings |
c22f292731be
Update to CLDR 1.5.1, which split out the metazone mappings into a separate supplemental file.
cmlenz
parents:
235
diff
changeset
|
110 meta_zones[elem.attrib['type']] = child.attrib['mzone'] |
c22f292731be
Update to CLDR 1.5.1, which split out the metazone mappings into a separate supplemental file.
cmlenz
parents:
235
diff
changeset
|
111 |
235
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
112 outfile = open(os.path.join(destdir, 'global.dat'), 'wb') |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
113 try: |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
114 pickle.dump(global_data, outfile, 2) |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
115 finally: |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
116 outfile.close() |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
117 |
10
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
118 # build a territory containment mapping for inheritance |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
119 regions = {} |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
120 for elem in sup.findall('//territoryContainment/group'): |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
121 regions[elem.attrib['type']] = elem.attrib['contains'].split() |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
122 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
123 # Resolve territory containment |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
124 territory_containment = {} |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
125 region_items = regions.items() |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
126 region_items.sort() |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
127 for group, territory_list in region_items: |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
128 for territory in territory_list: |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
129 containers = territory_containment.setdefault(territory, set([])) |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
130 if group in territory_containment: |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
131 containers |= territory_containment[group] |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
132 containers.add(group) |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
133 |
3 | 134 filenames = os.listdir(os.path.join(srcdir, 'main')) |
135 filenames.remove('root.xml') | |
136 filenames.sort(lambda a,b: len(a)-len(b)) | |
137 filenames.insert(0, 'root.xml') | |
138 | |
139 for filename in filenames: | |
140 stem, ext = os.path.splitext(filename) | |
141 if ext != '.xml': | |
142 continue | |
143 | |
387
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
144 print>>sys.stderr, 'Processing input file %r' % filename |
28
695884591af6
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
24
diff
changeset
|
145 tree = parse(os.path.join(srcdir, 'main', filename)) |
3 | 146 data = {} |
147 | |
10
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
148 language = None |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
149 elem = tree.find('//identity/language') |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
150 if elem is not None: |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
151 language = elem.attrib['type'] |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
152 print>>sys.stderr, ' Language: %r' % language |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
153 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
154 territory = None |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
155 elem = tree.find('//identity/territory') |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
156 if elem is not None: |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
157 territory = elem.attrib['type'] |
15 | 158 else: |
159 territory = '001' # world | |
10
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
160 print>>sys.stderr, ' Territory: %r' % territory |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
161 regions = territory_containment.get(territory, []) |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
162 print>>sys.stderr, ' Regions: %r' % regions |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
163 |
3 | 164 # <localeDisplayNames> |
165 | |
166 territories = data.setdefault('territories', {}) | |
167 for elem in tree.findall('//territories/territory'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
168 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
169 and elem.attrib['type'] in territories: |
3 | 170 continue |
171 territories[elem.attrib['type']] = _text(elem) | |
172 | |
173 languages = data.setdefault('languages', {}) | |
174 for elem in tree.findall('//languages/language'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
175 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
176 and elem.attrib['type'] in languages: |
3 | 177 continue |
178 languages[elem.attrib['type']] = _text(elem) | |
179 | |
180 variants = data.setdefault('variants', {}) | |
181 for elem in tree.findall('//variants/variant'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
182 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
183 and elem.attrib['type'] in variants: |
3 | 184 continue |
185 variants[elem.attrib['type']] = _text(elem) | |
186 | |
187 scripts = data.setdefault('scripts', {}) | |
188 for elem in tree.findall('//scripts/script'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
189 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
190 and elem.attrib['type'] in scripts: |
3 | 191 continue |
192 scripts[elem.attrib['type']] = _text(elem) | |
193 | |
194 # <dates> | |
195 | |
10
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
196 week_data = data.setdefault('week_data', {}) |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
197 supelem = sup.find('//weekData') |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
198 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
199 for elem in supelem.findall('minDays'): |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
200 territories = elem.attrib['territories'].split() |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
201 if territory in territories or any([r in territories for r in regions]): |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
202 week_data['min_days'] = int(elem.attrib['count']) |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
203 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
204 for elem in supelem.findall('firstDay'): |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
205 territories = elem.attrib['territories'].split() |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
206 if territory in territories or any([r in territories for r in regions]): |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
207 week_data['first_day'] = weekdays[elem.attrib['day']] |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
208 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
209 for elem in supelem.findall('weekendStart'): |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
210 territories = elem.attrib['territories'].split() |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
211 if territory in territories or any([r in territories for r in regions]): |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
212 week_data['weekend_start'] = weekdays[elem.attrib['day']] |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
213 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
214 for elem in supelem.findall('weekendEnd'): |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
215 territories = elem.attrib['territories'].split() |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
216 if territory in territories or any([r in territories for r in regions]): |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
217 week_data['weekend_end'] = weekdays[elem.attrib['day']] |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
218 |
235
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
219 zone_formats = data.setdefault('zone_formats', {}) |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
220 for elem in tree.findall('//timeZoneNames/gmtFormat'): |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
221 if 'draft' not in elem.attrib and 'alt' not in elem.attrib: |
235
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
222 zone_formats['gmt'] = unicode(elem.text).replace('{0}', '%s') |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
223 break |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
224 for elem in tree.findall('//timeZoneNames/regionFormat'): |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
225 if 'draft' not in elem.attrib and 'alt' not in elem.attrib: |
235
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
226 zone_formats['region'] = unicode(elem.text).replace('{0}', '%s') |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
227 break |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
228 for elem in tree.findall('//timeZoneNames/fallbackFormat'): |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
229 if 'draft' not in elem.attrib and 'alt' not in elem.attrib: |
235
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
230 zone_formats['fallback'] = unicode(elem.text) \ |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
231 .replace('{0}', '%(0)s').replace('{1}', '%(1)s') |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
232 break |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
233 |
3 | 234 time_zones = data.setdefault('time_zones', {}) |
235 for elem in tree.findall('//timeZoneNames/zone'): | |
30
9a00ac84004c
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
28
diff
changeset
|
236 info = {} |
9a00ac84004c
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
28
diff
changeset
|
237 city = elem.findtext('exemplarCity') |
9a00ac84004c
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
28
diff
changeset
|
238 if city: |
9a00ac84004c
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
28
diff
changeset
|
239 info['city'] = unicode(city) |
9a00ac84004c
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
28
diff
changeset
|
240 for child in elem.findall('long/*'): |
9a00ac84004c
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
28
diff
changeset
|
241 info.setdefault('long', {})[child.tag] = unicode(child.text) |
9a00ac84004c
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
28
diff
changeset
|
242 for child in elem.findall('short/*'): |
9a00ac84004c
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
28
diff
changeset
|
243 info.setdefault('short', {})[child.tag] = unicode(child.text) |
9a00ac84004c
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
28
diff
changeset
|
244 time_zones[elem.attrib['type']] = info |
3 | 245 |
235
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
246 meta_zones = data.setdefault('meta_zones', {}) |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
247 for elem in tree.findall('//timeZoneNames/metazone'): |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
248 info = {} |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
249 city = elem.findtext('exemplarCity') |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
250 if city: |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
251 info['city'] = unicode(city) |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
252 for child in elem.findall('long/*'): |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
253 info.setdefault('long', {})[child.tag] = unicode(child.text) |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
254 for child in elem.findall('short/*'): |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
255 info.setdefault('short', {})[child.tag] = unicode(child.text) |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
256 info['common'] = elem.findtext('commonlyUsed') == 'true' |
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
257 meta_zones[elem.attrib['type']] = info |
36 | 258 |
3 | 259 for calendar in tree.findall('//calendars/calendar'): |
260 if calendar.attrib['type'] != 'gregorian': | |
261 # TODO: support other calendar types | |
262 continue | |
263 | |
264 months = data.setdefault('months', {}) | |
265 for ctxt in calendar.findall('months/monthContext'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
266 ctxt_type = ctxt.attrib['type'] |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
267 ctxts = months.setdefault(ctxt_type, {}) |
3 | 268 for width in ctxt.findall('monthWidth'): |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
269 width_type = width.attrib['type'] |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
270 widths = ctxts.setdefault(width_type, {}) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
271 for elem in width.getiterator(): |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
272 if elem.tag == 'month': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
273 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
274 and int(elem.attrib['type']) in widths: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
275 continue |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
276 widths[int(elem.attrib.get('type'))] = unicode(elem.text) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
277 elif elem.tag == 'alias': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
278 ctxts[width_type] = Alias( |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
279 _translate_alias(['months', ctxt_type, width_type], |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
280 elem.attrib['path']) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
281 ) |
3 | 282 |
283 days = data.setdefault('days', {}) | |
284 for ctxt in calendar.findall('days/dayContext'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
285 ctxt_type = ctxt.attrib['type'] |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
286 ctxts = days.setdefault(ctxt_type, {}) |
3 | 287 for width in ctxt.findall('dayWidth'): |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
288 width_type = width.attrib['type'] |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
289 widths = ctxts.setdefault(width_type, {}) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
290 for elem in width.getiterator(): |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
291 if elem.tag == 'day': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
292 dtype = weekdays[elem.attrib['type']] |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
293 if ('draft' in elem.attrib or 'alt' not in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
294 and dtype in widths: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
295 continue |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
296 widths[dtype] = unicode(elem.text) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
297 elif elem.tag == 'alias': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
298 ctxts[width_type] = Alias( |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
299 _translate_alias(['days', ctxt_type, width_type], |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
300 elem.attrib['path']) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
301 ) |
3 | 302 |
303 quarters = data.setdefault('quarters', {}) | |
304 for ctxt in calendar.findall('quarters/quarterContext'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
305 ctxt_type = ctxt.attrib['type'] |
3 | 306 ctxts = quarters.setdefault(ctxt.attrib['type'], {}) |
307 for width in ctxt.findall('quarterWidth'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
308 width_type = width.attrib['type'] |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
309 widths = ctxts.setdefault(width_type, {}) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
310 for elem in width.getiterator(): |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
311 if elem.tag == 'quarter': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
312 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
313 and int(elem.attrib['type']) in widths: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
314 continue |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
315 widths[int(elem.attrib['type'])] = unicode(elem.text) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
316 elif elem.tag == 'alias': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
317 ctxts[width_type] = Alias( |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
318 _translate_alias(['quarters', ctxt_type, width_type], |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
319 elem.attrib['path']) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
320 ) |
3 | 321 |
322 eras = data.setdefault('eras', {}) | |
323 for width in calendar.findall('eras/*'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
324 width_type = NAME_MAP[width.tag] |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
325 widths = eras.setdefault(width_type, {}) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
326 for elem in width.getiterator(): |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
327 if elem.tag == 'era': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
328 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
329 and int(elem.attrib['type']) in widths: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
330 continue |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
331 widths[int(elem.attrib.get('type'))] = unicode(elem.text) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
332 elif elem.tag == 'alias': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
333 eras[width_type] = Alias( |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
334 _translate_alias(['eras', width_type], |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
335 elem.attrib['path']) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
336 ) |
3 | 337 |
338 # AM/PM | |
339 periods = data.setdefault('periods', {}) | |
340 for elem in calendar.findall('am'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
341 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
342 and elem.tag in periods: |
3 | 343 continue |
344 periods[elem.tag] = unicode(elem.text) | |
345 for elem in calendar.findall('pm'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
346 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
347 and elem.tag in periods: |
3 | 348 continue |
349 periods[elem.tag] = unicode(elem.text) | |
350 | |
351 date_formats = data.setdefault('date_formats', {}) | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
352 for format in calendar.findall('dateFormats'): |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
353 for elem in format.getiterator(): |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
354 if elem.tag == 'dateFormatLength': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
355 if 'draft' in elem.attrib and \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
356 elem.attrib.get('type') in date_formats: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
357 continue |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
358 try: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
359 date_formats[elem.attrib.get('type')] = \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
360 dates.parse_pattern(unicode(elem.findtext('dateFormat/pattern'))) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
361 except ValueError, e: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
362 print>>sys.stderr, 'ERROR: %s' % e |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
363 elif elem.tag == 'alias': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
364 date_formats = Alias(_translate_alias( |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
365 ['date_formats'], elem.attrib['path']) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
366 ) |
3 | 367 |
368 time_formats = data.setdefault('time_formats', {}) | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
369 for format in calendar.findall('timeFormats'): |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
370 for elem in format.getiterator(): |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
371 if elem.tag == 'timeFormatLength': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
372 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
373 and elem.attrib.get('type') in time_formats: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
374 continue |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
375 try: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
376 time_formats[elem.attrib.get('type')] = \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
377 dates.parse_pattern(unicode(elem.findtext('timeFormat/pattern'))) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
378 except ValueError, e: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
379 print>>sys.stderr, 'ERROR: %s' % e |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
380 elif elem.tag == 'alias': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
381 time_formats = Alias(_translate_alias( |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
382 ['time_formats'], elem.attrib['path']) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
383 ) |
3 | 384 |
35 | 385 datetime_formats = data.setdefault('datetime_formats', {}) |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
386 for format in calendar.findall('dateTimeFormats'): |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
387 for elem in format.getiterator(): |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
388 if elem.tag == 'dateTimeFormatLength': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
389 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
390 and elem.attrib.get('type') in datetime_formats: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
391 continue |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
392 try: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
393 datetime_formats[elem.attrib.get('type')] = \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
394 unicode(elem.findtext('dateTimeFormat/pattern')) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
395 except ValueError, e: |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
396 print>>sys.stderr, 'ERROR: %s' % e |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
397 elif elem.tag == 'alias': |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
398 datetime_formats = Alias(_translate_alias( |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
399 ['datetime_formats'], elem.attrib['path']) |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
400 ) |
35 | 401 |
3 | 402 # <numbers> |
403 | |
404 number_symbols = data.setdefault('number_symbols', {}) | |
405 for elem in tree.findall('//numbers/symbols/*'): | |
406 number_symbols[elem.tag] = unicode(elem.text) | |
407 | |
408 decimal_formats = data.setdefault('decimal_formats', {}) | |
409 for elem in tree.findall('//decimalFormats/decimalFormatLength'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
410 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
411 and elem.attrib.get('type') in decimal_formats: |
3 | 412 continue |
28
695884591af6
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
24
diff
changeset
|
413 pattern = unicode(elem.findtext('decimalFormat/pattern')) |
695884591af6
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
24
diff
changeset
|
414 decimal_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern) |
3 | 415 |
416 scientific_formats = data.setdefault('scientific_formats', {}) | |
417 for elem in tree.findall('//scientificFormats/scientificFormatLength'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
418 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
419 and elem.attrib.get('type') in scientific_formats: |
3 | 420 continue |
127 | 421 pattern = unicode(elem.findtext('scientificFormat/pattern')) |
422 scientific_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern) | |
3 | 423 |
424 currency_formats = data.setdefault('currency_formats', {}) | |
425 for elem in tree.findall('//currencyFormats/currencyFormatLength'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
426 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
427 and elem.attrib.get('type') in currency_formats: |
3 | 428 continue |
127 | 429 pattern = unicode(elem.findtext('currencyFormat/pattern')) |
430 currency_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern) | |
3 | 431 |
432 percent_formats = data.setdefault('percent_formats', {}) | |
433 for elem in tree.findall('//percentFormats/percentFormatLength'): | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
434 if ('draft' in elem.attrib or 'alt' in elem.attrib) \ |
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
435 and elem.attrib.get('type') in percent_formats: |
3 | 436 continue |
28
695884591af6
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
24
diff
changeset
|
437 pattern = unicode(elem.findtext('percentFormat/pattern')) |
695884591af6
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
24
diff
changeset
|
438 percent_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern) |
3 | 439 |
28
695884591af6
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
24
diff
changeset
|
440 currency_names = data.setdefault('currency_names', {}) |
695884591af6
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
24
diff
changeset
|
441 currency_symbols = data.setdefault('currency_symbols', {}) |
3 | 442 for elem in tree.findall('//currencies/currency'): |
387
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
443 code = elem.attrib['type'] |
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
444 # TODO: support plural rules for currency name selection |
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
445 for name in elem.findall('displayName'): |
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
446 if ('draft' in name.attrib or 'count' in name.attrib) \ |
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
447 and code in currency_names: |
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
448 continue |
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
449 currency_names[code] = unicode(name.text) |
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
450 # TODO: support choice patterns for currency symbol selection |
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
451 symbol = elem.find('symbol') |
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
452 if symbol is not None and 'draft' not in symbol.attrib \ |
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
453 and 'choice' not in symbol.attrib: |
88e3589ca8df
Improve CLDR import of currency-related data to ignore unsupported features such as symbol choice patterns and pluralized display names. See #93.
cmlenz
parents:
377
diff
changeset
|
454 currency_symbols[code] = unicode(symbol.text) |
3 | 455 |
235
d0cd235ede46
Upgraded to CLDR 1.5 and improved timezone formatting.
cmlenz
parents:
127
diff
changeset
|
456 outfile = open(os.path.join(destdir, 'localedata', stem + '.dat'), 'wb') |
3 | 457 try: |
458 pickle.dump(data, outfile, 2) | |
459 finally: | |
460 outfile.close() | |
461 | |
377
841858d5b567
Implement support for aliases in the CLDR data. Closes #68. Also, update to CLDR 1.6, and a much improved `dump_data` script.
cmlenz
parents:
347
diff
changeset
|
462 |
3 | 463 if __name__ == '__main__': |
464 main() |