0

How do I set the refresh js file when you change the language?

I have translation files in

config/locales/en.yml and pl.yml

and in vendor/assets/javascripts/file.js.erb i have

console.log("<%= I18n.t('test.test') %>")

I included js in app/views/index.html.erb

It works ok, but when I change the cookie with the language and refresh the page js does not change the language?

How i can set compile "file.js.erb" whenever the page is refreshed?

Adrian
  • 532
  • 1
  • 7
  • 16

1 Answers1

0

You don't. In most cases your assets are compiled statically at deploy time.

Wheat that means is that when you create your awesome new "Feature X" your production server should compile the assets when you push to the production server - compiling per request would be really slow.

This means that you should be extremely restrictive with ERB interpolation in your assets files as you should only use variables which are known at compile time such as the paths to other assets.

I would say that it's really best to avoid it except the asset helpers since it just leads to confusion about what is happening where.

If you need to pass data between your server and the client then use data attributes or JSON/AJAX.

<p data-localized="<%= I18n.t('hello') %>">Hello!</p>
max
  • 96,212
  • 14
  • 104
  • 165