1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "golang.org/x/text/language"
11 "golang.org/x/text/language/display"
15 supported := []string{
16 "en-US", "en-GB", "ja", "zh", "zh-Hans", "zh-Hant", "pt", "pt-PT", "ko", "ar", "el", "ru", "uk", "pa",
19 en := display.English.Languages()
21 for _, s := range supported {
22 t := language.MustParse(s)
23 fmt.Printf("%-20s (%s)\n", en.Name(t), display.Self.Name(t))
27 // American English (American English)
28 // British English (British English)
31 // Simplified Chinese (简体中文)
32 // Traditional Chinese (繁體中文)
33 // Portuguese (português)
34 // European Portuguese (português europeu)
39 // Ukrainian (українська)
44 n := display.Tags(language.English)
45 fmt.Println(n.Name(language.Make("nl")))
46 fmt.Println(n.Name(language.Make("nl-BE")))
47 fmt.Println(n.Name(language.Make("nl-CW")))
48 fmt.Println(n.Name(language.Make("nl-Arab")))
49 fmt.Println(n.Name(language.Make("nl-Cyrl-RU")))
56 // Dutch (Cyrillic, Russia)
59 // ExampleDictionary shows how to reduce the amount of data linked into your
60 // binary by only using the predefined Dictionary variables of the languages you
62 func ExampleDictionary() {
63 tags := []language.Tag{
69 dicts := []*display.Dictionary{
76 m := language.NewMatcher(tags)
78 getDict := func(t language.Tag) *display.Dictionary {
79 _, i, confidence := m.Match(t)
80 // Skip this check if you want to support a fall-back language, which
81 // will be the first one passed to NewMatcher.
82 if confidence == language.No {
88 // The matcher will match Swiss German to German.
89 n := getDict(language.Make("gsw")).Languages()
90 fmt.Println(n.Name(language.German))
91 fmt.Println(n.Name(language.Make("de-CH")))
92 fmt.Println(n.Name(language.Make("gsw")))
96 // Schweizer Hochdeutsch