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

Add Reset() #9

Merged
merged 1 commit into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func SetMessageWithDesc(lang, langDesc string, localeFile interface{}, otherLoca
return err
}

// Reset resets locale store.
func Reset() {
locales = &localeStore{store: make(map[string]*locale)}
}

// SetMessage sets the message file for localization.
func SetMessage(lang string, localeFile interface{}, otherLocaleFiles ...interface{}) error {
return SetMessageWithDesc(lang, lang, localeFile, otherLocaleFiles...)
Expand Down
14 changes: 14 additions & 0 deletions i18n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ func Test_Tr(t *testing.T) {
if result != `test value <span style="color: ; background: ">more text</span>` {
t.Errorf(`expect 'test value <span style="color: ; background: ">more text</span>', got '%s'`, result)
}

langs := ListLangs()
if len(langs) != 1 {
t.Errorf("expect '1', got '%d'", len(langs))
} else if langs[0] != "en-US" {
t.Errorf("expect 'en-US', got '%s'", langs[0])
}

Reset()

langs = ListLangs()
if len(langs) != 0 {
t.Errorf("expect '0', got '%d'", len(langs))
}
}

func Benchmark_Tr(b *testing.B) {
Expand Down