Sergio Nekora
Sergio Nekora

Reputation: 319

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

Upvotes: 0

Views: 1022

Answers (1)

Simone Carletti
Simone Carletti

Reputation: 176402

You are missing the quotes.

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

Upvotes: 3

Related Questions