Merge pull request #697 from j-lenoch/i18n-accept-language-header

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

Former-commit-id: 9926dafa40c422b4a6f8f859ca43cebebab3cd24
This commit is contained in:
Bill Q 2017-08-02 03:32:42 +03:00 committed by GitHub
commit 1da255bfc9

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
}
}
}
}
}