diff --git a/CHANGES.md b/CHANGES.md index 9a3e5e6..1587df5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ * Update attr 20.2.0 (4f74fba) to 20.3.0 (f3762ba) * Update diskcache_py3 5.0.1 (9670fbb) to 5.1.0 (40ce0de) * Update diskcache_py2 4.1.0 (b0451e0) from 5.1.0 (40ce0de) +* Update humanize 3.1.0 (aec9dc2) to 3.2.0 (a0f03c1) * Update Rarfile 3.1 (a4202ca) to 4.0 (55fe778) * Update Requests library 2.24.0 (2f70990) to 2.25.0 (589c454) * Update urllib3 1.25.11 (00f1769) to 1.26.2 (eae04d6) diff --git a/lib/humanize/__init__.py b/lib/humanize/__init__.py index cb9657c..f02bbf8 100644 --- a/lib/humanize/__init__.py +++ b/lib/humanize/__init__.py @@ -1,6 +1,7 @@ """Main package for humanize.""" + from humanize.filesize import naturalsize -from humanize.i18n import activate, deactivate +from humanize.i18n import activate, deactivate, thousands_separator from humanize.number import apnumber, fractional, intcomma, intword, ordinal, scientific from humanize.time import ( naturaldate, @@ -29,5 +30,6 @@ __all__ = [ "ordinal", "precisedelta", "scientific", + "thousands_separator", "VERSION", ] diff --git a/lib/humanize/i18n.py b/lib/humanize/i18n.py index c017789..55e6d66 100644 --- a/lib/humanize/i18n.py +++ b/lib/humanize/i18n.py @@ -4,12 +4,18 @@ import gettext as gettext_module import os.path from threading import local -__all__ = ["activate", "deactivate", "gettext", "ngettext"] +__all__ = ["activate", "deactivate", "gettext", "ngettext", "thousands_separator"] _TRANSLATIONS = {None: gettext_module.NullTranslations()} _CURRENT = local() +# Mapping of locale to thousands separator +_THOUSANDS_SEPARATOR = { + "fr_FR": " ", +} + + def _get_default_locale_path(): try: if __file__ is None: @@ -130,3 +136,16 @@ def gettext_noop(message): str: Original text, unchanged. """ return message + + +def thousands_separator() -> str: + """Return the thousands separator for a locale, default to comma. + + Returns: + str: Thousands separator. + """ + try: + sep = _THOUSANDS_SEPARATOR[_CURRENT.locale] + except (AttributeError, KeyError): + sep = "," + return sep diff --git a/lib/humanize/locale/nl_NL/LC_MESSAGES/humanize.mo b/lib/humanize/locale/nl_NL/LC_MESSAGES/humanize.mo index 541391f..de1be93 100644 Binary files a/lib/humanize/locale/nl_NL/LC_MESSAGES/humanize.mo and b/lib/humanize/locale/nl_NL/LC_MESSAGES/humanize.mo differ diff --git a/lib/humanize/locale/nl_NL/LC_MESSAGES/humanize.po b/lib/humanize/locale/nl_NL/LC_MESSAGES/humanize.po index fdb0480..4d51053 100644 --- a/lib/humanize/locale/nl_NL/LC_MESSAGES/humanize.po +++ b/lib/humanize/locale/nl_NL/LC_MESSAGES/humanize.po @@ -1,5 +1,5 @@ -# French (France) translations for PROJECT. -# Copyright (C) 2013 ORGANIZATION +# Dutch (Netherlands) translations for PROJECT. +# Copyright (C) 2020 ORGANIZATION # This file is distributed under the same license as the PROJECT project. # FIRST AUTHOR , 2013. # @@ -202,7 +202,7 @@ msgstr "een uur" msgid "%d hour" msgid_plural "%d hours" msgstr[0] "%d uur" -msgstr[1] "%d uren" +msgstr[1] "%d uur" #: src/humanize/time.py:148 msgid "a day" diff --git a/lib/humanize/number.py b/lib/humanize/number.py index b9854cd..8b62e4d 100644 --- a/lib/humanize/number.py +++ b/lib/humanize/number.py @@ -10,6 +10,7 @@ from . import compat from .i18n import gettext as _ from .i18n import gettext_noop as N_ from .i18n import pgettext as P_ +from .i18n import thousands_separator def ordinal(value): @@ -99,9 +100,10 @@ def intcomma(value, ndigits=None): Returns: str: string containing commas every three digits. """ + sep = thousands_separator() try: if isinstance(value, compat.string_types): - float(value.replace(",", "")) + float(value.replace(sep, "")) else: float(value) except (TypeError, ValueError): @@ -112,7 +114,7 @@ def intcomma(value, ndigits=None): else: orig = str(value) - new = re.sub(r"^(-?\d+)(\d{3})", r"\g<1>,\g<2>", orig) + new = re.sub(r"^(-?\d+)(\d{3})", r"\g<1>%s\g<2>" % sep, orig) if orig == new: return new else: