LC_NUMERIC = default_locale('LC_NUMERIC')
+def get_currency_name(currency, locale=LC_NUMERIC):
+ """Return the name used by the locale for the specified currency.
+
+ >>> get_currency_name('USD', 'en_US')
+ u'US Dollar'
+
+ :param currency: the currency code
+ :param locale: the `Locale` object or locale identifier
+ :return: the currency symbol
+ :rtype: `unicode`
+ :since: version 0.9.4
+ """
+ return Locale.parse(locale).currencies.get(currency, currency)
+
def get_currency_symbol(currency, locale=LC_NUMERIC):
"""Return the symbol used by the locale for the specified currency.
filenames.insert(0, 'root.xml')
for filename in filenames:
- print>>sys.stderr, 'Processing input file %r' % filename
stem, ext = os.path.splitext(filename)
if ext != '.xml':
continue
- #if stem != 'root':
- # break
+ print>>sys.stderr, 'Processing input file %r' % filename
tree = parse(os.path.join(srcdir, 'main', filename))
data = {}
currency_names = data.setdefault('currency_names', {})
currency_symbols = data.setdefault('currency_symbols', {})
for elem in tree.findall('//currencies/currency'):
- name = elem.findtext('displayName')
- if name:
- currency_names[elem.attrib['type']] = unicode(name)
- symbol = elem.findtext('symbol')
- if symbol:
- currency_symbols[elem.attrib['type']] = unicode(symbol)
+ code = elem.attrib['type']
+ # TODO: support plural rules for currency name selection
+ for name in elem.findall('displayName'):
+ if ('draft' in name.attrib or 'count' in name.attrib) \
+ and code in currency_names:
+ continue
+ currency_names[code] = unicode(name.text)
+ # TODO: support choice patterns for currency symbol selection
+ symbol = elem.find('symbol')
+ if symbol is not None and 'draft' not in symbol.attrib \
+ and 'choice' not in symbol.attrib:
+ currency_symbols[code] = unicode(symbol.text)
outfile = open(os.path.join(destdir, 'localedata', stem + '.dat'), 'wb')
try: