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