summaryrefslogtreecommitdiff
path: root/app/controllers/application_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r--app/controllers/application_controller.rb22
1 files changed, 12 insertions, 10 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index b2c5762..b73a463 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -22,18 +22,20 @@ class ApplicationController < ActionController::Base
# ensure that the locale is encoded as the url prefix and I18n.locale is set.
#
def set_locale
- if params[:locale].nil? || !AVAILABLE_LANGUAGES.include?(params[:locale])
- locale = HttpAcceptLanguage::compatible_language_from(request.headers['HTTP_ACCEPT_LANGUAGE'], AVAILABLE_LANGUAGES) || DEFAULT_LOCALE
- locale = locale.to_s.sub('-', '_').sub(/_\w\w/, '')
- if request.path == '/'
- url = '/' + locale
+ if request.format == 'text/html'
+ if params[:locale].nil? || !AVAILABLE_LANGUAGES.include?(params[:locale])
+ locale = HttpAcceptLanguage::compatible_language_from(request.headers['HTTP_ACCEPT_LANGUAGE'], AVAILABLE_LANGUAGES) || DEFAULT_LOCALE
+ locale = locale.to_s.sub('-', '_').sub(/_\w\w/, '')
+ if request.path == '/'
+ url = '/' + locale
+ else
+ url = url_for(params.merge(:locale => locale))
+ end
+ redirect_to url
else
- url = url_for(params.merge(:locale => locale))
+ I18n.locale = params[:locale]
+ self.default_url_options[:locale] = params[:locale]
end
- redirect_to url
- else
- I18n.locale = params[:locale]
- self.default_url_options[:locale] = params[:locale]
end
end