0

Is there a way to use i18n on ember/emberjs-bootstrap TextField labels.

For example

{{view "Bootstrap.Forms.TextField"  valueBinding="account.email" label={{t 'account.email'}}}}

This would not work, but I am looking for something if its possible via Handlebars syntax, without me needing to extend each element I want to support i18n.

madth3
  • 7,275
  • 12
  • 50
  • 74
sudhanshu
  • 462
  • 5
  • 17

2 Answers2

2

I'm not sure if you're using Ember-i18n already, but it has a good integration with Ember and seems to be a good start to build on or extend. Here are some simple examples, one using interpolated data.

<h2>{{t user.edit.title}}</h2>

<h2>{{t user.followers.title count="2"}}</h2>

And you keys are defined as

Em.I18n.translations = {
  'user.edit.title': 'Edit User',
  'user.followers.title.one': 'One Follower',
  'user.followers.title.other': 'All {{count}} Followers',
  'button.add_user.title': 'Add a user',
  'button.add_user.text': 'Add',
  'button.add_user.disabled': 'Saving...'
};
ken
  • 3,745
  • 6
  • 34
  • 49
  • Thanks for sharing. I am using this its good but my question is I want to use translations inside TextField view the way I mentioned. I know I can extend it and write the label to use the translations but if there is a direct way to mention label as {{t user.edit.title}}. Please take a peek at code mentioned in question. – sudhanshu Jan 25 '13 at 14:43
  • Effectively my questions falls in handlebars not precisely EmberJS https://github.com/wycats/handlebars.js/issues/222 – sudhanshu Jan 25 '13 at 14:52
0

I am using this as a work around, which is no where close to elegant.

{{#T frontend.signup.name}}
{{view "Bootstrap.Forms.TextField"  valueBinding="account.name"  label=i18Label}}
{{/T}}

Handlebars.registerHelper "T", (key, options) ->
 ret = options.fn( i18Label: I18n.t(key) )

Usually I get a case of one string at a time. Only other way is to extend TextField views.

sudhanshu
  • 462
  • 5
  • 17