travis-web/assets/scripts/app/helpers/i18n_handlebars.coffee
Randy Morgan e4819d8e0b Fixed I18n handlebars helpers to update when locale changes
Via the console, you can Travis.set('locale', 'ja') and all the labels
will properly update. This should work on User#updateLocale as well but
I am having a devil of a time testing it locally as I cannot sign in.
2012-12-11 08:54:43 +09:00

35 lines
806 B
CoffeeScript

I18nBoundView = Ember.View.extend Ember._Metamorph, {
key: null,
valueDidChange: ->
return if this.morph.isRemoved()
this.morph.html(this.valueForRender())
valueForRender: ->
new Handlebars.SafeString I18n.t(this.key)
init: ->
this._super()
Travis.addObserver('locale', this, 'valueDidChange')
didInsertElement: ->
this.valueDidChange()
destroy: ->
Travis.removeObserver('locale', this, 'valueDidChange')
this._super()
render: (buffer) ->
buffer.push(this.valueForRender())
}
Ember.Handlebars.registerHelper 't', (key, options) ->
view = options.data.view
bindView = view.createChildView(I18nBoundView, { key: key })
view.appendChild(bindView)
# dont write any content from this helper, let the child view
# take care of itself.
false