From: Aarni Koskela Date: Wed, 30 Mar 2016 16:41:52 +0000 (+0300) Subject: CLDR: import unit_patterns as nested dicts X-Git-Tag: 2.3.1~3^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57088a4ebbf6ba6a2c35e2b9f56dac28baeeb9ee;p=thirdparty%2Fbabel.git CLDR: import unit_patterns as nested dicts (Instead of colon-separated flat dicts.) This should not be a breaking change, unless someone has used the private API `l._data["unit_patterns"]`. --- diff --git a/babel/dates.py b/babel/dates.py index 62ba79b9..3c75b385 100644 --- a/babel/dates.py +++ b/babel/dates.py @@ -915,8 +915,7 @@ def format_timedelta(delta, granularity='second', threshold=.85, else: yield unit_rel_patterns['past'] a_unit = 'duration-' + a_unit - yield locale._data['unit_patterns'].get(a_unit + ':' + format) - yield locale._data['unit_patterns'].get(a_unit) + yield locale._data['unit_patterns'].get(a_unit, {}).get(format) for unit, secs_per_unit in TIMEDELTA_UNITS: value = abs(seconds) / secs_per_unit diff --git a/scripts/import_cldr.py b/scripts/import_cldr.py index c3a5e596..58a1a012 100755 --- a/scripts/import_cldr.py +++ b/scripts/import_cldr.py @@ -761,10 +761,9 @@ def parse_unit_patterns(data, tree): unit_length_type = elem.attrib['type'] for unit in elem.findall('unit'): unit_type = unit.attrib['type'] + unit_and_length_patterns = unit_patterns.setdefault(unit_type, {}).setdefault(unit_length_type, {}) for pattern in unit.findall('unitPattern'): - box = unit_type - box += ':' + unit_length_type - unit_patterns.setdefault(box, {})[pattern.attrib['count']] = text_type(pattern.text) + unit_and_length_patterns[pattern.attrib['count']] = _text(pattern) def parse_date_fields(data, tree): @@ -804,6 +803,7 @@ def parse_currency_formats(data, tree): type = elem.attrib.get('type') if curr_length_type: # Handle ``, etc. + # TODO(3.x): use nested dicts instead of colon-separated madness type = '%s:%s' % (type, curr_length_type) if _should_skip_elem(elem, type, currency_formats): continue