0

I have a file app/assets/javascripts/calendar/weekplans.js.erb, which contains some basic erb:

var init_weekplans = function() {
  //..
  allDayText: '<%= t('weekplan.all-day') %>'
  //..
}

Rails fails on (pre)compiling this asset with undefined method 't'. I'd like to use the t() method from ActionView::Helpers::TranslationHelper in there. How do I include this? Is it wise to include this at all, or should I simply push any such variable from the controller or view into this init_weekplans function, instead?

berkes
  • 26,996
  • 27
  • 115
  • 206

1 Answers1

1

You can try with

I18n.t instead of t.
Arkan
  • 6,196
  • 3
  • 38
  • 54
  • Thanks. That does the trick. I did, however, find a crucial mistake in my thinking: when the asset is precompiled it is no longer multilingual, but compiled with the default language instead; so I need to abandon this idea entirely, unfortunately. – berkes Jun 07 '13 at 09:18
  • Yup, you're right. You can take a look at this question though: http://stackoverflow.com/questions/2701749/rails-internationalization-of-javascript-strings – Arkan Jun 07 '13 at 09:32