diff options
author | Aarni Koskela <akx@iki.fi> | 2015-12-20 21:53:06 +0200 |
---|---|---|
committer | Aarni Koskela <akx@iki.fi> | 2015-12-21 12:52:18 +0200 |
commit | 29b1724668a2804c48e8950577741c99fb9e2d57 (patch) | |
tree | 62c8586437a3ac4cdea00baa77bef97a7971e614 /scripts | |
parent | 4c8515aae11b2faf4ab81c7412df3d89ee65c6ec (diff) | |
download | babel-29b1724668a2804c48e8950577741c99fb9e2d57.tar.gz |
import_cldr: support currency format lengths
Non-default currency format lengths acquire colon-separated suffixes like units already do since 9327e0824a1bbed538e73d42b971988f8214b490
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/import_cldr.py | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/scripts/import_cldr.py b/scripts/import_cldr.py index d179604..4f70ef9 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 `<currencyFormatLength type="short">`, 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() |