# HG changeset patch # User cmlenz # Date 1216064779 0 # Node ID e69a068990f07d7b9ca723e25c91c53372eb3b7c # Parent 726144c5f0d112c9b8d58232492030412d9d6f34 Ported [424], [425], and [428] back to 0.9.x branch. diff --git a/0.9.x/babel/__init__.py b/0.9.x/babel/__init__.py --- a/0.9.x/babel/__init__.py +++ b/0.9.x/babel/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2007 Edgewall Software +# Copyright (C) 2007-2008 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which @@ -30,6 +30,10 @@ __docformat__ = 'restructuredtext en' try: - __version__ = __import__('pkg_resources').get_distribution('Babel').version + from pkg_resources import get_distribution, ResolutionError + try: + __version__ = get_distribution('Babel').version + except ResolutionError: + __version__ = None # unknown except ImportError: - pass + __version__ = None # unknown diff --git a/0.9.x/babel/core.py b/0.9.x/babel/core.py --- a/0.9.x/babel/core.py +++ b/0.9.x/babel/core.py @@ -518,7 +518,7 @@ def first_week_day(self): return self._data['week_data']['first_day'] first_week_day = property(first_week_day, doc="""\ - The first day of a week. + The first day of a week, with 0 being Monday. >>> Locale('de', 'DE').first_week_day 0 @@ -531,7 +531,7 @@ def weekend_start(self): return self._data['week_data']['weekend_start'] weekend_start = property(weekend_start, doc="""\ - The day the weekend starts. + The day the weekend starts, with 0 being Monday. >>> Locale('de', 'DE').weekend_start 5 @@ -542,7 +542,7 @@ def weekend_end(self): return self._data['week_data']['weekend_end'] weekend_end = property(weekend_end, doc="""\ - The day the weekend ends. + The day the weekend ends, with 0 being Monday. >>> Locale('de', 'DE').weekend_end 6 diff --git a/0.9.x/babel/numbers.py b/0.9.x/babel/numbers.py --- a/0.9.x/babel/numbers.py +++ b/0.9.x/babel/numbers.py @@ -40,6 +40,20 @@ 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. diff --git a/0.9.x/scripts/dump_data.py b/0.9.x/scripts/dump_data.py --- a/0.9.x/scripts/dump_data.py +++ b/0.9.x/scripts/dump_data.py @@ -36,7 +36,9 @@ if len(args) > 1: for key in args[1].split('.'): data = data[key] - pprint(dict(data.items())) + if isinstance(data, dict): + data = dict(data.items()) + pprint(data) if __name__ == '__main__': diff --git a/0.9.x/scripts/import_cldr.py b/0.9.x/scripts/import_cldr.py --- a/0.9.x/scripts/import_cldr.py +++ b/0.9.x/scripts/import_cldr.py @@ -137,13 +137,11 @@ 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 = {} @@ -442,12 +440,18 @@ 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: