Countries
Countries
The package includes 248+ countries with full ISO 3166-1 metadata.
Country Properties
Each country has the following fields:
| Field | Description |
|---|---|
alpha2Code | ISO 3166-1 alpha-2 code (e.g. "US") |
alpha3Code | ISO 3166-1 alpha-3 code (e.g. "USA") |
numericCode | ISO 3166-1 numeric code (e.g. 840) |
nativeName | Native country name |
capital | Capital city |
mainLanguage | Primary language code |
languages | List of spoken language codes |
tld | Top-level domain (e.g. ".us") |
callingCode | International calling code (e.g. 1) |
continent | Continent identifier |
currency | Primary currency code |
Lookup by Code
Alpha-2 Code
country, ok := intl.CountryByAlpha2("US")
if ok {
fmt.Println(country.NativeName) // United States
fmt.Println(country.Capital) // Washington, D.C.
}Alpha-3 Code
country, ok := intl.CountryByAlpha3("USA")
if ok {
fmt.Println(country.Alpha2Code) // US
}Numeric Code (Dart only)
final country = Country.fromNumericCode(840);
print(country?.nativeName); // United States
List All Countries
allCountries := intl.AllCountries()
fmt.Println(len(allCountries)) // 248Filter by Continent
european := intl.CountriesByContinent("europe")
for _, c := range european {
fmt.Println(c.NativeName)
}SVG Flags
Each country has an inline SVG flag available as a string.
svg, ok := intl.GetFlag("US")
if ok {
// svg contains the full <svg>...</svg> markup
fmt.Println(len(svg))
}
// Or access the map directly
svg = intl.Flags["US"]Emoji Flags
code := intl.CountryUS
fmt.Println(code.EmojiFlag())Country Metadata
country, _ := intl.CountryByAlpha2("JP")
fmt.Println(country.CallingCode) // 81
fmt.Println(country.TLD) // .jp
fmt.Println(country.Currency) // JPY
fmt.Println(country.Continent) // asia
fmt.Println(country.MainLanguage) // ja