-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n_test.go
61 lines (45 loc) · 1.1 KB
/
i18n_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package ela
import (
"bytes"
"fmt"
. "github.com/smartystreets/goconvey/convey"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func TestI18n(t *testing.T) {
Convey("I18n sections", t, func() {
i18n := NewI18n("etc/locale")
i18n.SetLang("zh_CN")
hello := i18n.Tr("hello")
world := i18n.Tr("world")
fmt.Println(hello)
fmt.Println(world)
So(hello, ShouldEqual, "你好")
So(world, ShouldEqual, "世界")
i18ne := NewEmptyI18n()
So(i18ne, ShouldNotBeNil)
i18ne.Load("etc/locale")
hello1 := i18n.Tr("_", "hello")
world1 := i18n.Tr("_", "world")
fmt.Println(hello1)
fmt.Println(world1)
So(hello1, ShouldEqual, "你好")
So(world1, ShouldEqual, "世界")
// todo
e := Web()
e.Use(InitI18nModule("etc/locale"))
e.Router("/", func(ctx *Context) {
fmt.Println("ctrl test")
})
fmt.Println("III")
// fmt.Println(middlewares)
resp := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
req.Body = ioutil.NopCloser(bytes.NewBufferString("This is my request body"))
// So(err, ShouldBeNil)
m := Web()
m.ServeHTTP(resp, req)
})
}