]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
CLDR: import unit_patterns as nested dicts
authorAarni Koskela <akx@iki.fi>
Wed, 30 Mar 2016 16:41:52 +0000 (19:41 +0300)
committerAarni Koskela <akx@iki.fi>
Tue, 5 Apr 2016 21:22:59 +0000 (00:22 +0300)
(Instead of colon-separated flat dicts.)

This should not be a breaking change, unless someone has used the private
API `l._data["unit_patterns"]`.

babel/dates.py
scripts/import_cldr.py

index 62ba79b966f243b082f2c10c5b68c6e67a87f1ce..3c75b385e1b2bc59e4db3a8829e5310ed57d507b 100644 (file)
@@ -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
index c3a5e596d09609a0d7dd89daf15e479b571d0f62..58a1a012465bc920c822a3e5fb0aec5adf41ab2d 100755 (executable)
@@ -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 `<currencyFormatLength type="short">`, 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