#14181 closed (fixed)
Template tag needed to disable/force L10N formatting on a per-variable basis
Reported by: | Russell Keith-Magee | Owned by: | Benjamin Wohlwend |
---|---|---|---|
Component: | Internationalization | Version: | 1.2 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The L10N support added in Django 1.2 is great, but there are times when you don't want to use L10N, regardless of any system settings.
#14164 is one manifestation of this problem. Outside of sitemaps, any data being rendered to XML (or any other format for data interchange) is generally going to need data to be rendered in "english" locale format.
A simple workaround is to render the value to a string in the context, so that the template renders a string, not an integer/float. However, a more general appoach is required.
Some possible options: A template filter to disable localization:
{{ value|unlocalized }}
A template filter to force a specific localization:
{{ value|locale:"en" }}
Or, template tag variants of the same:
{% unlocalized %} {{ value }} {% endunlocalized %} {% localize "en" %} {{ value }} {% endlocalize %}
The "localize" filter is the easiest to implement, but probably not the easiest to use.
Attachments (3)
Change History (9)
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:2 by , 14 years ago
Triage Stage: | Design decision needed → Accepted |
---|
comment:3 by , 14 years ago
milestone: | → 1.3 |
---|---|
Owner: | changed from | to
How about
{% localize off %} {{ value }} {% endlocalize %} {% localize "de-ch" %} {{ value }} {% endlocalize %}
using {% localize off %}
instead of {% unlocalized %}
would save us one additional tag in the global namespace. Granted, {% endlocalize %}
to re-enable localization looks a little weird, but there's precedence in the {% autoescape %}
tag.
I'll adapt my patch from #13617 to this syntax and upload it here.
by , 14 years ago
Attachment: | localize-template-tag.diff added |
---|
Implementation of {% localization %} template tag
comment:4 by , 14 years ago
Has patch: | set |
---|---|
Status: | new → assigned |
I rewrote the patch from #13617 to the proposed syntax. For {% localize on %}
and {% localize "some-locale" %}
to make any sense, the tag has to be able to override USE_L10N
. This makes the patch a little more intrusive than I'd liked to (see django/utils/formats.py
in the patch).
by , 14 years ago
Attachment: | localize-template-tag-2.diff added |
---|
Changes proposed by russellm on django-developers
comment:5 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
If/when this is accepted, the fix for #14164 should be updated to use this new technique.