1

How to use action helper in a i18n key. For example, the i18n key is

Please <a{{action displayList}}>click here</a> to display the list.

How to translate this properly with ember runtime(i.e handlebars uncompiled version)

Jan Vlcek
  • 85
  • 7
Dinesh
  • 111
  • 9
  • I don't see anything related to i18n in the code you entered – Mudassir Ali May 29 '13 at 09:36
  • This is an i18n property key. fb.clickhere.msg = Please click here to display the list. using loc helper available in gists, translation is done. The code in handlebars is {{loc fb.clickhere.msg}} – Dinesh May 29 '13 at 09:56
  • Can you please update the question with lil more insight to your code, As per my understanding you defined fb.clickhere.msg = "click here" and you want to render this button using {{loc fb.clickhere.msg}}, If it is so you can do the same using {{loc fb.clickhere.msg}} where fb.clickhere.msg = "click here" – Mudassir Ali May 29 '13 at 10:11
  • Translation should be done for the message completely. Complete message is "Please click here to display the list". The anchor portion is only for "click here". In the case mentioned by you, translation will be broken. – Dinesh May 29 '13 at 11:05

2 Answers2

1

It is been a while since this question was asked, but since I haven't found the solution anywhere, let me put my solution here. The way I solved it is using Handlebars subexpressions. For your example it would look like this:

in translation file

var translations = {
    'fb.clickhere.msg': 'Please <a {{actionDisplayList}}>click here</a> to display the list.'
}

in Handlebars template

{{t 'fb.clickhere.msg' actionDisplayList=(action "displayList") }}
Jan Vlcek
  • 85
  • 7
0

If Handlebar helpers support returning Ember.View instance then the following defined helper should work

{{localizedView fb.clickhere.msg}}

Handlebars.registerBoundHelper("localizedView", function(value, options){
  // value = fb.clickhere.msg
  var localizedString = loc(value); // localizedString = "<a{{action displayList}}>click here</a>"
  return Ember.View.create({template: Ember.Handlebars.compile(localizedString)});
}) // Ofcourse you should define it before you can use this 
Mudassir Ali
  • 7,913
  • 4
  • 32
  • 60