I have two template files: one for the form (loginFormTemplate) and one for the dialog (dialogTemplate). When I put them togheter I only get the i18n on my form (like ${i18n.username}, etc.), but not my dialog html it’s says ${undefined}. I have clearly defined it in my nls file. Why? Here’s my code when I construct my dialog.
var template = lang.replace(dialogTemplate, {
form: loginFormTemplate
});
var contentWidget = new (declare(
[_Widget, _TemplatedMixin, _WidgetsInTemplateMixin],
{
templateString: template,
i18n: i18n
}
));
I could create “variables” just like my form within the dialoTemplate and pass my i18n value, but I don’t find it quite elegant. I just want to do it once. So, instead it would be like this.
var template = lang.replace(dialogTemplate, {
form: loginFormTemplate,
_ok: i18n.okLabel,
_cancel: i18n.cancelLabel
});
var contentWidget = new (declare(
[_Widget, _TemplatedMixin, _WidgetsInTemplateMixin],
{
templateString: template,
i18n: i18n
}
));
Here’s my solution with with phusick answer (my form is notated %[]):
var template = lang.replace(
dialogTemplate,
{form: loginFormTemplate},
/\%\[([^\]]+)\]/g
);
I’m not by my computer, but I guess calling ‘lang.replace’ replaces not only {form}, but also your ${i18n.*} with undefined since only ‘form’ is defined when calling ‘lang.replace’.
Edit: You can use ‘lang.replace’ with a custom pattern to avoid conflicts between i18n and string concatenation: http://livedocs.dojotoolkit.org/dojo/_base/lang#advanced-usage