Search code examples
javascriptruby-on-railsruby-on-rails-3.2rails-i18n

Hot get I18.locale from a .js.erb file?


I am trying to do an 'if' statement depending on the language and do to find the right way to make JS to find the locale.

As as I trial I have tried with similar combinations to this, but no avail.

alert(<%= I18n.locale.to_s %>);

The page loads but no alert is shown.

Any idea what I am missing?

Thanks


Solution

  • You are missing the quotes.

    alert('<%= I18n.locale.to_s %>');