From 5d654d249a5d096cfdddd35bd9c143c3f7447b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Tikvi=C4=87?= Date: Thu, 12 Jul 2018 13:05:42 +0200 Subject: [PATCH] interface change --- localization.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/localization.go b/localization.go index 391d7a9..db4a9fb 100644 --- a/localization.go +++ b/localization.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "io/ioutil" - "net/http" "strings" "sync" ) @@ -72,20 +71,19 @@ func (d *Dictionary) GetDefaultLocale() string { return d.defaultLocale } -func (d *Dictionary) GetBestMatchLocale(req *http.Request) (best string) { - accepted := d.parseAcceptedLanguageHeader(req) +func (d *Dictionary) GetBestMatchLocale(acceptedLanguages string) (best string) { + accepted := d.parseAcceptedLanguageHeader(acceptedLanguages) best = accepted[0] return } -func (d *Dictionary) parseAcceptedLanguageHeader(req *http.Request) (langs []string) { - a := req.Header.Get("Accepted-Language") - if a == "" { +func (d *Dictionary) parseAcceptedLanguageHeader(acceptedLanguages string) (langs []string) { + if acceptedLanguages == "" { langs = append(langs, d.GetDefaultLocale()) return } - parts := strings.Split(a, ",") + parts := strings.Split(acceptedLanguages, ",") for _, p := range parts { langs = append(langs, p) } -- 1.8.1.2