...
1
2
3
4
5 package display_test
6
7 import (
8 "fmt"
9
10 "golang.org/x/text/language"
11 "golang.org/x/text/language/display"
12 "golang.org/x/text/message"
13 )
14
15 func ExampleFormatter() {
16 message.SetString(language.Dutch, "In %v people speak %v.", "In %v spreekt men %v.")
17
18 fr := language.French
19 region, _ := fr.Region()
20 for _, tag := range []string{"en", "nl"} {
21 p := message.NewPrinter(language.Make(tag))
22
23 p.Printf("In %v people speak %v.", display.Region(region), display.Language(fr))
24 p.Println()
25 }
26
27
28
29
30 }
31
32 func ExampleNamer() {
33 supported := []string{
34 "en-US", "en-GB", "ja", "zh", "zh-Hans", "zh-Hant", "pt", "pt-PT", "ko", "ar", "el", "ru", "uk", "pa",
35 }
36
37 en := display.English.Languages()
38
39 for _, s := range supported {
40 t := language.MustParse(s)
41 fmt.Printf("%-20s (%s)\n", en.Name(t), display.Self.Name(t))
42 }
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 }
60
61 func ExampleTags() {
62 n := display.Tags(language.English)
63 fmt.Println(n.Name(language.Make("nl")))
64 fmt.Println(n.Name(language.Make("nl-BE")))
65 fmt.Println(n.Name(language.Make("nl-CW")))
66 fmt.Println(n.Name(language.Make("nl-Arab")))
67 fmt.Println(n.Name(language.Make("nl-Cyrl-RU")))
68
69
70
71
72
73
74
75 }
76
77
78
79
80 func ExampleDictionary() {
81 tags := []language.Tag{
82 language.English,
83 language.German,
84 language.Japanese,
85 language.Russian,
86 }
87 dicts := []*display.Dictionary{
88 display.English,
89 display.German,
90 display.Japanese,
91 display.Russian,
92 }
93
94 m := language.NewMatcher(tags)
95
96 getDict := func(t language.Tag) *display.Dictionary {
97 _, i, confidence := m.Match(t)
98
99
100 if confidence == language.No {
101 return nil
102 }
103 return dicts[i]
104 }
105
106
107 n := getDict(language.Make("gsw")).Languages()
108 fmt.Println(n.Name(language.German))
109 fmt.Println(n.Name(language.Make("de-CH")))
110 fmt.Println(n.Name(language.Make("gsw")))
111
112
113
114
115
116 }
117
View as plain text