ruby on rails - RubyOnRails - Does not keep the selected language when I refresh the page -


in development mode work fine. not in production mode on heroku.

when select locale , refresh page, displays language default half time , language selected otherwise. not know do. tried clear cache rails.cache.clear command, not work. guess problem cache system. i'm new ruby on rails. have idea how fix this?

to understand problem, can go website, select french language , refresh page several times. once page in french. time in english.

https://releaseit.herokuapp.com/

my application_controller:

  before_action :set_locale   def set_locale     if params[:locale].in? %w(en fr)       i18n.locale = params[:locale]     end   end 

the config files same here: https://github.com/starterkits/rails4-starterkit/tree/master/config

sorry english (i french , use google translator)

i don't know (or see) pass locale in url. far know in order use params[:locale] url should like:

https://releaseit.herokuapp.com/fr/something https://releaseit.herokuapp.com/en/something https://releaseit.herokuapp.com/en https://releaseit.herokuapp.com?locale=fr 

http://guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-url-params

what more try set_locale method:

  def set_locale         if params[:locale]       i18n.locale = params[:locale] || i18n.default_locale     else       i18n.locale = http_accept_language.compatible_language_from(         i18n.available_locales       )     end   end 

set_locale method should executed on every page reload set proper locale each time.

it requires http_accept_language gem from: https://github.com/iain/http_accept_language

check out route_translator gem creating routes locale.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -