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