部分中文转换为多语言代号

This commit is contained in:
刘祥超
2023-06-28 16:19:05 +08:00
parent bd57d35d63
commit 9db82b0bea
18 changed files with 656 additions and 164 deletions

View File

@@ -13,6 +13,26 @@ func TestMessage(t *testing.T) {
t.Log(langs.Message("en-us", "user_description", "Lily"))
}
func TestMessageVariable(t *testing.T) {
var lang = langs.DefaultManager().AddLang("en-us")
lang.Set("user", "Lily")
lang.Set("user2", "${lang.user}")
lang.Set("user_name", "Name: ${lang.user}")
lang.Set("user_name3", "Name: ${lang.user3}, ${user4}")
//lang.Set("user3", "")
err := lang.Compile()
if err != nil {
t.Log("ERROR(ignore):", err)
}
t.Log("user:", lang.Get("user"))
t.Log("user2:", lang.Get("user2"))
t.Log("user_name:", lang.Get("user_name"))
t.Log("user_name3:", lang.Get("user_name3"))
t.Log("user_name3_2:", lang.Get("name3"))
}
func TestMessageDefault(t *testing.T) {
var lang = langs.DefaultManager().AddLang("zh-cn")
lang.Set("user_description", "user: %s")
@@ -31,6 +51,6 @@ func TestFormat(t *testing.T) {
lang.Set("book_name", "Go语言")
}
t.Log(langs.Format("en-US", "this is ${lang.book_name} book"))
t.Log(langs.Format("zh-CN", "this is ${lang.book_name} book"))
t.Log(langs.Format("en-US", "this is ${lang:book_name} book"))
t.Log(langs.Format("zh-CN", "this is ${lang:book_name} book"))
}