...
1
2
3
4
5 package main
6
7 import "golang.org/x/text/message"
8
9 func main() {
10 p := message.NewPrinter(message.MatchLanguage("en"))
11
12
13 p.Println("Hello world!")
14
15
16 p.Print("Hello world!\n")
17
18
19 p.Printf("Hello world!\n")
20
21
22 city := "Amsterdam"
23
24 p.Printf("Hello %s!\n", city)
25
26 person := "Sheila"
27 place := "Zürich"
28
29
30 p.Printf("%s is visiting %s!\n",
31 person,
32 place,
33 )
34
35 pp := struct {
36 Person string
37 Place string
38 extra int
39 }{
40 person, place, 4,
41 }
42
43
44 p.Printf("%[1]s is visiting %[3]s!\n",
45 pp.Person,
46 pp.extra,
47 pp.Place,
48 )
49
50
51 p.Printf("%d files remaining!", 2)
52
53 const n = 2
54
55
56 p.Printf("%d more files remaining!", n)
57
58
59 type referralCode int
60
61 const c = referralCode(5)
62
63
64 p.Printf("Use the following code for your discount: %d\n", c)
65
66
67 const msgOutOfOrder = "%s is out of order!"
68 const device = "Soda machine"
69
70 p.Printf(msgOutOfOrder, device)
71
72
73 miles := 1.2345
74 p.Printf("%.2[1]f miles traveled (%[1]f)", miles)
75 }
76
View as plain text