Mercurial > babel > old > mirror
annotate scripts/import_cldr.py @ 129:d6aef0675953
Add a couple of CLI tests.
author | cmlenz |
---|---|
date | Mon, 18 Jun 2007 17:05:00 +0000 |
parents | a72de8971819 |
children | d0cd235ede46 |
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 | |
19 import sys | |
20 try: | |
21 from xml.etree.ElementTree import parse | |
22 except ImportError: | |
23 from elementtree.ElementTree import parse | |
24 | |
67
ad48b95af0d9
Add Babel soruce path to CLDR import script automatically for asmodai ;-).
cmlenz
parents:
36
diff
changeset
|
25 # 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
|
26 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
|
27 |
11 | 28 from babel import dates, numbers |
3 | 29 |
17 | 30 weekdays = {'mon': 0, 'tue': 1, 'wed': 2, 'thu': 3, 'fri': 4, 'sat': 5, |
31 '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
|
32 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
33 try: |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
34 any |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
35 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
|
36 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
|
37 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
|
38 |
3 | 39 def _text(elem): |
40 buf = [elem.text or ''] | |
41 for child in elem: | |
42 buf.append(_text(child)) | |
43 buf.append(elem.tail or '') | |
44 return u''.join(filter(None, buf)).strip() | |
45 | |
46 def main(): | |
47 parser = OptionParser(usage='%prog path/to/cldr') | |
48 options, args = parser.parse_args() | |
49 if len(args) != 1: | |
50 parser.error('incorrect number of arguments') | |
51 | |
52 srcdir = args[0] | |
53 destdir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), | |
54 '..', 'babel', 'localedata') | |
55 | |
10
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
56 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
|
57 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
58 # 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
|
59 regions = {} |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
60 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
|
61 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
|
62 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
63 # 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 |
3 | 74 filenames = os.listdir(os.path.join(srcdir, 'main')) |
75 filenames.remove('root.xml') | |
76 filenames.sort(lambda a,b: len(a)-len(b)) | |
77 filenames.insert(0, 'root.xml') | |
78 | |
79 dicts = {} | |
80 | |
81 for filename in filenames: | |
82 print>>sys.stderr, 'Processing input file %r' % filename | |
83 stem, ext = os.path.splitext(filename) | |
84 if ext != '.xml': | |
85 continue | |
86 | |
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
|
87 tree = parse(os.path.join(srcdir, 'main', filename)) |
3 | 88 data = {} |
89 | |
10
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 territory = elem.attrib['type'] |
15 | 100 else: |
101 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
|
102 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
|
103 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
|
104 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
|
105 |
3 | 106 # <localeDisplayNames> |
107 | |
108 territories = data.setdefault('territories', {}) | |
109 for elem in tree.findall('//territories/territory'): | |
110 if 'draft' in elem.attrib and elem.attrib['type'] in territories: | |
111 continue | |
112 territories[elem.attrib['type']] = _text(elem) | |
113 | |
114 languages = data.setdefault('languages', {}) | |
115 for elem in tree.findall('//languages/language'): | |
116 if 'draft' in elem.attrib and elem.attrib['type'] in languages: | |
117 continue | |
118 languages[elem.attrib['type']] = _text(elem) | |
119 | |
120 variants = data.setdefault('variants', {}) | |
121 for elem in tree.findall('//variants/variant'): | |
122 if 'draft' in elem.attrib and elem.attrib['type'] in variants: | |
123 continue | |
124 variants[elem.attrib['type']] = _text(elem) | |
125 | |
126 scripts = data.setdefault('scripts', {}) | |
127 for elem in tree.findall('//scripts/script'): | |
128 if 'draft' in elem.attrib and elem.attrib['type'] in scripts: | |
129 continue | |
130 scripts[elem.attrib['type']] = _text(elem) | |
131 | |
132 # <dates> | |
133 | |
10
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
134 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
|
135 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
|
136 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 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
|
141 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
142 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
|
143 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
|
144 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
|
145 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
|
146 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 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
|
151 |
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 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
|
156 |
3 | 157 time_zones = data.setdefault('time_zones', {}) |
158 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
|
159 info = {} |
9a00ac84004c
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
28
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 time_zones[elem.attrib['type']] = info |
3 | 168 |
36 | 169 zone_aliases = data.setdefault('zone_aliases', {}) |
170 if stem == 'root': | |
171 for elem in sup.findall('//timezoneData/zoneFormatting/zoneItem'): | |
172 if 'aliases' in elem.attrib: | |
173 canonical_id = elem.attrib['type'] | |
174 for alias in elem.attrib['aliases'].split(): | |
175 zone_aliases[alias] = canonical_id | |
176 | |
3 | 177 for calendar in tree.findall('//calendars/calendar'): |
178 if calendar.attrib['type'] != 'gregorian': | |
179 # TODO: support other calendar types | |
180 continue | |
181 | |
182 months = data.setdefault('months', {}) | |
183 for ctxt in calendar.findall('months/monthContext'): | |
184 ctxts = months.setdefault(ctxt.attrib['type'], {}) | |
185 for width in ctxt.findall('monthWidth'): | |
186 widths = ctxts.setdefault(width.attrib['type'], {}) | |
187 for elem in width.findall('month'): | |
188 if 'draft' in elem.attrib and int(elem.attrib['type']) in widths: | |
189 continue | |
190 widths[int(elem.attrib.get('type'))] = unicode(elem.text) | |
191 | |
192 days = data.setdefault('days', {}) | |
193 for ctxt in calendar.findall('days/dayContext'): | |
194 ctxts = days.setdefault(ctxt.attrib['type'], {}) | |
195 for width in ctxt.findall('dayWidth'): | |
196 widths = ctxts.setdefault(width.attrib['type'], {}) | |
197 for elem in width.findall('day'): | |
10
0ca5dd65594f
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
3
diff
changeset
|
198 dtype = weekdays[elem.attrib['type']] |
3 | 199 if 'draft' in elem.attrib and dtype in widths: |
200 continue | |
201 widths[dtype] = unicode(elem.text) | |
202 | |
203 quarters = data.setdefault('quarters', {}) | |
204 for ctxt in calendar.findall('quarters/quarterContext'): | |
205 ctxts = quarters.setdefault(ctxt.attrib['type'], {}) | |
206 for width in ctxt.findall('quarterWidth'): | |
207 widths = ctxts.setdefault(width.attrib['type'], {}) | |
208 for elem in width.findall('quarter'): | |
209 if 'draft' in elem.attrib and int(elem.attrib['type']) in widths: | |
210 continue | |
211 widths[int(elem.attrib.get('type'))] = unicode(elem.text) | |
212 | |
213 eras = data.setdefault('eras', {}) | |
214 for width in calendar.findall('eras/*'): | |
215 ewidth = {'eraNames': 'wide', 'eraAbbr': 'abbreviated'}[width.tag] | |
216 widths = eras.setdefault(ewidth, {}) | |
217 for elem in width.findall('era'): | |
218 if 'draft' in elem.attrib and int(elem.attrib['type']) in widths: | |
219 continue | |
220 widths[int(elem.attrib.get('type'))] = unicode(elem.text) | |
221 | |
222 # AM/PM | |
223 periods = data.setdefault('periods', {}) | |
224 for elem in calendar.findall('am'): | |
225 if 'draft' in elem.attrib and elem.tag in periods: | |
226 continue | |
227 periods[elem.tag] = unicode(elem.text) | |
228 for elem in calendar.findall('pm'): | |
229 if 'draft' in elem.attrib and elem.tag in periods: | |
230 continue | |
231 periods[elem.tag] = unicode(elem.text) | |
232 | |
233 date_formats = data.setdefault('date_formats', {}) | |
234 for elem in calendar.findall('dateFormats/dateFormatLength'): | |
235 if 'draft' in elem.attrib and elem.attrib.get('type') in date_formats: | |
236 continue | |
237 try: | |
238 date_formats[elem.attrib.get('type')] = \ | |
11 | 239 dates.parse_pattern(unicode(elem.findtext('dateFormat/pattern'))) |
3 | 240 except ValueError, e: |
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
|
241 print>>sys.stderr, 'ERROR: %s' % e |
3 | 242 |
243 time_formats = data.setdefault('time_formats', {}) | |
244 for elem in calendar.findall('timeFormats/timeFormatLength'): | |
245 if 'draft' in elem.attrib and elem.attrib.get('type') in time_formats: | |
246 continue | |
247 try: | |
248 time_formats[elem.attrib.get('type')] = \ | |
11 | 249 dates.parse_pattern(unicode(elem.findtext('timeFormat/pattern'))) |
3 | 250 except ValueError, e: |
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
|
251 print>>sys.stderr, 'ERROR: %s' % e |
3 | 252 |
35 | 253 datetime_formats = data.setdefault('datetime_formats', {}) |
254 for elem in calendar.findall('dateTimeFormats/dateTimeFormatLength'): | |
255 if 'draft' in elem.attrib and elem.attrib.get('type') in datetime_formats: | |
256 continue | |
257 try: | |
258 datetime_formats[elem.attrib.get('type')] = \ | |
259 unicode(elem.findtext('dateTimeFormat/pattern')) | |
260 except ValueError, e: | |
261 print>>sys.stderr, 'ERROR: %s' % e | |
262 | |
3 | 263 # <numbers> |
264 | |
265 number_symbols = data.setdefault('number_symbols', {}) | |
266 for elem in tree.findall('//numbers/symbols/*'): | |
267 number_symbols[elem.tag] = unicode(elem.text) | |
268 | |
269 decimal_formats = data.setdefault('decimal_formats', {}) | |
270 for elem in tree.findall('//decimalFormats/decimalFormatLength'): | |
271 if 'draft' in elem.attrib and elem.attrib.get('type') in decimal_formats: | |
272 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
|
273 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
|
274 decimal_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern) |
3 | 275 |
276 scientific_formats = data.setdefault('scientific_formats', {}) | |
277 for elem in tree.findall('//scientificFormats/scientificFormatLength'): | |
278 if 'draft' in elem.attrib and elem.attrib.get('type') in scientific_formats: | |
279 continue | |
127 | 280 pattern = unicode(elem.findtext('scientificFormat/pattern')) |
281 scientific_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern) | |
3 | 282 |
283 currency_formats = data.setdefault('currency_formats', {}) | |
284 for elem in tree.findall('//currencyFormats/currencyFormatLength'): | |
285 if 'draft' in elem.attrib and elem.attrib.get('type') in currency_formats: | |
286 continue | |
127 | 287 pattern = unicode(elem.findtext('currencyFormat/pattern')) |
288 currency_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern) | |
3 | 289 |
290 percent_formats = data.setdefault('percent_formats', {}) | |
291 for elem in tree.findall('//percentFormats/percentFormatLength'): | |
292 if 'draft' in elem.attrib and elem.attrib.get('type') in percent_formats: | |
293 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
|
294 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
|
295 percent_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern) |
3 | 296 |
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
|
297 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
|
298 currency_symbols = data.setdefault('currency_symbols', {}) |
3 | 299 for elem in tree.findall('//currencies/currency'): |
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
|
300 name = elem.findtext('displayName') |
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
|
301 if name: |
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
|
302 currency_names[elem.attrib['type']] = unicode(name) |
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
|
303 symbol = elem.findtext('symbol') |
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
|
304 if symbol: |
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
|
305 currency_symbols[elem.attrib['type']] = unicode(symbol) |
3 | 306 |
307 dicts[stem] = data | |
308 outfile = open(os.path.join(destdir, stem + '.dat'), 'wb') | |
309 try: | |
310 pickle.dump(data, outfile, 2) | |
311 finally: | |
312 outfile.close() | |
313 | |
314 if __name__ == '__main__': | |
315 main() |