...
1
2
3
4
5 package pkg
6
7 import (
8 "net/http"
9
10 "golang.org/x/text/language"
11 "golang.org/x/text/message"
12 )
13
14 var matcher = language.NewMatcher(message.DefaultCatalog.Languages())
15
16 func Generize(w http.ResponseWriter, r *http.Request) {
17 lang, _ := r.Cookie("lang")
18 accept := r.Header.Get("Accept-Language")
19 tag := message.MatchLanguage(lang.String(), accept)
20 p := message.NewPrinter(tag)
21
22 p.Fprintf(w, "Hello %s!\n", r.Header.Get("From"))
23
24 p.Fprintf(w, "Do you like your browser (%s)?\n", r.Header.Get("User-Agent"))
25 }
26
View as plain text