package geo import "strings" // countryToLanguage maps an uppercase ISO 3166-1 alpha-2 country code to // an ISO 639-1 lowercase language code. The set is intentionally minimal // — covering the top-traffic Galaxy locales — and is consulted as a // fallback when neither the request body nor the Accept-Language header // supplied a locale at send-email-code. Unknown countries map to the // empty string so the auth flow can default to "en". // // The mapping is intentionally hard-coded rather than derived from the // GeoLite2 database: countries with multiple official languages collapse // to the single most common UI locale to keep the registration path // deterministic. The implementation may revise this table without changing the // surface auth depends on. var countryToLanguage = map[string]string{ // English-default territories and the platform fallback. "US": "en", "GB": "en", "AU": "en", "NZ": "en", "IE": "en", "CA": "en", // Western Europe. "DE": "de", "AT": "de", "CH": "de", "FR": "fr", "BE": "fr", "LU": "fr", "ES": "es", "MX": "es", "AR": "es", "CL": "es", "CO": "es", "IT": "it", "PT": "pt", "BR": "pt", "NL": "nl", // Central / Eastern Europe. "PL": "pl", "RU": "ru", "BY": "ru", "KZ": "ru", "UA": "uk", "CZ": "cs", "SK": "sk", "HU": "hu", "RO": "ro", "BG": "bg", // Northern Europe. "SE": "sv", "NO": "no", "DK": "da", "FI": "fi", // Asia. "JP": "ja", "KR": "ko", "CN": "zh", "TW": "zh", "HK": "zh", "SG": "zh", "VN": "vi", "TH": "th", "ID": "id", "IN": "en", "IL": "he", "TR": "tr", // Middle East and North Africa. "SA": "ar", "AE": "ar", "EG": "ar", } // languageForCountry returns the ISO 639-1 language code mapped to // country, or "" when no mapping is known. country is normalised to // uppercase before lookup. func languageForCountry(country string) string { if country == "" { return "" } return countryToLanguage[strings.ToUpper(strings.TrimSpace(country))] }