lib/translations_ennder/rails.rb in translations_ennder-1.0.0 vs lib/translations_ennder/rails.rb in translations_ennder-1.0.1

- old
+ new

@@ -21,5 +21,31 @@ end else puts "Railx V3.x.y, init_translations_ennder()" init_translations_ennder end + + +class ApplicationController + # Instance methods here + def set_locale + if (params[:locale] and params[:locale].match /^(en|fr)$/) + I18n.locale = params[:locale] + elsif session[:locale].nil? + _http_lang = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first + if _http_lang.match /^(en|fr)$/ + I18n.locale = _http_lang + else + I18n.locale = :fr + end + else + I18n.locale = session[:locale] || :fr + end + +# logger.debug "locale=[#{session[:locale]}]" + + if session[:locale] != I18n.locale + session[:locale] = I18n.locale + end + end +end +