Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Version 2.1

- Parse and honour the locale inheritance exceptions
(https://github.com/python-babel/babel/issues/97)
- Add support for spelling numbers (currently only en_GB and hu_HU)
- Fix Locale.parse using ``global.dat`` incompatible types
(https://github.com/python-babel/babel/issues/174)
- Fix display of negative offsets in ``FixedOffsetTimezone``
Expand Down
15 changes: 15 additions & 0 deletions babel/numbers.py → babel/numbers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
from babel.core import default_locale, Locale, get_global
from babel._compat import range_type

from . import _spelling as numspell
numspell.load() # load locale specific submodules


LC_NUMERIC = default_locale('LC_NUMERIC')

Expand Down Expand Up @@ -387,6 +390,18 @@ def format_scientific(number, format=None, locale=LC_NUMERIC):
return pattern.apply(number, locale)


def spell_number(number, locale=LC_NUMERIC, **kwargs):
"""Return value spelled out for a specific locale

:param number: the number to format
:param locale: the `Locale` object or locale identifier
:param kwargs: optional locale specific parameters
"""
locale = Locale.negotiate([str(locale)], numspell._registry.keys())
speller = numspell.NumberSpeller(str(locale))
return speller.apply(number, **kwargs)


class NumberFormatError(ValueError):
"""Exception raised when a string cannot be parsed into a number."""

Expand Down
Loading