Flags
Flags
The package includes 256 SVG country flags, minified and embedded as strings. Flags are keyed by ISO 3166-1 alpha-2 country codes.
SVG Flags
Get a Flag by Country Code
svg, ok := intl.GetFlag("US")
if ok {
fmt.Println(len(svg)) // SVG markup length
}
// Or access the map directly
svg = intl.Flags["US"]Rendering SVG Flags
The SVG strings can be used directly in your application:
// Write to an HTML template
fmt.Fprintf(w, `<div class="flag">%s</div>`, intl.Flags["NO"])
// Save to a file
os.WriteFile("flag.svg", []byte(intl.Flags["NO"]), 0644)Emoji Flags
Emoji flags are generated from country codes using regional indicator symbols.
code := intl.CountryUS
fmt.Println(code.EmojiFlag())
code = intl.CountryNO
fmt.Println(code.EmojiFlag())Language Flags
Languages can have a representative flag via their defaultFlagCode.
lang, ok := intl.LanguageByCode("fr")
if ok && lang.DefaultFlagCode != "" {
flag, flagOk := intl.GetFlag(lang.DefaultFlagCode)
if flagOk {
// Use the French flag SVG
}
}All Available Flags
Iterate over all available flags:
for code, svg := range intl.Flags {
fmt.Printf("%s: %d bytes\n", code, len(svg))
}