1

I have the following markup in a template:

<p class="form-action-title"><i class="icon-edit"></i> {{t generic.title.edit}} ...</p>

And this is rendered as:

<p class="form-action-title"><i class="icon-edit"></i> <span id="i18n-14">Editar</span> ...</p>

I would like to completely remove the <span> for the translated text (it messes-up my styling). I have tried with:

{{t generic.title.edit tagName=""}}

But has no effect. The strange thing is that, according to the documentation, the following {{t}}:

{{#view Em.Button titleTranslation="button.add_user.title">
  {{t button.add_user.text}}
{{/view}}

Renders no <span>:

<button title="Add a user">
  Add
</button>

(I haven't tried this, I just trust the docs)

What can I do to get rid of the <span>?

blueFast
  • 41,341
  • 63
  • 198
  • 344
  • Guess there is no way to get rid of span in `t` helper as you could see here https://github.com/jamesarosen/ember-i18n/blob/master/lib/i18n.js#L170 – selvagsz Aug 15 '13 at 10:15
  • @Selva-G: Strange anyway that, according to the documentation, `{{t button.add_user.text}}` renders `Add`, without ``. Maybe because it is within a ` – blueFast Aug 15 '13 at 13:37

1 Answers1

2

Two options:

Patch the source: https://github.com/jamesarosen/ember-i18n/blob/master/lib/i18n.js#L133 and https://github.com/jamesarosen/ember-i18n/blob/master/lib/i18n.js#L170

Or create your own simple helper:

Ember.Handlebars.registerHelper('i18n', function(key) {
  return new Handlebars.SafeString(Ember.I18n.t(key))
});

and then

{{i18n generic.title.edit}}

Hope it helps.

intuitivepixel
  • 23,302
  • 3
  • 57
  • 51
  • Thanks, worked like a charm! I had to do `Handlebars.registerHelper('i18n', function(key) {` instead of the `Ember.Handlebars.helper`. I have had this issue before, not sure what it is. They work slightly differently. Anyway, with `Handlebars.registerHelper` works perfectly! – blueFast Aug 15 '13 at 10:35
  • @gonvaled, the difference beetwen `registerHelper` and `helper` is that `registerHelper` is binding un-aware, but if your tranlateable keys are static and don't change while your app is running then `registerHelper` is fine. – intuitivepixel Aug 15 '13 at 10:45