...
1
2
3
4
5 package gettext_test
6
7 import (
8 "fmt"
9 "io/ioutil"
10 "log"
11
12 "github.com/chai2010/gettext-go"
13 )
14
15 func Example() {
16 gettext := gettext.New("hello", "./examples/locale").SetLanguage("zh_CN")
17 fmt.Println(gettext.Gettext("Hello, world!"))
18
19
20
21 }
22
23 func Example_zip() {
24 gettext := gettext.New("hello", "./examples/locale.zip").SetLanguage("zh_CN")
25 fmt.Println(gettext.Gettext("Hello, world!"))
26
27
28
29 }
30
31 func Example_zipData() {
32 zipData, err := ioutil.ReadFile("./examples/locale.zip")
33 if err != nil {
34 log.Fatal(err)
35 }
36
37 gettext := gettext.New("hello", "???", zipData).SetLanguage("zh_CN")
38 fmt.Println(gettext.Gettext("Hello, world!"))
39
40
41
42 }
43
44 func Example_bind() {
45 gettext.BindLocale(gettext.New("hello", "./examples/locale.zip"))
46 gettext.SetLanguage("zh_CN")
47
48 fmt.Println(gettext.Gettext("Hello, world!"))
49
50
51
52 }
53
54 func Example_multiLang() {
55 zh := gettext.New("hello", "./examples/locale").SetLanguage("zh_CN")
56 tw := gettext.New("hello", "./examples/locale").SetLanguage("zh_TW")
57
58 fmt.Println(zh.PGettext(
59 "code.google.com/p/gettext-go/examples/hi.SayHi",
60 "pkg hi: Hello, world!",
61 ))
62
63 fmt.Println(tw.PGettext(
64 "code.google.com/p/gettext-go/examples/hi.SayHi",
65 "pkg hi: Hello, world!",
66 ))
67
68
69
70
71 }
72
73 func Example_json() {
74 const jsonData = `{
75 "zh_CN": {
76 "LC_MESSAGES": {
77 "hello.json": [{
78 "msgctxt" : "",
79 "msgid" : "Hello, world!",
80 "msgid_plural": "",
81 "msgstr" : ["你好, 世界!"]
82 }]
83 }
84 }
85 }`
86
87 gettext := gettext.New("hello", "???", jsonData).SetLanguage("zh_CN")
88 fmt.Println(gettext.Gettext("Hello, world!"))
89
90
91
92 }
93
View as plain text