Django

Code

Ticket #6355 (closed: duplicate)

Opened 1 year ago

Last modified 9 months ago

Interpolate function of i18n for javascript is incorrectly documented

Reported by: pigletto Assigned to: nobody
Milestone: Component: Documentation
Version: SVN Keywords: interpolate i18n javascript
Cc: pigletto@gmail.com Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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);

Attachments

Change History

01/13/08 06:12:19 changed by Simon Greenhill <dev@simon.net.nz>

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

03/23/08 14:30:26 changed by ramiro

  • status changed from new to closed.
  • resolution set to duplicate.

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.


Add/Change #6355 (Interpolate function of i18n for javascript is incorrectly documented)




Change Properties
Action