forked from goinggo/beego-mgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exampletemplate_test.go
46 lines (39 loc) · 1012 Bytes
/
exampletemplate_test.go
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
package i18n_test
import (
"github.com/goinggo/beego-mgo/go-i18n/i18n"
"os"
"text/template"
)
var funcMap = map[string]interface{}{
"T": i18n.IdentityTfunc,
}
var tmpl = template.Must(template.New("").Funcs(funcMap).Parse(`
{{T "program_greeting"}}
{{T "person_greeting" .}}
{{T "your_unread_email_count" 0}}
{{T "your_unread_email_count" 1}}
{{T "your_unread_email_count" 2}}
{{T "person_unread_email_count" 0 .}}
{{T "person_unread_email_count" 1 .}}
{{T "person_unread_email_count" 2 .}}
`))
func Example_template() {
i18n.MustLoadTranslationFile("../goi18n/testdata/expected/en-US.all.json")
T, _ := i18n.Tfunc("en-US")
tmpl.Funcs(map[string]interface{}{
"T": T,
})
tmpl.Execute(os.Stdout, map[string]interface{}{
"Person": "Bob",
"Timeframe": T("d_days", 1),
})
// Output:
// Hello world
// Hello Bob
// You have 0 unread emails.
// You have 1 unread email.
// You have 2 unread emails.
// Bob has 0 unread emails.
// Bob has 1 unread email.
// Bob has 2 unread emails.
}