Skip to content
Open
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
21 changes: 21 additions & 0 deletions babel/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from babel.core import Locale, default_locale, get_global
from babel.localedata import LocaleDataDict
from babel.rbnf import RuleBasedNumberFormat

LC_MONETARY = default_locale(('LC_MONETARY', 'LC_NUMERIC'))
LC_NUMERIC = default_locale('LC_NUMERIC')
Expand Down Expand Up @@ -1023,6 +1024,26 @@ def __init__(self, message: str, suggestions: list[str] | None = None) -> None:
SPACE_CHARS_RE = re.compile('|'.join(SPACE_CHARS))


def spell_number(number, locale=LC_NUMERIC, ruleset=None):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add type annotations here, please?

"""Return value spelled out for a specific locale

:param number: the number to format
:param locale: the `Locale` object or locale identifier
:param ruleset: the ruleset to use; defaults to regular numbers.
"""
speller = RuleBasedNumberFormat.negotiate(locale)
return speller.format(number, ruleset=ruleset)


def get_rbnf_rules(locale=LC_NUMERIC):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this needs to be a public API? (If it is, it also locks down the public API for RuleBasedNumberFormat.) Or... WDYT, what sort of app would consume the raw rules?

"""Return all the available public rules for a specific locale

:param locale: the `Locale` object or locale identifier
"""
speller = RuleBasedNumberFormat.negotiate(locale)
return speller.available_rulesets


def parse_number(
string: str,
locale: Locale | str | None = None,
Expand Down
Loading
Loading