Skip to content

Commit

Permalink
localedata: Check inheritance exceptions first
Browse files Browse the repository at this point in the history
When deriving the parent locale from the given name, look first in the
inheritance exception list.  This will cover cases like "es_MX", which
parent is "es_419" and not "es".

Fixes #97
  • Loading branch information
etanol committed Aug 5, 2015
1 parent 504aafe commit 3ef0d6d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions babel/localedata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ def load(name, merge_inherited=True):
if name == 'root' or not merge_inherited:
data = {}
else:
parts = name.split('_')
if len(parts) == 1:
parent = 'root'
else:
parent = '_'.join(parts[:-1])
from babel.core import get_global
parent = get_global('parent_exceptions').get(name)
if not parent:
parts = name.split('_')
if len(parts) == 1:
parent = 'root'
else:
parent = '_'.join(parts[:-1])
data = load(parent).copy()
filename = os.path.join(_dirname, '%s.dat' % name)
fileobj = open(filename, 'rb')
Expand Down
2 changes: 1 addition & 1 deletion babel/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def format_currency(number, currency, format=None, locale=LC_NUMERIC):
>>> format_currency(1099.98, 'USD', locale='en_US')
u'$1,099.98'
>>> format_currency(1099.98, 'USD', locale='es_CO')
u'1.099,98\\xa0US$'
u'US$1.099,98'
>>> format_currency(1099.98, 'EUR', locale='de_DE')
u'1.099,98\\xa0\\u20ac'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def test_format_currency():
assert (numbers.format_currency(1099.98, 'USD', locale='en_US')
== u'$1,099.98')
assert (numbers.format_currency(1099.98, 'USD', locale='es_CO')
== u'1.099,98\xa0US$')
== u'US$1.099,98')
assert (numbers.format_currency(1099.98, 'EUR', locale='de_DE')
== u'1.099,98\xa0\u20ac')
assert (numbers.format_currency(1099.98, 'EUR', u'\xa4\xa4 #,##0.00',
Expand Down

0 comments on commit 3ef0d6d

Please sign in to comment.