Update i18n middleware and toolkit methods to support IETF and RFC2616.

Add IETF matching method to vendor unkwon/i18n.
Update i18n middleware to support RFC2616.


Former-commit-id: 186f08dec3eb98df13bf2a0da61f0a31fe135358
This commit is contained in:
Jörn Lenoch 2017-08-02 00:49:21 +02:00
parent 351f099ad6
commit 3a3d1f24a1

View File

@ -31,9 +31,16 @@ func (i *i18nMiddleware) ServeHTTP(ctx context.Context) {
if len(language) > 0 {
wasByCookie = true
} else {
// try to get by the request headers(?)
if langHeader := ctx.GetHeader("Accept-Language"); i18n.IsExist(langHeader) {
language = langHeader
// try to get by the request headers.
langHeader := ctx.GetHeader("Accept-Language")
if len(langHeader) > 0 {
for _, langEntry := range strings.Split(langHeader, ",") {
lc := strings.Split(langEntry, ";")[0]
if lc, ok := i18n.IsExistSimilar(lc); ok {
language = lc
break
}
}
}
}
}