diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-05-12 23:56:07 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-05-12 23:56:07 -0400 |
commit | 38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8 (patch) | |
tree | a4fde09672192b97d453ad605b030bd5a10c5a45 /vendor/github.com/nicksnyder/go-i18n/i18n/exampletemplate_test.go | |
parent | 84d2482ddbff9564c9ad75b2d30af66e3ddfd44d (diff) | |
download | chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.tar.gz chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.tar.bz2 chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.zip |
Moving to glide
Diffstat (limited to 'vendor/github.com/nicksnyder/go-i18n/i18n/exampletemplate_test.go')
-rw-r--r-- | vendor/github.com/nicksnyder/go-i18n/i18n/exampletemplate_test.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/github.com/nicksnyder/go-i18n/i18n/exampletemplate_test.go b/vendor/github.com/nicksnyder/go-i18n/i18n/exampletemplate_test.go new file mode 100644 index 000000000..962936610 --- /dev/null +++ b/vendor/github.com/nicksnyder/go-i18n/i18n/exampletemplate_test.go @@ -0,0 +1,63 @@ +package i18n_test + +import ( + "github.com/nicksnyder/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), + }) + + tmpl.Execute(os.Stdout, struct { + Person string + Timeframe string + }{ + 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. + // + // 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. +} |