-
Notifications
You must be signed in to change notification settings - Fork 4
/
example_test.go
71 lines (58 loc) · 1.61 KB
/
example_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
62
63
64
65
66
67
68
69
70
71
package spreak_test
import (
"fmt"
"golang.org/x/text/language"
"github.com/vorlif/spreak"
"github.com/vorlif/spreak/localize"
)
func ExampleNewBundle() {
bundle, err := spreak.NewBundle(
spreak.WithSourceLanguage(language.English),
spreak.WithDefaultDomain("helloworld"),
spreak.WithDomainPath("helloworld", "./examples/locale/"),
spreak.WithLanguage(language.German, language.Spanish, language.French),
)
if err != nil {
panic(err)
}
t := spreak.NewLocalizer(bundle, language.Spanish)
fmt.Println(t.Get("Hello world"))
// Output:
// Hola Mundo
}
func ExampleLocalizer_Get() {
bundle, err := spreak.NewBundle(
spreak.WithSourceLanguage(language.English),
spreak.WithDefaultDomain("helloworld"),
spreak.WithDomainPath("helloworld", "./examples/locale/"),
spreak.WithLanguage(language.German, language.Spanish, language.French),
)
if err != nil {
panic(err)
}
t := spreak.NewLocalizer(bundle, language.Spanish)
fmt.Println(t.Get("Hello world"))
// Output:
// Hola Mundo
}
func ExampleLocalizer_Localize() {
bundle, err := spreak.NewBundle(
spreak.WithDefaultDomain("helloworld"),
spreak.WithDomainPath("helloworld", "./examples/locale/"),
spreak.WithLanguage(language.German, language.Spanish, language.French),
)
if err != nil {
panic(err)
}
t := spreak.NewLocalizer(bundle, language.Spanish)
msg := &localize.Message{Singular: "Hello world"}
fmt.Println(t.Localize(msg))
// Output:
// Hola Mundo
}
func ExampleExpandLanguage() {
expanded := spreak.ExpandLanguage(language.MustParse("zh-Hans"))
fmt.Println(expanded)
// Output:
// [zh-Hans zh_Hans zh-CN zh_CN zho zh]
}