Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: refine library to text #916

Merged
merged 1 commit into from
Jan 4, 2024
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
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"])
}
Loading