Skip to content

Commit

Permalink
lib: refine library to text
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Jan 4, 2024
1 parent a3d545d commit 516e575
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 60 deletions.
25 changes: 0 additions & 25 deletions i18n/library.go

This file was deleted.

35 changes: 0 additions & 35 deletions i18n/library_test.go

This file was deleted.

11 changes: 11 additions & 0 deletions i18n/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
// limitations under the License.
package i18n

func T(en string, zh string) *Text {
t := &Text{
dic: make(map[string]string),
}
t.dic["en"] = en
if zh != "" {
t.dic["zh"] = zh
}
return t
}

type Text struct {
dic map[string]string
}
Expand Down
15 changes: 15 additions & 0 deletions i18n/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,18 @@ func TestText(t *testing.T) {
language = "zh"
assert.Equal(t, "你好", tx.Text())
}

func TestLibrary(t *testing.T) {
//Test T(en string, zh string)*Text
text := T("hello", "你好")
assert.Equal(t, "hello", text.dic["en"])
assert.Equal(t, "你好", text.dic["zh"])

text = T("", "你好")
assert.Equal(t, "", text.dic["en"])
assert.Equal(t, "你好", text.dic["zh"])

text = T("hello", "")
assert.Equal(t, "hello", text.dic["en"])
assert.Equal(t, "", text.dic["zh"])
}

0 comments on commit 516e575

Please sign in to comment.