Fix language detection, never show untranslated strings (fixes #543)

This commit is contained in:
Jakob Borg 2014-08-28 13:23:23 +02:00
parent f44f5964bb
commit aa827f3042
3 changed files with 18 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

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

View File

@ -91,14 +91,27 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
var lang, matching;
for (var i = 0; i < langs.length; i++) {
lang = langs[i];
matching = validLangs.filter(function (l) {
return lang.length >= 2 && l.indexOf(lang) == 0;
if (lang.length < 2) {
continue;
}
matching = validLangs.filter(function (possibleLang) {
// The langs returned by the /rest/langs call will be in lower
// case. We compare to the lowercase version of the language
// code we have as well.
possibleLang = possibleLang.toLowerCase()
if (possibleLang.length > lang.length) {
return possibleLang.indexOf(lang) == 0;
} else {
return lang.indexOf(possibleLang) == 0;
}
});
if (matching.length >= 1) {
$translate.use(matching[0]);
break;
return;
}
}
// Fallback if nothing matched
$translate.use("en");
})
$(window).bind('beforeunload', function() {