Opened 18 years ago
Closed 18 years ago
#6355 closed (duplicate)
Interpolate function of i18n for javascript is incorrectly documented
| Reported by: | Maciej Wiśniowski | Owned by: | nobody |
|---|---|---|---|
| Component: | Documentation | Version: | dev |
| 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: | no | UI/UX: | no |
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 by , 18 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 18 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
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.