Opened 7 years ago

Closed 7 years ago

#6355 closed (duplicate)

Interpolate function of i18n for javascript is incorrectly documented

Reported by: pigletto Owned by: nobody
Component: Documentation Version: master
Severity: Keywords: interpolate i18n javascript
Cc: pigletto@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Docs at: http://www.djangoproject.com/documentation/i18n/ gives following example:

d = {
    count: 10
};
s = interpolate(ungettext('this is %(count)s object', 'this are %(count)s objects', d.count), d);

but, according to interpolate definition:

function interpolate(fmt, obj, named) {
    if (named) {
        return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});
    } else {
        return fmt.replace(/%s/g, function(match){return String(obj.shift())});
    }
}

there should be third parameter (named) in call to interpolate. Otherwise it always tries to do positional substitution Like:

d = {
    count: 10
};
s = interpolate(ungettext('this is %(count)s object', 'this are %(count)s objects', d.count), d, true);

Change History (2)

comment:1 Changed 7 years ago by Simon Greenhill <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 7 years ago by ramiro

  • Resolution set to duplicate
  • Status changed from new to closed

I'm marking this as a dupe of #6859 that is newer but it also fixes other problems in the same area of the documentation and has a patch.

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