SlexAxton / require-handlebars-plugin

A plugin for handlebars in require.js (both in dev and build)
804 stars 202 forks source link

Using handlebars variables within i18n template strings #54

Closed jorgenhorstink closed 12 years ago

jorgenhorstink commented 12 years ago

Hi,

I'd like to use handlebars variables within the i18n template string;

{ "hello", "Hello {{name}}! Welcome back." }

To make this possible, you'd have to compile the Handlebar template twice, and provide it with the same context.

I made this change to line 387 of the hbs.js file;

- "return t;\n" +
+ "return function (context, options) { var t2 = Handlebars.compile(t(context, options)); return t2(context, options); };\n"

What do you think of this approach, and what is the impact on performance?

regards, Jorgen

SlexAxton commented 12 years ago

I think that'd probably be a bad idea. I've prototyped my ideal solution for using icu messageformat inside of hbs templates, but its not fully fleshed out.

You'll probably want to use a real i18n formatting DSL like my message format.js

Then to see what I've prototyped, check out https://github.com/SlexAxton/messageform.at/blob/master/dev/template/create.hbs

Which uses a modified hbs.js file and ast i18n helper. It compiles the inline templates and writes them out into modules.

Hopefully that helps!