[Django] #29986: ngettext_lazy result doesn't support `.format`§

5 views
Skip to first unread message

Django

unread,
Nov 25, 2018, 4:49:31 PM11/25/18
to django-...@googlegroups.com
#29986: ngettext_lazy result doesn't support `.format`§
-----------------------------------------+------------------------------
Reporter: patrick | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 2.1
Severity: Normal | Keywords: translations
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------------
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:
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29986>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 25, 2018, 4:49:59 PM11/25/18
to django-...@googlegroups.com
#29986: ngettext_lazy result doesn't support `.format`
-------------------------------+--------------------------------------

Reporter: patrick | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 2.1
Severity: Normal | Resolution:

Keywords: translations | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/29986#comment:1>

Django

unread,
Nov 25, 2018, 4:57:10 PM11/25/18
to django-...@googlegroups.com
#29986: ngettext_lazy result doesn't support `.format`
-------------------------------+--------------------------------------

Reporter: patrick | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 2.1
Severity: Normal | Resolution:

Keywords: translations | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by patrick):

* has_patch: 0 => 1


Old description:

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

New description:

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

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29986#comment:2>

Django

unread,
Nov 26, 2018, 2:50:22 AM11/26/18
to django-...@googlegroups.com
#29986: ngettext_lazy result doesn't support `.format`
--------------------------------------+------------------------------------

Reporter: patrick | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 2.1
Severity: Normal | Resolution:
Keywords: translations | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Claude Paroz):

* needs_better_patch: 0 => 1
* component: Uncategorized => Internationalization
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/29986#comment:3>

Django

unread,
Dec 1, 2018, 10:12:41 AM12/1/18
to django-...@googlegroups.com
#29986: ngettext_lazy result doesn't support `.format`
-------------------------------------+-------------------------------------

Reporter: patrick | Owner: nobody
Type: Bug | Status: new
Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution:
Keywords: translations | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29986#comment:4>

Django

unread,
Dec 6, 2018, 3:24:21 PM12/6/18
to django-...@googlegroups.com
#29986: ngettext_lazy result doesn't support `.format`
-------------------------------------+-------------------------------------
Reporter: patrick | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution: fixed

Keywords: translations | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"ae180fa4b7f927a4aeae772975927c9888bb0cb0" ae180fa4]:
{{{
#!CommitTicketReference repository=""
revision="ae180fa4b7f927a4aeae772975927c9888bb0cb0"
Fixed #29986 -- Added .format() support to ngettext_lazy strings.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29986#comment:5>

Reply all
Reply to author
Forward
0 new messages