changeset 389:a11564c5c1f1 stable-0.9.x

Ported [424], [425], and [428] back to 0.9.x branch.
author cmlenz
date Mon, 14 Jul 2008 19:46:19 +0000
parents 7e3d7532f3d4
children bc9b22b72ff7
files babel/__init__.py babel/core.py babel/numbers.py scripts/dump_data.py scripts/import_cldr.py
diffstat 5 files changed, 40 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/babel/__init__.py
+++ b/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
--- a/babel/core.py
+++ b/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
--- a/babel/numbers.py
+++ b/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.
     
--- a/scripts/dump_data.py
+++ b/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__':
--- a/scripts/import_cldr.py
+++ b/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:
Copyright (C) 2012-2017 Edgewall Software