mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #27486 -- Fixed Python 3.7 DeprecationWarning in intword and filesizeformat filters.
intword and filesizeformat passed floats to ngettext() which is deprecated in Python 3.7. The rationale for this warning is documented in BPO-28692: https://bugs.python.org/issue28692. For filesizeformat, the filesize value is expected to be an int -- it fills %d string formatting placeholders. It was likely coerced to a float to ensure floating point division on Python 2. Python 3 always does floating point division, so coerce to an int instead of a float to fix the warning. For intword, the number may contain a decimal component. In English, a decimal component makes the noun plural. A helper function, round_away_from_one(), was added to convert the float to an integer that is appropriate for ngettext().
This commit is contained in:
parent
175656e166
commit
9e38ed0536
6 changed files with 51 additions and 7 deletions
|
@ -57,7 +57,9 @@ e.g. with the ``'de'`` language:
|
|||
===========
|
||||
|
||||
Converts a large integer (or a string representation of an integer) to a
|
||||
friendly text representation. Works best for numbers over 1 million.
|
||||
friendly text representation. Translates ``1.0`` as a singular phrase and all
|
||||
other numeric values as plural, this may be incorrect for some languages. Works
|
||||
best for numbers over 1 million.
|
||||
|
||||
Examples:
|
||||
|
||||
|
@ -74,6 +76,11 @@ e.g. with the ``'de'`` language:
|
|||
* ``1200000`` becomes ``'1,2 Millionen'``.
|
||||
* ``1200000000`` becomes ``'1,2 Milliarden'``.
|
||||
|
||||
.. versionchanged:: 3.0
|
||||
|
||||
All numeric values are now translated as plural, except ``1.0`` which is
|
||||
translated as a singular phrase. This may be incorrect for some languages.
|
||||
|
||||
.. templatefilter:: naturalday
|
||||
|
||||
``naturalday``
|
||||
|
|
|
@ -416,6 +416,9 @@ Miscellaneous
|
|||
when ``doseq=False``, rather than iterating them, bringing it into line with
|
||||
the standard library :func:`urllib.parse.urlencode` function.
|
||||
|
||||
* ``intword`` template filter now translates ``1.0`` as a singular phrase and
|
||||
all other numeric values as plural. This may be incorrect for some languages.
|
||||
|
||||
.. _deprecated-features-3.0:
|
||||
|
||||
Features deprecated in 3.0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue