Forum: Ruby-Forum.com Set locale

Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-03-18 16:48
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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.