def user_preferred_languages
      return [] if header.to_s.strip.empty?
      @user_preferred_languages ||= begin
        header.to_s.gsub(/\s+/, '').split(',').map do |language|
          locale, quality = language.split(';q=')
          raise ArgumentError, 'Not correctly formatted' unless locale =~ /^[a-z\-0-9]+|\*$/i

          locale  = locale.downcase.gsub(/-[a-z0-9]+$/i, &:upcase) # Uppercase territory
          locale  = nil if locale == '*' # Ignore wildcards

          quality = quality ? quality.to_f : 1.0

          [locale, quality]
        end.sort do |(_, left), (_, right)|
          right <=> left
        end.map(&:first).compact
      rescue ArgumentError # Just rescue anything if the browser messed up badly.
        []
      end
    end
def user_preferred_languages
      return [] if header.to_s.strip.empty?
      @user_preferred_languages ||= begin
        header.to_s.gsub(/\s+/, '').split(',').map do |language|
          locale, quality = language.split(';q=')
          raise ArgumentError, 'Not correctly formatted' unless locale =~ /^[a-z\-0-9]+|\*$/i

          locale  = locale.downcase.gsub(/-[a-z0-9]+$/i, &:upcase) # Uppercase territory
          locale  = nil if locale == '*' # Ignore wildcards

          quality = quality ? quality.to_f : 1.0

          [locale, quality]
        end.sort do |(_, left), (_, right)|
          right <=> left
        end.map(&:first).compact
      rescue ArgumentError # Just rescue anything if the browser messed up badly.
        []
      end
    end
Returns a sorted array based on user preference in HTTP_ACCEPT_LANGUAGE.
 Browsers send this HTTP header, so don't think this is holy.

 Example:

   request.user_preferred_languages
   # => [ 'nl-NL', 'nl-BE', 'nl', 'en-US', 'en' ]