diff --git a/pkg/geoip/geoip.go b/pkg/geoip/geoip.go index 7b61450..c1d0c74 100644 --- a/pkg/geoip/geoip.go +++ b/pkg/geoip/geoip.go @@ -48,9 +48,9 @@ func (g GeoIP) Find(query string, params ...string) (result fmt.Stringer, err er } result = Result{ - Country: record.Country.Names[lang], + Country: getMapLang(record.Country.Names, lang), CountryCode: record.Country.IsoCode, - Area: record.City.Names[lang], + Area: getMapLang(record.City.Names, lang), } return } @@ -72,3 +72,13 @@ func (r Result) String() string { return fmt.Sprintf("%s %s", r.Country, r.Area) } } + +const DefaultLang = "en" + +func getMapLang(data map[string]string, lang string) string { + res, found := data[lang] + if found { + return res + } + return data[DefaultLang] +}