fivetanley / i18nliner-handlebars

i18nliner, but for your handlebars templates
MIT License
10 stars 9 forks source link

Any tips on how I can use this in an ember-cli project? #5

Open simonexmachina opened 10 years ago

simonexmachina commented 10 years ago

Happy to help out, just want to know how I should approach it.

jenseng commented 10 years ago

@aexmachina we're still sorting out some of the details, and some of it might end up in a new project that uses i18nliner-handlebars as its foundation (maybe i18nliner-ember?). In the meantime it should be possible to make it work with a little bit of duct tape...

  1. You'll need to hook into ember-cli's handlebars compilation so that i18nliner's pre-processor can do its thing. I haven't dug into it too much to know where, but the gist of it is you need to give EmberHandlebars a pre-processed AST rather than the source string, e.g.

    // somewhere inside ember-cli / ember-template-compiler ... assuming we have a `source` var 
    var Handlebars = require('handlebars');
    var ast = Handlebars.parse(source);
    var PreProcessor = require('i18nliner-handlebars/dist/lib/pre_processor')['default'];
    PreProcessor.process(ast);
    var result = EmberHandlebars.precompile(ast).toString();
    // do whatever you usually do with result
  2. You'll need some runtime scripts:
    1. i18n.js
    2. i18nliner's i18n.js extensions
    3. i18nliner handlebars helpers for ember ... see here for something that ought to work.

So yeah, it takes a little bit to wire everything up, but it's not too terrible. I'm using i18nliner in three different ember apps atm, but none of them uses ember-cli (one broccoli, one grunt, and one franken-guard). We'll definitely be improving this in the near term, so watch this space. I'll post some updates and close this ticket once the plan solidifies a bit more.