Opened 7 years ago
Closed 7 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 )
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:
Change History (5)
comment:1 by , 7 years ago
| Summary: | ngettext_lazy result doesn't support `.format`§ → ngettext_lazy result doesn't support `.format` |
|---|
comment:2 by , 7 years ago
| Description: | modified (diff) |
|---|---|
| Has patch: | set |
comment:3 by , 7 years ago
| Component: | Uncategorized → Internationalization |
|---|---|
| Patch needs improvement: | set |
| Triage Stage: | Unreviewed → Accepted |
comment:4 by , 7 years ago
| Patch needs improvement: | unset |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
comment:5 by , 7 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
In ae180fa4: