Browse Source

Merge branch 'feature/UpdateHumanize' into develop

tags/release_0.25.1
JackDandy 4 years ago
parent
commit
51c5af601a
  1. 1
      CHANGES.md
  2. 4
      lib/humanize/__init__.py
  3. 21
      lib/humanize/i18n.py
  4. BIN
      lib/humanize/locale/nl_NL/LC_MESSAGES/humanize.mo
  5. 6
      lib/humanize/locale/nl_NL/LC_MESSAGES/humanize.po
  6. 6
      lib/humanize/number.py

1
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)

4
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",
]

21
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

BIN
lib/humanize/locale/nl_NL/LC_MESSAGES/humanize.mo

Binary file not shown.

6
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 <EMAIL@ADDRESS>, 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"

6
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:

Loading…
Cancel
Save