# File lib/gettext-setup/gettext_setup.rb, line 78
  def self.negotiate_locale(accept_header)
    unless @@config
      raise ArgumentError, "No config.yaml found! Use `GettextSetup.initialize(locales_path)` to locate your config.yaml"
    end
    return FastGettext.default_locale if accept_header.nil?
    available_locales = accept_header.split(",").map do |locale|
      pair = locale.strip.split(';q=')
      pair << '1.0' unless pair.size == 2
      pair[0] = FastGettext.default_locale if pair[0] == '*'
      pair
    end.sort_by do |(locale,qvalue)|
      qvalue.to_f
    end.select do |(locale,_)|
      FastGettext.available_locales.include?(locale)
    end
    if available_locales and available_locales.last
      available_locales.last.first
    else
      # We can't satisfy the request preference. Just use the default locale.
      default_locale
    end
  end