-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader_test.go
52 lines (41 loc) · 1.32 KB
/
loader_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
package i18n
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoadFiles(t *testing.T) {
assert := assert.New(t)
bundle := NewBundle(
WithDefaultLocale("zh-Hans"),
WithLocales("zh-Hans"),
)
assert.NoError(bundle.LoadFiles("test/zh-Hans.json", "test/zh_Hans.json", "test/zh-Hans.hello.json"))
localizer := bundle.NewLocalizer("zh-Hans")
assert.Equal("讯息 A", localizer.Get("message_a"))
assert.Equal("讯息 B", localizer.Get("message_b"))
assert.Equal("讯息 C", localizer.Get("message_c"))
}
func TestLoadGlob(t *testing.T) {
assert := assert.New(t)
bundle := NewBundle(
WithDefaultLocale("zh-Hans"),
WithLocales("zh-Hans"),
)
assert.NoError(bundle.LoadGlob("test/*.json"))
localizer := bundle.NewLocalizer("zh-Hans")
assert.Equal("讯息 A", localizer.Get("message_a"))
assert.Equal("讯息 B", localizer.Get("message_b"))
assert.Equal("讯息 C", localizer.Get("message_c"))
}
func TestLoadFS(t *testing.T) {
assert := assert.New(t)
bundle := NewBundle(
WithDefaultLocale("zh-Hans"),
WithLocales("zh-Hans"),
)
assert.NoError(bundle.LoadFS(testTranslationFS, "test/*.json"))
localizer := bundle.NewLocalizer("zh-Hans")
assert.Equal("讯息 A", localizer.Get("message_a"))
assert.Equal("讯息 B", localizer.Get("message_b"))
assert.Equal("讯息 C", localizer.Get("message_c"))
}