mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
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:
commit
1da255bfc9
|
@ -31,9 +31,16 @@ func (i *i18nMiddleware) ServeHTTP(ctx context.Context) {
|
||||||
if len(language) > 0 {
|
if len(language) > 0 {
|
||||||
wasByCookie = true
|
wasByCookie = true
|
||||||
} else {
|
} else {
|
||||||
// try to get by the request headers(?)
|
// try to get by the request headers.
|
||||||
if langHeader := ctx.GetHeader("Accept-Language"); i18n.IsExist(langHeader) {
|
langHeader := ctx.GetHeader("Accept-Language")
|
||||||
language = langHeader
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user