Opened 5 years ago

Closed 5 years ago

#29986 closed Bug (fixed)

ngettext_lazy result doesn't support `.format`

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 (5)

comment:1 by patrick, 5 years ago

Summary: ngettext_lazy result doesn't support `.format`§ngettext_lazy result doesn't support `.format`

comment:2 by patrick, 5 years ago

Description: modified (diff)
Has patch: set

comment:3 by Claude Paroz, 5 years ago

Component: UncategorizedInternationalization
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:4 by Claude Paroz, 5 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:5 by Tim Graham <timograham@…>, 5 years ago

Resolution: fixed
Status: newclosed

In ae180fa4:

Fixed #29986 -- Added .format() support to ngettext_lazy strings.

Note: See TracTickets for help on using tickets.
Back to Top