Länder
Länder
Das Paket enthält 248+ Länder mit vollständigen ISO 3166-1-Metadaten.
Ländereigenschaften
Jedes Land hat die folgenden Felder:
| Feld | Beschreibung |
|---|---|
alpha2Code | ISO 3166-1 Alpha-2-Code (z.B. "US") |
alpha3Code | ISO 3166-1 Alpha-3-Code (z.B. "USA") |
numericCode | ISO 3166-1 numerischer Code (z.B. 840) |
nativeName | Eigenname des Landes |
capital | Hauptstadt |
mainLanguage | Primärer Sprachcode |
languages | Liste der gesprochenen Sprachcodes |
tld | Top-Level-Domain (z.B. ".us") |
callingCode | Internationale Vorwahl (z.B. 1) |
continent | Kontinent-Bezeichner |
currency | Primärer Währungscode |
Suche nach 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
}Numerischer Code (nur Dart)
final country = Country.fromNumericCode(840);
print(country?.nativeName); // United States
Alle Länder auflisten
allCountries := intl.AllCountries()
fmt.Println(len(allCountries)) // 248Nach Kontinent filtern
european := intl.CountriesByContinent("europe")
for _, c := range european {
fmt.Println(c.NativeName)
}SVG-Flaggen
Für jedes Land ist eine eingebettete SVG-Flagge als String verfügbar.
svg, ok := intl.GetFlag("US")
if ok {
// svg enthält das vollständige <svg>...</svg>-Markup
fmt.Println(len(svg))
}
// Oder direkt auf die Map zugreifen
svg = intl.Flags["US"]Emoji-Flaggen
code := intl.CountryUS
fmt.Println(code.EmojiFlag())Länder-Metadaten
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