-
-
Save thedaviddias/5426689 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Handlebars.registerHelper('loc', function(property, fn) { | |
var str; | |
// we are bound to a value, it is now the context | |
if (fn.contexts && typeof fn.contexts[0] === 'string') { | |
str = fn.contexts[0]; | |
// Convention, start all localization keys with _ | |
} else if (property[0] === '_') { | |
str = property; | |
// Convention, start all globals with capital | |
} else if (/[A-Z]/.test(property[0])) { | |
str = Em.getPath(window, property) | |
// all other's are local properties | |
} else { | |
str = this.getPath(property) | |
} | |
return new Handlebars.SafeString((str || '').loc('')); | |
}); | |
// use: | |
// {{loc _some_string}} | |
// {{#bind App.someString}}{{loc App.someString}}{{/bind}} | |
// {{#bind view.localString}}{{loc view.localString}}{{/bind}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment