Translation update, handle locales precisely

This commit is contained in:
Jakob Borg
2014-08-14 17:04:17 +02:00
parent e78d9ad592
commit dfef929187
7 changed files with 151 additions and 19 deletions

View File

@@ -503,9 +503,8 @@ func restGetLang(w http.ResponseWriter, r *http.Request) {
lang := r.Header.Get("Accept-Language")
var langs []string
for _, l := range strings.Split(lang, ",") {
if len(l) >= 2 {
langs = append(langs, l[:2])
}
parts := strings.SplitN(l, ";", 2)
langs = append(langs, strings.TrimSpace(parts[0]))
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
json.NewEncoder(w).Encode(langs)