Skip to content

Instantly share code, notes, and snippets.

@igorescobar
Created August 18, 2015 22:40
Show Gist options
  • Save igorescobar/39f2f55af1e09dd51ac3 to your computer and use it in GitHub Desktop.
Save igorescobar/39f2f55af1e09dd51ac3 to your computer and use it in GitHub Desktop.
Registering global mustache helpers
function i18nLambda (text, render) {
text = dict[text] || text
return render(text)
}
var Context = mustache.Context
Context.prototype._lookup = Context.prototype.lookup
Context.prototype.lookup = function i18nLookup (name) {
return (name === 'i18n' ? i18nLambda : this._lookup(name)
}
// {{#i18n}}Hello.{{/i18n}} {{#i18n}}My name is {{ name }}.{{/i18n}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment