-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provide handlebars helpers #4
Comments
Awesome! Will these integrate with i18nliner-js in some way I assume? |
yeah i'm still figuring out how some of the glue between them should work... i have an app that has i18nliner + i18nliner-js + i18nliner-handlebars all hacked together w/o issues, so it is possible. just need to settle on a nicer/cleaner approach |
my working ember version of these looks like this: Ember.Handlebars.registerHelper("t", function() {
var args = [].slice.call(arguments);
var hbsOptions = args.pop();
if (hbsOptions.fn) {
window.console.log("WARNING: unhandled {{#t}} block call; looks like i18nliner-handlebars pre-processor is not wired up");
// IOW, translations no worky
return hbsOptions.fn(this);
}
var hash = hbsOptions.hash;
var hashTypes = hbsOptions.hashTypes;
var hashContexts = hbsOptions.hashContexts;
var key;
var value;
var type;
var wrappers;
var result;
var options = {};
for (key in hash) {
if (!hash.hasOwnProperty(key)) continue;
value = hash[key];
type = hashTypes[key];
if (type === "ID") {
options[key] = Ember.get(hashContexts[key], value);
} else if (type === "STRING"){
options[key] = value;
}
}
wrappers = [];
while ((key = "w" + wrappers.length) && hash[key]) {
wrappers.push(hash[key]);
}
if (wrappers.length)
options.wrappers = wrappers;
args.push(options);
result = I18n.t.apply(I18n, args);
if (wrappers.length) // i18nliner-js auto html-escapes if there are wrappers
result = new Ember.Handlebars.SafeString(result);
return result;
});
Ember.Handlebars.registerHelper("__i18nliner_escape", function(val) {
return Ember.Handlebars.Utils.escapeExpression(val);
});
Ember.Handlebars.registerHelper("__i18nliner_safe", function(val) {
return Ember.Handlebars.SafeString(val);
});
Ember.Handlebars.registerHelper("__i18nliner_concat", function() {
var args = [].slice.call(arguments, 0, arguments.length - 1);
return args.join("");
}); the vanilla handlebars ones could be quite a bit simpler |
Nice. I'm ok with vanilla handlebars helpers first. I mean, you're doing all the work and stuff I'm just providing input, so it doesn't mean much. When I get some time I'd like to get this wired up with broccoli/ember-cli and work on helpers then. I'd like i18nliner to be the go-to solution for i18n in Emberland as I found the development experience extremely pleasant (thank you!). I know y'all aren't heavily invested in Ember (save for one project maybe?) so this working version is great! Stuff is about to change in emberland with htmlbars coming (eventually ), which gives us compile-time tag balancing warnings and other nice things. |
what do you think about having some of that be in other modules/add-ons? iow, i18nliner-handlebars at most just provides a framework for:
then you could have separate add-ons for things like:
as it is, i am now incorporating i18nliner-handlebars into my third app, and every one of them has a different build process (broccoli vs grunt vs rjs), and a mix of ember-ish vs vanilla handlebars. so i think it'd be good if we weren't too prescriptive about how people use it (in the main/core lib anyway) |
definitely in favor of different addons for all the things |
i'd be happy to work on broccoli if you guys need it soon |
need to provide handlebars helpers for the following:
t
__i18nliner_escape
__i18nliner_safe
__i18nliner_concat
these don't need to be ember-aware; that could potentially be done in an add-on node package
The text was updated successfully, but these errors were encountered: