It looks like the the answer for this is in the variable replacement helper tr:
// handlebars helper from i18next
Handlebars.registerHelper('tr', function(context, options) {
var opts = i18n.functions.extend(options.hash, context);
if (options.fn) opts.defaultValue = options.fn(context);
var result = i18n.t(opts.key, opts);
return new Handlebars.SafeString(result);
});
// random "This" object passed in:
var person = {name:"Bob", age:42, eyeColor:"blue"};
//Handlebars string:
{{tr this key='view.WelcomeMessage'}}
// translation.json file
{ "view":
{
"WelcomeMessage": "Welcome, __name__. We've been expecting you."
}
}
// Output
Welcome, Bob. We've been expecting you.
Note that the tr
example given on http://i18next.com/pages/doc_templates.html does have an extra parameter at the end. This is only necessary if you want to replace one of the this
attributes with something else.