Opened 8 years ago
Closed 6 years ago
#27486 closed Cleanup/optimization (fixed)
intword and filesizeformat filters shouldn't pass non-integers to gettext
Reported by: | Tim Graham | Owned by: | |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Python plans to deprecate selecting plural form by fractional numbers. The intword
and filesizeformat
template filters are currently doing this:
$ python -Wall tests/runtests.py humanize_tests.tests.HumanizeTests.test_i18n_intword Testing against Django installed in '/home/tim/code/django/django' with up to 3 processes Creating test database for alias 'default'... Creating test database for alias 'other'... /home/tim/code/django/django/utils/translation/trans_real.py:373: DeprecationWarning: Plural value must be an integer, got float return getattr(t, translation_function)(singular, plural, number) .
python -Wall tests/runtests.py template_tests.filter_tests.test_filesizeformat.FunctionTests.test_localized_formats Testing against Django installed in '/home/tim/code/django/django' with up to 3 processes Creating test database for alias 'default'... Creating test database for alias 'other'... /home/tim/code/django/django/utils/translation/trans_real.py:373: DeprecationWarning: Plural value must be an integer, got float return getattr(t, translation_function)(singular, plural, number) .
Change History (6)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
My PR does naive int()
casting. I closed it since it seems a more involved solution would be better. Perhaps we could look to see how other projects handle the issue.
comment:3 by , 8 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
Note:
See TracTickets
for help on using tickets.
The exact rule about pluralizing floats/decimals depends on the language, so whether we floor or ceil the number before passing it to
ngettext
we'll do the right thing for some languages and wrong for others. This is a known limitation of thegettext
spec (in C,ngettext
is only accepting integers). We should make a choice and then document the limitation.It would not be impossible to try providing a language-specific hook in the LANG_INFO structure and call that hook when converting floats to ints.