Forum: Ruby-Forum.com Set locale

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
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
This topic is locked and can not be replied to.