Opened 7 years ago
Last modified 7 years ago
#29986 closed Bug
ngettext_lazy result doesn't support `.format`§ — at Initial Version
| 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
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:
Note:
See TracTickets
for help on using tickets.