-
Notifications
You must be signed in to change notification settings - Fork 35
autofetch with Rails 2.3 or newer
Edouard edited this page Jan 20, 2022
·
2 revisions
If you use Rails 2.3 or newer, you should use the rack middleware. If this is not an option for you, you can also do otherwise.
- Before anything, you need to have a rack middleware set up to assign the value of the current locale to
I18n.locale
.
This is very much specific to your app, this is left as an exercise to the reader. You can inspire yourself from Ryan Tomakyo’s locale.rb.
You can also find an example of a very simple middleware using the `locale` parameter in examples/locale.rb
- The next step is to setup the `autofetch` middleware. Add this line in
config/environments/development.rb
and any other environments you want to autofetch:
config.middleware.use "WebTranslateIt::AutoFetch"
- Restart your application, load a page. You should see this in the logs:
Looking for fr_FR translations...
Done. Response code: 200
That’s it!