Skip to content

Instantly share code, notes, and snippets.

@josip
Created April 16, 2009 17:04
Show Gist options
  • Save josip/96526 to your computer and use it in GitHub Desktop.
Save josip/96526 to your computer and use it in GitHub Desktop.
(function () {
var r = /{(\w+)}/g;
window._ = function (s, d) {
if(!s)
return "";
if(!d)
return s;
return s.replace(r, function (c, p) {
return d[p] || "";
});
};
})();
/*
Usage:
_("This is my {0} very long {1}", ["long", "string"]);
_("This is my {desc} very long {what}", {desc:"long", what:"string"});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment