spark-server/internal/pkg/i18n/i18n_test.go
zhr ae9a71034d feat: implement Spark IM V3 modular monolith
Add HTTP /v1 MVC, TCP send path, groups with server-side member-avatar collage, object-storage upload, and friends/favorites around the architecture-v3 layout.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 19:52:11 +08:00

42 lines
1.4 KiB
Go

package i18n
import "testing"
func TestParseLanguage(t *testing.T) {
cases := map[string]Lang{
"": ZhCN,
"zh": ZhCN,
"zh-CN": ZhCN,
"zh_CN": ZhCN,
"zh-Hans": ZhCN,
"en": En,
"en-US,en;q=0.9": En,
"zh-TW": ZhTW,
"zh-HK": ZhTW,
"zh-Hant-TW": ZhTW,
"fr,en;q=0.8": En,
"zh-CN,zh;q=0.9,en;q=0.8": ZhCN,
}
for in, want := range cases {
if got := Parse(in); got != want {
t.Fatalf("Parse(%q)=%s want %s", in, got, want)
}
}
}
func TestErrorAndNotifyI18n(t *testing.T) {
if ErrorMsg(ZhCN, "40101") != "未授权" || ErrorMsg(En, "40101") != "unauthorized" || ErrorMsg(ZhTW, "40101") != "未授權" {
t.Fatalf("err 40101 %s %s %s", ErrorMsg(ZhCN, "40101"), ErrorMsg(En, "40101"), ErrorMsg(ZhTW, "40101"))
}
if ErrorMsg(ZhCN, "40402") != "原文件已过期" || ErrorMsg(En, "40402") != "media expired" {
t.Fatalf("err 40402 %s %s", ErrorMsg(ZhCN, "40402"), ErrorMsg(En, "40402"))
}
title, body := Notify(En, NotifyFriendRequest, map[string]string{"name": "Ada"})
if title != "Friend request" || body != "Ada sent you a friend request" {
t.Fatalf("notify %q %q", title, body)
}
if T(ZhTW, NotifyKickReplaced, nil) != "已在其他裝置登入" {
t.Fatalf("kick %s", T(ZhTW, NotifyKickReplaced, nil))
}
}