def compatible_language_from(available_languages)
      user_preferred_languages.map do |preferred| #en-US
        preferred = preferred.downcase
        preferred_language = preferred.split('-', 2).first

        available_languages.find do |available| # en
          available = available.to_s.downcase
          preferred == available || preferred_language == available.split('-', 2).first
        end
      end.compact.first
    end
def compatible_language_from(available_languages)
      user_preferred_languages.map do |preferred| #en-US
        preferred = preferred.downcase
        preferred_language = preferred.split('-', 2).first

        available_languages.find do |available| # en
          available = available.to_s.downcase
          preferred == available || preferred_language == available.split('-', 2).first
        end
      end.compact.first
    end
Returns the first of the user_preferred_languages that is compatible
 with the available locales. Ignores region.

 Example:

   request.compatible_language_from I18n.available_locales