From: Aarni Koskela Date: Sun, 20 Dec 2015 19:53:06 +0000 (+0200) Subject: import_cldr: support currency format lengths X-Git-Tag: 2.2.0~1^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29b1724668a2804c48e8950577741c99fb9e2d57;p=thirdparty%2Fbabel.git import_cldr: support currency format lengths Non-default currency format lengths acquire colon-separated suffixes like units already do since 9327e0824a1bbed538e73d42b971988f8214b490 --- diff --git a/scripts/import_cldr.py b/scripts/import_cldr.py index d179604c..4f70ef9b 100755 --- a/scripts/import_cldr.py +++ b/scripts/import_cldr.py @@ -600,21 +600,7 @@ def main(): scientific_formats[elem.attrib.get('type')] = \ numbers.parse_pattern(pattern) - currency_formats = data.setdefault('currency_formats', {}) - for elem in tree.findall('.//currencyFormats/currencyFormatLength/currencyFormat'): - if ('draft' in elem.attrib or 'alt' in elem.attrib) \ - and elem.attrib.get('type') in currency_formats: - continue - for child in elem.getiterator(): - if child.tag == 'alias': - currency_formats[elem.attrib.get('type')] = Alias( - _translate_alias(['currency_formats', elem.attrib['type']], - child.attrib['path']) - ) - elif child.tag == 'pattern': - pattern = text_type(child.text) - currency_formats[elem.attrib.get('type')] = \ - numbers.parse_pattern(pattern) + parse_currency_formats(data, tree) percent_formats = data.setdefault('percent_formats', {}) for elem in tree.findall('.//percentFormats/percentFormatLength'): @@ -674,5 +660,27 @@ def main(): outfile.close() +def parse_currency_formats(data, tree): + currency_formats = data.setdefault('currency_formats', {}) + for length_elem in tree.findall('.//currencyFormats/currencyFormatLength'): + curr_length_type = length_elem.attrib.get('type') + for elem in length_elem.findall('currencyFormat'): + type = elem.attrib.get('type') + if curr_length_type: + # Handle ``, etc. + type = '%s:%s' % (type, curr_length_type) + if ('draft' in elem.attrib or 'alt' in elem.attrib) and type in currency_formats: + continue + for child in elem.getiterator(): + if child.tag == 'alias': + currency_formats[type] = Alias( + _translate_alias(['currency_formats', elem.attrib['type']], + child.attrib['path']) + ) + elif child.tag == 'pattern': + pattern = text_type(child.text) + currency_formats[type] = numbers.parse_pattern(pattern) + + if __name__ == '__main__': main()