Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of local numbering systems for number symbols #1036

Merged
merged 3 commits into from
Nov 28, 2023
Merged
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
32 changes: 29 additions & 3 deletions babel/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Locale:
`Locale` objects provide access to a collection of locale data, such as
territory and language names, number and date format patterns, and more:

>>> locale.number_symbols['decimal']
>>> locale.number_symbols['latn']['decimal']
u'.'

If a locale is requested for which no locale data is available, an
Expand Down Expand Up @@ -625,16 +625,42 @@ def currency_symbols(self) -> localedata.LocaleDataDict:

@property
def number_symbols(self) -> localedata.LocaleDataDict:
"""Symbols used in number formatting.
"""Symbols used in number formatting by number system.

.. note:: The format of the value returned may change between
Babel versions.

>>> Locale('fr', 'FR').number_symbols['decimal']
>>> Locale('fr', 'FR').number_symbols["latn"]['decimal']
u','
>>> Locale('fa', 'IR').number_symbols["arabext"]['decimal']
u'٫'
>>> Locale('fa', 'IR').number_symbols["latn"]['decimal']
u'.'
"""
return self._data['number_symbols']

@property
def other_numbering_systems(self) -> localedata.LocaleDataDict:
"""
Mapping of other numbering systems available for the locale.
See: https://www.unicode.org/reports/tr35/tr35-numbers.html#otherNumberingSystems

>>> Locale('el', 'GR').other_numbering_systems['traditional']
u'grek'

.. note:: The format of the value returned may change between
Babel versions.
"""
kajte marked this conversation as resolved.
Show resolved Hide resolved
return self._data['numbering_systems']

@property
def default_numbering_system(self) -> str:
"""The default numbering system used by the locale.
>>> Locale('el', 'GR').default_numbering_system
u'latn'
"""
return self._data['default_numbering_system']

@property
def decimal_formats(self) -> localedata.LocaleDataDict:
"""Locale patterns for decimal number formatting.
Expand Down
Loading