1 package main
2
3 import (
4 "fmt"
5
6 "github.com/go-playground/locales"
7 "github.com/go-playground/locales/en"
8 "github.com/go-playground/locales/en_CA"
9 "github.com/go-playground/locales/fr"
10 "github.com/go-playground/locales/nl"
11 "github.com/go-playground/universal-translator"
12 )
13
14
15 var universalTraslator *ut.UniversalTranslator
16
17 func main() {
18
19
20 e := en.New()
21 universalTraslator = ut.New(e, e, en_CA.New(), nl.New(), fr.New())
22
23 en, _ := universalTraslator.GetTranslator("en")
24
25
26
27
28
29
30
31 fmt.Println("Cardinal Plural Rules:", en.PluralsCardinal())
32 fmt.Println("Ordinal Plural Rules:", en.PluralsOrdinal())
33 fmt.Println("Range Plural Rules:", en.PluralsRange())
34
35
36
37 en.Add("welcome", "Welcome {0} to our test", false)
38
39
40 en.AddCardinal("days", "You have {0} day left to register", locales.PluralRuleOne, false)
41 en.AddCardinal("days", "You have {0} days left to register", locales.PluralRuleOther, false)
42
43
44 en.AddOrdinal("day-of-month", "{0}st", locales.PluralRuleOne, false)
45 en.AddOrdinal("day-of-month", "{0}nd", locales.PluralRuleTwo, false)
46 en.AddOrdinal("day-of-month", "{0}rd", locales.PluralRuleFew, false)
47 en.AddOrdinal("day-of-month", "{0}th", locales.PluralRuleOther, false)
48
49
50
51 en.AddRange("between", "It's {0}-{1} days away", locales.PluralRuleOther, false)
52
53
54
55 fmt.Println(en.T("welcome", "Joeybloggs"))
56
57 fmt.Println(en.C("days", 1, 0, en.FmtNumber(1, 0)))
58 fmt.Println(en.C("days", 2, 0, en.FmtNumber(2, 0)))
59 fmt.Println(en.C("days", 10456.25, 2, en.FmtNumber(10456.25, 2)))
60
61 fmt.Println(en.O("day-of-month", 1, 0, en.FmtNumber(1, 0)))
62 fmt.Println(en.O("day-of-month", 2, 0, en.FmtNumber(2, 0)))
63 fmt.Println(en.O("day-of-month", 3, 0, en.FmtNumber(3, 0)))
64 fmt.Println(en.O("day-of-month", 4, 0, en.FmtNumber(4, 0)))
65 fmt.Println(en.O("day-of-month", 10456.25, 0, en.FmtNumber(10456.25, 0)))
66
67 fmt.Println(en.R("between", 0, 0, 1, 0, en.FmtNumber(0, 0), en.FmtNumber(1, 0)))
68 fmt.Println(en.R("between", 1, 0, 2, 0, en.FmtNumber(1, 0), en.FmtNumber(2, 0)))
69 fmt.Println(en.R("between", 1, 0, 100, 0, en.FmtNumber(1, 0), en.FmtNumber(100, 0)))
70 }
71
View as plain text