-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlocalization_test.go
81 lines (66 loc) · 2.34 KB
/
localization_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
72
73
74
75
76
77
78
79
80
81
package frame_test
import (
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/pitabwire/frame"
"testing"
)
func TestTranslations(t *testing.T) {
translations := frame.Translations("tests_runner/localization", "en", "sw")
_, srv := frame.NewService("Test Localization Srv", translations)
bundle := srv.Bundle()
enLocalizer := i18n.NewLocalizer(bundle, "en", "sw")
englishVersion, err := enLocalizer.Localize(&i18n.LocalizeConfig{
DefaultMessage: &i18n.Message{
ID: "Example",
},
TemplateData: map[string]any{
"Name": "Air",
},
PluralCount: 1,
})
if err != nil {
t.Errorf(" There was an error parsing the translations %s", err)
return
}
if englishVersion != "Air has nothing" {
t.Errorf("Localizations didn't quite work like they should, found : %s expected : %s", englishVersion, "Air has nothing")
return
}
swLocalizer := i18n.NewLocalizer(bundle, "sw")
swVersion, err := swLocalizer.Localize(&i18n.LocalizeConfig{
DefaultMessage: &i18n.Message{
ID: "Example",
},
TemplateData: map[string]any{
"Name": "Air",
},
PluralCount: 1,
})
if err != nil {
t.Errorf(" There was an error parsing the translations %s", err)
return
}
if swVersion != "Air haina chochote" {
t.Errorf("Localizations didn't quite work like they should, found : %s expected : %s", swVersion, "Air haina chochote")
return
}
}
func TestTranslationsHelpers(t *testing.T) {
translations := frame.Translations("tests_runner/localization", "en", "sw")
ctx, srv := frame.NewService("Test Localization Srv", translations)
englishVersion := srv.Translate(ctx, "en", "Example")
if englishVersion != "<no value> has nothing" {
t.Errorf("Localizations didn't quite work like they should, found : %s expected : %s", englishVersion, "<no value> has nothing")
return
}
englishVersion = srv.TranslateWithMap(ctx, "en", "Example", map[string]any{"Name": "MapMan"})
if englishVersion != "MapMan has nothing" {
t.Errorf("Localizations didn't quite work like they should, found : %s expected : %s", englishVersion, "MapMan has nothing")
return
}
englishVersion = srv.TranslateWithMapAndCount(ctx, "en", "Example", map[string]any{"Name": "CountMen"}, 2)
if englishVersion != "CountMen have nothing" {
t.Errorf("Localizations didn't quite work like they should, found : %s expected : %s", englishVersion, "CountMen have nothing")
return
}
}