Opened 6 years ago

Last modified 6 years ago

#29986 closed Bug

ngettext_lazy result doesn't support `.format` — at Version 2

Reported by: patrick Owned by: nobody
Component: Internationalization Version: 2.1
Severity: Normal Keywords: translations
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by patrick)

I was trying to use ngettext_lazy in combination with str.format and I discovered that it doesn't actually work,
here's a test script that you can try with latest django:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "translation.settings")

import django  # noqa

django.setup()

from django.utils.translation import ugettext_lazy, ngettext_lazy  # noqa

singular_string = ugettext_lazy("this {name} will be translated")
plural_string = ngettext_lazy(
    singular="{total} string will be translated",
    plural="{total} strings will be translated",
    number="total",
)

a = singular_string.format(name="string")

b = plural_string.format(total=2)

print()

print("a:", a)
print("b:", b)

This is the output:

~/D/p/django-ngettext-lazy pipenv run python example.py

a: this string will be translated
b:

EDIT: added a patch here:

โ€‹https://github.com/django/django/pull/10691

Change History (2)

comment:1 by patrick, 6 years ago

Summary: ngettext_lazy result doesn't support `.format`ยง โ†’ ngettext_lazy result doesn't support `.format`

comment:2 by patrick, 6 years ago

Description: modified (diff)
Has patch: set
Note: See TracTickets for help on using tickets.
Back to Top