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

Commit

Permalink
Add Flush()
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Mar 21, 2021
1 parent 09abd91 commit 4d482d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit 4d482d2

Please sign in to comment.