Countries

Countries

The package includes 248+ countries with full ISO 3166-1 metadata.

Country Properties

Each country has the following fields:

FieldDescription
alpha2CodeISO 3166-1 alpha-2 code (e.g. "US")
alpha3CodeISO 3166-1 alpha-3 code (e.g. "USA")
numericCodeISO 3166-1 numeric code (e.g. 840)
nativeNameNative country name
capitalCapital city
mainLanguagePrimary language code
languagesList of spoken language codes
tldTop-level domain (e.g. ".us")
callingCodeInternational calling code (e.g. 1)
continentContinent identifier
currencyPrimary 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)) // 248

Filter 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