Set locale


#1

Is there any beter way to write this?

before_filter :set_locale

def set_locale
if(params[:locale] and params[:locale].match /^(da|en|de)$/)
I18n.locale = params[:locale]
elsif session[:locale] == nil
xxx = request.env[‘HTTP_ACCEPT_LANGUAGE’].scan(/^[a-z]{2}/).first
if xxx.match /^(da|en|de)$/
I18n.locale = xxx
else
I18n.locale = ‘en’
end
else
I18n.locale = session[:locale] || ‘en’
end
session[:locale] = I18n.locale
end