- if @user
- if !@user.languages.empty?
- request.user_preferred_languages = @user.languages
- response.header['Vary'] = '*'
- elsif !request.user_preferred_languages.empty?
- @user.languages = request.user_preferred_languages
- @user.save
- end
+ if @user && !@user.languages.empty?
+ request.user_preferred_languages = @user.languages
+ response.header['Vary'] = '*'
+ end
+
+ I18n.locale = select_locale
+
+ if @user && @user.languages.empty? && !request.user_preferred_languages.empty?
+ @user.languages = request.user_preferred_languages
+ @user.save
+ end
+
+ response.headers['Content-Language'] = I18n.locale.to_s
+ end
+
+ def select_locale(locales = I18n.available_locales)
+ if params[:locale]
+ request.user_preferred_languages = [ params[:locale] ]