Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Add vary accept-language header

Cette révision appartient à :
Eliot Whalan 2017-05-11 23:12:19 +10:00
Parent c1cafb9d9a
révision 521064b946

Voir le fichier

@ -2,8 +2,8 @@ package languages
import (
"fmt"
"github.com/nicksnyder/go-i18n/i18n"
"github.com/ewhal/nyaa/service/user"
"github.com/nicksnyder/go-i18n/i18n"
"html/template"
"net/http"
)
@ -22,7 +22,7 @@ func TfuncWithFallback(language string, languages ...string) (i18n.TranslateFunc
if err1 != nil && err2 != nil {
// fallbackT is still a valid function even with the error, it returns translationID.
return fallbackT, err2;
return fallbackT, err2
}
return func(translationID string, args ...interface{}) string {
@ -42,7 +42,7 @@ func GetAvailableLanguages() (languages map[string]string) {
/* Translation files should have an ID with the translated language name.
If they don't, just use the languageTag */
if languageName := T("language_name"); languageName != "language_name" {
languages[languageTag] = languageName;
languages[languageTag] = languageName
} else {
languages[languageTag] = languageTag
}
@ -67,7 +67,7 @@ func SetTranslationFromRequest(tmpl *template.Template, r *http.Request, default
userLanguage := ""
user, _, err := userService.RetrieveCurrentUser(r)
if err == nil {
userLanguage = user.Language;
userLanguage = user.Language
}
cookie, err := r.Cookie("lang")
@ -78,5 +78,6 @@ func SetTranslationFromRequest(tmpl *template.Template, r *http.Request, default
// go-i18n supports the format of the Accept-Language header, thankfully.
headerLanguage := r.Header.Get("Accept-Language")
r.Header.Add("Vary", "Accept-Encoding")
return SetTranslation(tmpl, userLanguage, cookieLanguage, headerLanguage, defaultLanguage)
}