]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/application_controller.rb
Make sure "please read the terms" error is issued in the right language
[rails.git] / app / controllers / application_controller.rb
index 34987c93880f87141084d5e7bca4c8d62e7f5c60..657cb27e3abd381a687ed7ce0a51ea210d49c1f4 100644 (file)
@@ -111,6 +111,7 @@ class ApplicationController < ActionController::Base
       # allow editing - they have to go to the web site and see
       # (but can decline) the CTs to continue.
       if REQUIRE_TERMS_SEEN and not @user.terms_seen
+        set_locale
         render :text => t('application.setup_user_auth.need_to_see_terms'), :status => :forbidden
       end
     end
@@ -199,6 +200,24 @@ class ApplicationController < ActionController::Base
       end
     end
 
+    if request.compatible_language_from(I18n.available_locales).nil?
+      request.user_preferred_languages = request.user_preferred_languages.collect do |pl|
+        pls = [ pl ]
+
+        while pl.match(/^(.*)-[^-]+$/)
+          pls.push($1) if I18n.available_locales.include?($1.to_sym)
+          pl = $1
+        end
+
+        pls
+      end.flatten
+
+      if @user and not request.compatible_language_from(I18n.available_locales).nil?
+        @user.languages = request.user_preferred_languages
+        @user.save        
+      end
+    end
+
     I18n.locale = request.compatible_language_from(I18n.available_locales)
 
     response.headers['Content-Language'] = I18n.locale.to_s