summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/text/message/pipeline/testdata/test1/test1.go
blob: 88051f932e5a53458fe25cb7bce02630d300c730 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import "golang.org/x/text/message"

func main() {
	p := message.NewPrinter(message.MatchLanguage("en"))

	// NOT EXTRACTED: strings passed to Println are not extracted.
	p.Println("Hello world!")

	// NOT EXTRACTED: strings passed to Print are not extracted.
	p.Print("Hello world!\n")

	// Extract and trim whitespace (TODO).
	p.Printf("Hello world!\n")

	// NOT EXTRACTED: city is not used as a pattern or passed to %m.
	city := "Amsterdam"
	// This comment is extracted.
	p.Printf("Hello %s!\n", city)

	person := "Sheila"
	place := "Zürich"

	// Substitutions replaced by variable names.
	p.Printf("%s is visiting %s!\n",
		person, // The person of matter.
		place,  // Place the person is visiting.
	)

	pp := struct {
		Person string // The person of matter. // TODO: get this comment.
		Place  string
		extra  int
	}{
		person, place, 4,
	}

	// extract will drop this comment in favor of the one below.
	p.Printf("%[1]s is visiting %[3]s!\n", // Field names are placeholders.
		pp.Person,
		pp.extra,
		pp.Place, // Place the person is visiting.
	)

	// Numeric literal becomes placeholder.
	p.Printf("%d files remaining!", 2)

	const n = 2

	// Constant identifier becomes placeholder.
	p.Printf("%d more files remaining!", n)

	// Infer better names from type names.
	type referralCode int

	const c = referralCode(5)

	// Use type name as placeholder.
	p.Printf("Use the following code for your discount: %d\n", c)

	// Use constant name as message ID.
	const msgOutOfOrder = "%s is out of order!" // This comment wins.
	const device = "Soda machine"
	// This message has two IDs.
	p.Printf(msgOutOfOrder, device)

	// Multiple substitutions for same argument.
	miles := 1.2345
	p.Printf("%.2[1]f miles traveled (%[1]f)", miles)
}