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