Skip to content
This repository was archived by the owner on Nov 27, 2021. It is now read-only.

Commit 0ebbf2d

Browse files
authored
Add Reset() (#9)
1 parent 09abd91 commit 0ebbf2d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

i18n.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ func SetMessageWithDesc(lang, langDesc string, localeFile interface{}, otherLoca
174174
return err
175175
}
176176

177+
// Reset resets locale store.
178+
func Reset() {
179+
locales = &localeStore{store: make(map[string]*locale)}
180+
}
181+
177182
// SetMessage sets the message file for localization.
178183
func SetMessage(lang string, localeFile interface{}, otherLocaleFiles ...interface{}) error {
179184
return SetMessageWithDesc(lang, lang, localeFile, otherLocaleFiles...)

i18n_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ func Test_Tr(t *testing.T) {
4444
if result != `test value <span style="color: ; background: ">more text</span>` {
4545
t.Errorf(`expect 'test value <span style="color: ; background: ">more text</span>', got '%s'`, result)
4646
}
47+
48+
langs := ListLangs()
49+
if len(langs) != 1 {
50+
t.Errorf("expect '1', got '%d'", len(langs))
51+
} else if langs[0] != "en-US" {
52+
t.Errorf("expect 'en-US', got '%s'", langs[0])
53+
}
54+
55+
Reset()
56+
57+
langs = ListLangs()
58+
if len(langs) != 0 {
59+
t.Errorf("expect '0', got '%d'", len(langs))
60+
}
4761
}
4862

4963
func Benchmark_Tr(b *testing.B) {

0 commit comments

Comments
 (0)