Skip to content

Commit

Permalink
Add support for non-Latin numbering systems for number symbols (#1036)
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

Refs #446

Co-authored-by: Aarni Koskela <akx@iki.fi>
  • Loading branch information
kajte and akx authored Nov 28, 2023
1 parent d4e65e2 commit aca7663
Show file tree
Hide file tree
Showing 9 changed files with 503 additions and 82 deletions.
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.
"""
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

0 comments on commit aca7663

Please sign in to comment.