Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#6247 closed defect (fixed)

[cla/patch] dojo.string.substitute documentation / API issue and small enhancement

Reported by: dante Owned by: alex
Priority: high Milestone: 1.2
Component: String Version: 1.0
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by Adam Peller)

The documentation for dojo.string.substitute states:

// thisObject: 
//		where to look for optional format function; default to the global
//		namespace

though it seems to only ever look in the global namespace? proposed patch provided.

the patch also includes the enhancement: a non core API breaking addition of passing the key to the format and transform functions to allow for (now that the format option is found in context)

The enhancment will be used for a mixin which localizes strings inside dijit templates without having to use local variables. So in a template one could do the following

<li dojoType="dijit.MenuItem">{RESOURCE_ID:localized}</li>

The localized is a "format" function but is actually used to convert the RESOURCE_ID to a localized string.

Attachments (1)

string-proposed.patch (711 bytes) - added by dante 11 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 11 years ago by dante

Description: modified (diff)

Changed 11 years ago by dante

Attachment: string-proposed.patch added

comment:2 Changed 11 years ago by Adam Peller

One thing that might break here is without the use of dojo.getObject, dotted notation won't work for the format function anymore.

comment:3 Changed 11 years ago by James Burke

Not that I quite understand it yet, but realize the using dojo.global might have impact for multiversion support: if you are looking for things like "dijit.foo.bar", then this might not be visible from the dojo.global space. Although I guess, as Adam mentions, that dot notation might not work anyway. But I'm just putting in a note to consider the impact in a multiversion environment.

comment:4 Changed 11 years ago by Adam Peller

Description: modified (diff)

Any way you could get away with using the transform function instead? That gets the key and perhaps you can use some sort of convention.

The patch is a little weird also as it changes the meaning of ${} which is no longer a property lookup... I worry the function is too confusing as it is :-/

comment:5 Changed 11 years ago by alex

Owner: changed from Adam Peller to alex

comment:6 Changed 11 years ago by alex

Resolution: fixed
Status: newclosed

(In [14043]) update docs and unit tests. Also ensure that scoping is correct in dojo.string.substitute() formatters. Fixes #6247. Refs #5962

comment:7 Changed 11 years ago by Adam Peller

why was this committed without working through the above issues?

Note: See TracTickets for help on using tickets.