OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / text / feature / plural / example_test.go
1 // Copyright 2017 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.
4
5 package plural_test
6
7 import (
8         "golang.org/x/text/feature/plural"
9         "golang.org/x/text/language"
10         "golang.org/x/text/message"
11 )
12
13 func ExampleSelect() {
14         // Manually set some translations. This is typically done programmatically.
15         message.Set(language.English, "%d files remaining",
16                 plural.Selectf(1, "%d",
17                         "=0", "done!",
18                         plural.One, "one file remaining",
19                         plural.Other, "%[1]d files remaining",
20                 ))
21         message.Set(language.Dutch, "%d files remaining",
22                 plural.Selectf(1, "%d",
23                         "=0", "klaar!",
24                         // One can also use a string instead of a Kind
25                         "one", "nog één bestand te gaan",
26                         "other", "nog %[1]d bestanden te gaan",
27                 ))
28
29         p := message.NewPrinter(language.English)
30         p.Printf("%d files remaining", 5)
31         p.Println()
32         p.Printf("%d files remaining", 1)
33         p.Println()
34
35         p = message.NewPrinter(language.Dutch)
36         p.Printf("%d files remaining", 1)
37         p.Println()
38         p.Printf("%d files remaining", 0)
39         p.Println()
40
41         // Output:
42         // 5 files remaining
43         // one file remaining
44         // nog één bestand te gaan
45         // klaar!
46 }