Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/util/languages/translation.go
sfan5 e3a271cca7 Revert "Added Profile page"
This reverts commit 5860cf1d79.
2017-05-08 22:50:25 +02:00

27 lignes
752 o
Go

package languages
import (
"github.com/nicksnyder/go-i18n/i18n"
"html/template"
"net/http"
)
func SetTranslation(tmpl *template.Template, language string, languages ...string) {
T, _ := i18n.Tfunc(language, languages...)
tmpl.Funcs(map[string]interface{}{
"T": func(str string) template.HTML {
return template.HTML(T(str))
},
})
}
func SetTranslationFromRequest(tmpl *template.Template, r *http.Request, defaultLanguage string) {
cookie, err := r.Cookie("lang")
cookieLanguage := ""
if err == nil {
cookieLanguage = cookie.Value
}
// go-i18n supports the format of the Accept-Language header, thankfully.
headerLanguage := r.Header.Get("Accept-Language")
SetTranslation(tmpl, cookieLanguage, headerLanguage, defaultLanguage)
}