Skip to content

Commit

Permalink
Add support for number symbols of different numbering systems
Browse files Browse the repository at this point in the history
- Import number symbols for available  numbering systems from cldr data
- Add default_numbering_system  and other_numbering_systems properties for Locale
- Add numbering_system argument to relevant number formatting fuctions and use number symbols based on the given numbering system

Fixes partially issue python-babel#446
  • Loading branch information
kajte committed Nov 23, 2023
1 parent bf7b2ca commit 4336501
Show file tree
Hide file tree
Showing 9 changed files with 496 additions and 83 deletions.
29 changes: 26 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,39 @@ 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 othern numbering systems.
>>> Locale('el', 'GR').other_numbering_systems['traditional']
u'grek'
.. note:: The format of the value returned may change between
Babel versions.
"""
return self._data['numbering_systems']

@property
def default_numbering_system(self) -> str:
"""The default numbering systems 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

0 comments on commit 4336501

Please sign in to comment.