acceptlang/handler.go
func Languages() martini.Handler {
	return func(context martini.Context, request *http.Request) {
		header := request.Header.Get(acceptLanguageHeader)
		if header != "" {
			acceptLanguageHeaderValues := strings.Split(header, ",")
			acceptLanguages := make(AcceptLanguages, len(acceptLanguageHeaderValues))

			for i, languageRange := range acceptLanguageHeaderValues {
				// Check if a given range is qualified or not
				if qualifiedRange := strings.Split(languageRange, ";q="); len(qualifiedRange) == 2 {
					quality, error := strconv.ParseFloat(qualifiedRange[1], 32)
					if error != nil {
						// When the quality is unparseable, assume it's 1
						acceptLanguages[i] = AcceptLanguage{trimLanguage(qualifiedRange[0]), 1}
					} else {
						acceptLanguages[i] = AcceptLanguage{trimLanguage(qualifiedRange[0]), float32(quality)}
					}
				} else {
					acceptLanguages[i] = AcceptLanguage{trimLanguage(languageRange), 1}
				}
			}

			sort.Sort(acceptLanguages)
			context.Map(acceptLanguages)
		} else {
			// If we have no Accept-Language header just map an empty slice
			context.Map(make(AcceptLanguages, 0))
		}
	}
}
func Languages() martini.Handler {
	return func(context martini.Context, request *http.Request) {
		header := request.Header.Get(acceptLanguageHeader)
		if header != "" {
			acceptLanguageHeaderValues := strings.Split(header, ",")
			acceptLanguages := make(AcceptLanguages, len(acceptLanguageHeaderValues))

			for i, languageRange := range acceptLanguageHeaderValues {
				// Check if a given range is qualified or not
				if qualifiedRange := strings.Split(languageRange, ";q="); len(qualifiedRange) == 2 {
					quality, error := strconv.ParseFloat(qualifiedRange[1], 32)
					if error != nil {
						// When the quality is unparseable, assume it's 1
						acceptLanguages[i] = AcceptLanguage{trimLanguage(qualifiedRange[0]), 1}
					} else {
						acceptLanguages[i] = AcceptLanguage{trimLanguage(qualifiedRange[0]), float32(quality)}
					}
				} else {
					acceptLanguages[i] = AcceptLanguage{trimLanguage(languageRange), 1}
				}
			}

			sort.Sort(acceptLanguages)
			context.Map(acceptLanguages)
		} else {
			// If we have no Accept-Language header just map an empty slice
			context.Map(make(AcceptLanguages, 0))
		}
	}
}
// Creates a new handler that parses the Accept-Language HTTP header.
//
// The parsed structure is a slice of Accept-Language values stored in an
// AcceptLanguages instance, sorted based on the language qualifier.