{{{
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/29986#comment:1>
* 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>
* needs_better_patch: 0 => 1
* component: Uncategorized => Internationalization
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/29986#comment:3>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29986#comment:4>
* 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>