{"action":"created","issue":{"url":"https://api.github.com/repos/janl/mustache.js/issues/277","labels_url":"https://api.github.com/repos/janl/mustache.js/issues/277/labels{/name}","comments_url":"https://api.github.com/repos/janl/mustache.js/issues/277/comments","events_url":"https://api.github.com/repos/janl/mustache.js/issues/277/events","html_url":"https://github.com/janl/mustache.js/issues/277","id":9014450,"number":277,"title":"Registering global helpers ","user":{"login":"ifthikhan","id":730210,"avatar_url":"https://avatars.githubusercontent.com/u/730210?v=3","gravatar_id":"","url":"https://api.github.com/users/ifthikhan","html_url":"https://github.com/ifthikhan","followers_url":"https://api.github.com/users/ifthikhan/followers","following_url":"https://api.github.com/users/ifthikhan/following{/other_user}","gists_url":"https://api.github.com/users/ifthikhan/gists{/gist_id}","starred_url":"https://api.github.com/users/ifthikhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ifthikhan/subscriptions","organizations_url":"https://api.github.com/users/ifthikhan/orgs","repos_url":"https://api.github.com/users/ifthikhan/repos","events_url":"https://api.github.com/users/ifthikhan/events{/privacy}","received_events_url":"https://api.github.com/users/ifthikhan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/janl/mustache.js/labels/Future","name":"Future","color":"d4c5f9"},{"url":"https://api.github.com/repos/janl/mustache.js/labels/Needs-Feedback","name":"Needs-Feedback","color":"d7e102"},{"url":"https://api.github.com/repos/janl/mustache.js/labels/Plugin","name":"Plugin","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2012-12-05T10:16:10Z","updated_at":"2015-08-18T22:36:38Z","closed_at":null,"body":"Is it possible to register helper functions in a global manner that the calls to render uses the helper when referenced. \n\nI would like to i18n my templates and as far as I can see the helper function needs to be sent with each call to render."},"comment":{"url":"https://api.github.com/repos/janl/mustache.js/issues/comments/132376693","html_url":"https://github.com/janl/mustache.js/issues/277#issuecomment-132376693","issue_url":"https://api.github.com/repos/janl/mustache.js/issues/277","id":132376693,"user":{"login":"dasilvacontin","id":1260830,"avatar_url":"https://avatars.githubusercontent.com/u/1260830?v=3","gravatar_id":"","url":"https://api.github.com/users/dasilvacontin","html_url":"https://github.com/dasilvacontin","followers_url":"https://api.github.com/users/dasilvacontin/followers","following_url":"https://api.github.com/users/dasilvacontin/following{/other_user}","gists_url":"https://api.github.com/users/dasilvacontin/gists{/gist_id}","starred_url":"https://api.github.com/users/dasilvacontin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dasilvacontin/subscriptions","organizations_url":"https://api.github.com/users/dasilvacontin/orgs","repos_url":"https://api.github.com/users/dasilvacontin/repos","events_url":"https://api.github.com/users/dasilvacontin/events{/privacy}","received_events_url":"https://api.github.com/users/dasilvacontin/received_events","type":"User","site_admin":false},"created_at":"2015-08-18T22:36:38Z","updated_at":"2015-08-18T22:36:38Z","body":"Sorry, I should have explained myself better. I meant that I prefer @bobthecow's syntax where text is surrounded by a lambda, which performs the translation.\r\n\r\nIt's very easy to hack that functionality into mustache.js. More or less along the lines of:\r\n```js\r\nfunction i18nLambda (text, render) {\r\n  text = dict[text] || text\r\n  return render(text)\r\n}\r\n\r\nvar Context = mustache.Context\r\nContext.prototype._lookup = Context.prototype.lookup\r\nContext.prototype.lookup = function i18nLookup (name) {\r\n  return (name === 'i18n' ? i18nLambda : this._lookup(name)\r\n}\r\n```\r\n\r\nYou could then:\r\n```hbs\r\n{{#i18n}}Hello.{{/i18n}} {{#i18n}}My name is {{ name }}.{{/i18n}}\r\n```\r\n"}}