Opened 9 years ago

Closed 9 years ago

#25856 closed New feature (fixed)

JS strftime shim could (sometimes) support %B

Reported by: Keryn Knight Owned by: Akos Zsolt Hochrein
Component: Internationalization Version: dev
Severity: Normal Keywords:
Cc: django@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, using the calendar widget in the admin, when the first DATE_INPUT_FORMATS is %B %d, %Y you end up outputting undefined 03, 2015

At a glance (and a monolingual one at that) I think it ought to be possible to shim support for %B specifically in, at least sometimes; specifically, adding the following to admin/js/core.js:Date.prototype.strftime:

var fields = { ... }
if (typeof gettext !== "undefined" && typeof CalendarNamespace !== "undefined") {
    fields.B = CalendarNamespace.monthsOfYear[this.getMonth()]
}

thus, if the javascript catalog (jsi18n) is loaded, along with the calendar widget itself (calendar.js), an additional shim is added for whatever the locale's full month name is.

Marked as as an internationalization issue because the format is locale specific. Vaguely relates to #25024 if you squint at it.

NB: for the purposes of suggestion, I've gone with attempting to access gettext as a window global; it could instead test for window.gettext or django.gettext, I think.

Change History (6)

comment:1 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted

I guess if we have a patch, that will tell whether or not it's feasible. :-)

comment:2 by Akos Zsolt Hochrein, 9 years ago

I'd recommend using something like this:

...
    Date.prototype.getFullMonthName = function() {
        return typeof CalendarNamespace === "undefined"
            ? this.getTwoDigitMonth()
            : CalendarNamespace.monthsOfYear[this.getMonth()];
    };
...
    Date.prototype.strftime = function(format) {
        var fields = {
            ...
            B: this.getFullMonthName(),
            ...
        };
        ...
    };

comment:3 by Akos Zsolt Hochrein, 9 years ago

Owner: changed from nobody to Akos Zsolt Hochrein
Status: newassigned

comment:4 by Akos Zsolt Hochrein, 9 years ago

comment:5 by Tim Graham, 9 years ago

Has patch: set

comment:6 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In ab2d34ba:

Fixed #25856 -- Added %B support to Date.strftime.

This enables the admin to display the correct localized month name if %B
is used in the date format.

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