- 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