Skip to content

Instantly share code, notes, and snippets.

@mobz
Created March 16, 2010 03:02
Show Gist options
  • Save mobz/333592 to your computer and use it in GitHub Desktop.
Save mobz/333592 to your computer and use it in GitHub Desktop.
// i18n string format method
// usage: messageFormat("hello {0}, welcome {1}", "James", "Home");
function messageFormat(str) {
var args = arguments;
return str.replace(/{(\d)}/g, function(r, n) { return args[+n+1];});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment