Opened 3 months ago

Closed 12 days ago

#28544 closed Bug (fixed)

unlocalize template filter not consistent with "localize off" for datetimes - does not honor DATETIME_FORMAT

Reported by: Beda Kosata Owned by: nobody
Component: Internationalization Version: 1.11
Severity: Normal Keywords: l10n
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

Hello,

according to the documentation, using {% localize off %}{{ variable }}{% endlocalize %} should be equivalent to {{ variable|unlocalize }}. However, for datetimes the former formats the variable according to DATETIME_FORMAT setting, while the latter does not and uses some default ISO based formatting.

To make a suggestion, I think that the source for the ulocalize filter should be:

@register.filter(is_safe=False)
def unlocalize(value):
    """
    Forces a value to be rendered as a non-localized value,
    regardless of the value of ``settings.USE_L10N``.
    """
    return force_text(formats.localize(value, use_l10n=False))

instead of

@register.filter(is_safe=False)
def unlocalize(value):
    """
    Forces a value to be rendered as a non-localized value,
    regardless of the value of ``settings.USE_L10N``.
    """
    return force_text(value)

Best regards

Beda

Attachments (1)

28544.test.diff (2.3 KB) - added by Claude Paroz 3 months ago.
Failing test

Download all attachments as: .zip

Change History (5)

Changed 3 months ago by Claude Paroz

Attachment: 28544.test.diff added

Failing test

comment:1 Changed 3 months ago by Claude Paroz

Triage Stage: UnreviewedAccepted

comment:2 Changed 4 weeks ago by Claude Paroz

Has patch: set

comment:3 Changed 12 days ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:4 Changed 12 days ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In 1b7780ea:

Fixed #28544 -- Made unlocalize template filter behave like {% localize off %} tag

Thanks Beda Kosata for the report and Tim Graham for the review.

Note: See TracTickets for help on using tickets.
Back to Top