diff --git a/HISTORY.rst b/HISTORY.rst index 5129f99..a86bb78 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,11 @@ History ======= +0.2.3 (2025-01-18) +------------------ + +* Fix issues #17: Add support for babel>=2.14.0 and updated Locale.number_symbols format + 0.2.2 (2020-10-29) ------------------ diff --git a/setup.cfg b/setup.cfg index 7d1cdd0..51365d5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.2 +current_version = 0.2.3 commit = True tag = True diff --git a/setup.py b/setup.py index e11bcac..368c04b 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,10 @@ 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', ], description="Spreadsheet Number Format processor - a Python port of SheetJS/ssf.js", install_requires=requirements, @@ -45,6 +49,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/snoopyjc/ssf', - version='0.2.2', + version='0.2.3', zip_safe=False, ) diff --git a/ssf/__init__.py b/ssf/__init__.py index c978676..3105362 100644 --- a/ssf/__init__.py +++ b/ssf/__init__.py @@ -2,6 +2,6 @@ __author__ = """Joe Cool""" __email__ = 'snoopyjc@gmail.com' -__version__ = '0.2.2' +__version__ = '0.2.3' from .ssf import SSF diff --git a/ssf/ssf.py b/ssf/ssf.py index 2abde3c..7215169 100644 --- a/ssf/ssf.py +++ b/ssf/ssf.py @@ -567,13 +567,13 @@ def __init__(self, locale=None, locale_support=True, locale_currency=True, decim locale.months['format']['wide'][month])) self.months_leap = self.months if locale: - self.decimal_point = decimal_separator or locale.number_symbols['decimal'] - self.thousands_sep = thousands_separator or locale.number_symbols['group'] - self.plus_sign = locale.number_symbols['plusSign'] - self.minus_sign = locale.number_symbols['minusSign'] - self.percent_sign = locale.number_symbols['percentSign'] - self.time_separator = locale.number_symbols['timeSeparator'] - self.exponential = locale.number_symbols['exponential'] + self.decimal_point = decimal_separator or self.get_number_symbols_property(locale, 'decimal') + self.thousands_sep = thousands_separator or self.get_number_symbols_property(locale, 'group') + self.plus_sign = self.get_number_symbols_property(locale, 'plusSign') + self.minus_sign = self.get_number_symbols_property(locale, 'minusSign') + self.percent_sign = self.get_number_symbols_property(locale, 'percentSign') + self.time_separator = self.get_number_symbols_property(locale, 'timeSeparator') + self.exponential = self.get_number_symbols_property(locale, 'exponential') self.time_format = locale.time_formats['medium'].pattern.replace('a', 'AM/PM') self.short_date_format = locale.date_formats['short'].pattern.replace('E', 'd'). \ replace('M', 'm') @@ -592,6 +592,13 @@ def __init__(self, locale=None, locale_support=True, locale_currency=True, decim else: raise ValueError(f'Locale {self.locale_name} not found!') + def get_number_symbols_property(self, locale, prop): + """Get a property from the number symbols for the given locale""" + # https://github.com/snoopyjc/ssf/issues/17 + old_val = locale.number_symbols.get(prop) + new_val = locale.number_symbols.get('latn', {}).get(prop) + return old_val or new_val + def normalize_locale(self, locale): """Normalize locale based on examples in the lcid/locale map""" if locale is None: @@ -638,14 +645,15 @@ def commaify(self, s): # Add commas to ints df = ls-ln return s[:df] + self.commaify(s[df:]) if self.locale is not None: + locale_group = self.get_number_symbols_property(self.locale, 'group') if s[0] == '0': # Special processing for leading zeros i = int('1'+s) # Protect them with a leading '1', which we later remove result = format_decimal(i, locale=self.locale) - result = re.sub(r'^1(?:' + re.escape(self.locale.number_symbols['group']) + r')?(.*)$', r'\1', result) + result = re.sub(r'^1(?:' + re.escape(locale_group) + r')?(.*)$', r'\1', result) else: result = format_decimal(int(s), locale=self.locale) - if self.thousands_sep != self.locale.number_symbols['group']: - result = result.replace(self.locale.number_symbols['group'], self.thousands_sep) + if self.thousands_sep != locale_group: + result = result.replace(locale_group, self.thousands_sep) return result w = self.grouping[0] if len(self.grouping) >= 1 else 3