1
0

locale.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package geodb
  2. import "net/http"
  3. // GetRequesterCountryISOCode get the locale of the requester
  4. func (s *Store) GetLocaleFromRequest(r *http.Request) (string, error) {
  5. cc := s.GetRequesterCountryISOCode(r)
  6. return GetLocaleFromCountryCode(cc), nil
  7. }
  8. // GetLocaleFromCountryCode get the locale given the country code
  9. func GetLocaleFromCountryCode(cc string) string {
  10. //If you find your country is not in the list, please add it here
  11. mapCountryToLocale := map[string]string{
  12. "aa": "ar_AA",
  13. "by": "be_BY",
  14. "bg": "bg_BG",
  15. "es": "ca_ES",
  16. "cz": "cs_CZ",
  17. "dk": "da_DK",
  18. "ch": "de_CH",
  19. "de": "de_DE",
  20. "gr": "el_GR",
  21. "au": "en_AU",
  22. "be": "en_BE",
  23. "gb": "en_GB",
  24. "jp": "en_JP",
  25. "us": "en_US",
  26. "za": "en_ZA",
  27. "fi": "fi_FI",
  28. "ca": "fr_CA",
  29. "fr": "fr_FR",
  30. "hr": "hr_HR",
  31. "hu": "hu_HU",
  32. "is": "is_IS",
  33. "it": "it_IT",
  34. "il": "iw_IL",
  35. "kr": "ko_KR",
  36. "lt": "lt_LT",
  37. "lv": "lv_LV",
  38. "mk": "mk_MK",
  39. "nl": "nl_NL",
  40. "no": "no_NO",
  41. "pl": "pl_PL",
  42. "br": "pt_BR",
  43. "pt": "pt_PT",
  44. "ro": "ro_RO",
  45. "ru": "ru_RU",
  46. "sp": "sh_SP",
  47. "sk": "sk_SK",
  48. "sl": "sl_SL",
  49. "al": "sq_AL",
  50. "se": "sv_SE",
  51. "th": "th_TH",
  52. "tr": "tr_TR",
  53. "ua": "uk_UA",
  54. "cn": "zh_CN",
  55. "tw": "zh_TW",
  56. "hk": "zh_HK",
  57. }
  58. locale, ok := mapCountryToLocale[cc]
  59. if !ok {
  60. return "en-US"
  61. }
  62. return locale
  63. }