Drapeaux

Drapeaux

Le package inclut 256 drapeaux SVG de pays, minifies et integres sous forme de chaines de caracteres. Les drapeaux sont indexes par les codes pays ISO 3166-1 alpha-2.

Drapeaux SVG

Obtenir un drapeau par code pays

GoDartTypeScript
svg, ok := intl.GetFlag("US")
if ok {
    fmt.Println(len(svg)) // SVG markup length
}

// Or access the map directly
svg = intl.Flags["US"]

Afficher les drapeaux SVG

Les chaines SVG peuvent etre utilisees directement dans votre application :

GoDartTypeScript
// 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)

Drapeaux emoji

Les drapeaux emoji sont generes a partir des codes pays en utilisant les symboles indicateurs regionaux.

GoDartTypeScript
code := intl.CountryUS
fmt.Println(code.EmojiFlag())

code = intl.CountryNO
fmt.Println(code.EmojiFlag())

Drapeaux de langues

Les langues peuvent avoir un drapeau representatif via leur defaultFlagCode.

GoDartTypeScript
lang, ok := intl.LanguageByCode("fr")
if ok && lang.DefaultFlagCode != "" {
    flag, flagOk := intl.GetFlag(lang.DefaultFlagCode)
    if flagOk {
        // Use the French flag SVG
    }
}

Tous les drapeaux disponibles

Parcourir tous les drapeaux disponibles :

GoDartTypeScript
for code, svg := range intl.Flags {
    fmt.Printf("%s: %d bytes\n", code, len(svg))
}