I've spent the last few hours trying everything possible to make this work, googled, redesigned, tested, etc. - but somehow doesn't get it working.
ok, I would like to set the I18n.locale - fairly simple.
Basically I implemented what is written on the guide here:
http://guides.rubyonrails.org/i18n.html
Application_controller.rb
before_action :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
In fact mine looks like this:
class ApplicationController < ActionController::Base
logger.info "Point A..."
before_action :set_locale
def set_locale
logger.info "Point B..."
I18n.locale = extract_locale_from_accept_language_header
end
private
def extract_locale_from_accept_language_header
....
This Problem is that the locale gets set before I can set the locale, when first accessing the page. I would like to read browser settings of user first, if no locale is yet set. To give the user a chance to get to their localized site. If they change the locale subsequently (change language - fine, then the locale is set and that's what they are using until they decide to switch again).
I placed two lines in the code above and this is the output:
Point A...
Processing by StaticPagesController#home as HTML
Parameters: {"locale"=>"en"}
Point B...
I tried the following:
- removed default locale in application.rb: #config.i18n.default_locale = :en
- disabled all gems that could possible interfere (restarted the server each time)
Any help would be appreciated. Thanks, G