fix(i18n): use English runtime text and localize system UI

This commit is contained in:
Arthur Koba
2026-10-25 19:44:15 +03:00
parent ada0550571
commit 65a96670d5
289 changed files with 8092 additions and 3426 deletions
@@ -43,71 +43,71 @@ func TestValidateRuleGraph(t *testing.T) {
}{
{"duplicate start", func(g *RuleGraph) {
g.Nodes = append(g.Nodes, RuleNode{ID: "start-2", Type: RuleNodeStart, Config: rawConfig(`{}`)})
}, "恰好包含一个开始节点"},
}, "rule graph must contain exactly one start node"},
{"duplicate allow", func(g *RuleGraph) {
g.Nodes = append(g.Nodes, RuleNode{ID: "allow-2", Type: RuleNodeAllow, Config: rawConfig(`{}`)})
}, "恰好包含一个通过节点"},
}, "rule graph must contain exactly one allow node"},
{"cycle", func(g *RuleGraph) {
g.Edges[2].Target = "start"
}, "规则图不能包含循环"},
}, "rule graph must not contain cycles"},
{"unreachable", func(g *RuleGraph) {
g.Nodes = append(g.Nodes, RuleNode{ID: "orphan", Type: RuleNodeBlock, Config: rawConfig(`{"status_code":403,"response_body":""}`)})
}, "节点 orphan 无法从开始节点到达"},
{"missing false edge", func(g *RuleGraph) { g.Edges = g.Edges[:2] }, "节点 match-1 的 false 出口未连接"},
{"wrong handle", func(g *RuleGraph) { g.Edges[0].SourceHandle = "true" }, "边 e1 的源端口 true 不适用于节点 start"},
}, "node orphan is not reachable from the start node"},
{"missing false edge", func(g *RuleGraph) { g.Edges = g.Edges[:2] }, "node match-1 output false is not connected"},
{"wrong handle", func(g *RuleGraph) { g.Edges[0].SourceHandle = "true" }, "edge e1 source port true is not valid for node start"},
{"same handle multiple targets", func(g *RuleGraph) {
g.Edges = append(g.Edges, RuleEdge{ID: "e4", Source: "match-1", SourceHandle: "true", Target: "allow"})
}, "节点 match-1 的 true 出口连接了多个目标"},
{"unknown type", func(g *RuleGraph) { g.Nodes[1].Type = RuleNodeType("script") }, "节点 match-1 的类型 script 未知"},
{"dangling target", func(g *RuleGraph) { g.Edges[1].Target = "missing" }, "边 e2 的目标节点 missing 不存在"},
{"invalid ip", func(g *RuleGraph) { g.Nodes[1].Config = rawConfig(`{"ips":["bad"]}`) }, "节点 match-1 的 IP bad 无效"},
{"invalid cidr", func(g *RuleGraph) { g.Nodes[1].Config = rawConfig(`{"cidrs":["bad"]}`) }, "节点 match-1 的 CIDR bad 无效"},
{"missing ip group", func(g *RuleGraph) { g.Nodes[1].Config = rawConfig(`{"ip_group_ids":[99]}`) }, "节点 match-1 引用的 IP 组 99 不存在"},
}, "node match-1 output true is connected to multiple targets"},
{"unknown type", func(g *RuleGraph) { g.Nodes[1].Type = RuleNodeType("script") }, "node match-1 has unknown type script"},
{"dangling target", func(g *RuleGraph) { g.Edges[1].Target = "missing" }, "edge e2 references missing target node missing"},
{"invalid ip", func(g *RuleGraph) { g.Nodes[1].Config = rawConfig(`{"ips":["bad"]}`) }, "node match-1 contains invalid IP bad"},
{"invalid cidr", func(g *RuleGraph) { g.Nodes[1].Config = rawConfig(`{"cidrs":["bad"]}`) }, "node match-1 contains invalid CIDR bad"},
{"missing ip group", func(g *RuleGraph) { g.Nodes[1].Config = rawConfig(`{"ip_group_ids":[99]}`) }, "node match-1 references missing IP group 99"},
{"invalid country", func(g *RuleGraph) {
g.Nodes[1].Type = RuleNodeGeoMatch
g.Nodes[1].Config = rawConfig(`{"countries":["USA"]}`)
}, "节点 match-1 的国家代码 USA 无效"},
}, "node match-1 contains invalid country code USA"},
{"invalid region", func(g *RuleGraph) {
g.Nodes[1].Type = RuleNodeGeoMatch
g.Nodes[1].Config = rawConfig(`{"regions":["US-"]}`)
}, "节点 match-1 的地区代码 US- 无效"},
}, "node match-1 contains invalid region code US-"},
{"pow range", func(g *RuleGraph) {
g.Nodes[1].Type = RuleNodePoW
g.Nodes[1].Config = rawConfig(`{"algorithm":"fast","difficulty":17,"session_ttl":60,"challenge_ttl":30}`)
g.Edges[1].SourceHandle = "next"
g.Edges = g.Edges[:2]
}, "节点 match-1 的 PoW 难度必须在 1-16 之间"},
}, "PoW difficulty for node match-1 must be between 1 and 16"},
{"invalid ua browser", func(g *RuleGraph) {
g.Nodes[1].Type = RuleNodeUACheck
g.Nodes[1].Config = rawConfig(`{"browsers":["NotABrowser"],"match_mode":"or"}`)
}, "节点 match-1 的浏览器标签 NotABrowser 无效"},
}, "node match-1 contains invalid browser tag NotABrowser"},
{"invalid ua match mode", func(g *RuleGraph) {
g.Nodes[1].Type = RuleNodeUACheck
g.Nodes[1].Config = rawConfig(`{"match_mode":"xor"}`)
}, "节点 match-1 的匹配模式必须为 and 或 or"},
}, "match mode for node match-1 must be and or or"},
{"invalid ua custom regex", func(g *RuleGraph) {
g.Nodes[1].Type = RuleNodeUACheck
g.Nodes[1].Config = rawConfig(`{"block_custom_ua":true,"custom_ua_patterns":["("]}`)
}, "节点 match-1 的自定义 UA 正则无效"},
}, "invalid custom User-Agent pattern in node match-1"},
{"custom ua requires patterns", func(g *RuleGraph) {
g.Nodes[1].Type = RuleNodeUACheck
g.Nodes[1].Config = rawConfig(`{"block_custom_ua":true}`)
}, "节点 match-1 开启屏蔽自定义 UA 时至少需要一条正则"},
{"unknown config field", func(g *RuleGraph) { g.Nodes[1].Config = rawConfig(`{"ips":[],"surprise":true}`) }, "节点 match-1 的配置无效"},
{"null config", func(g *RuleGraph) { g.Nodes[1].Config = rawConfig(`null`) }, "节点 match-1 的配置无效"},
}, "node match-1 requires at least one pattern when custom User-Agent blocking is enabled"},
{"unknown config field", func(g *RuleGraph) { g.Nodes[1].Config = rawConfig(`{"ips":[],"surprise":true}`) }, "invalid configuration for node match-1"},
{"null config", func(g *RuleGraph) { g.Nodes[1].Config = rawConfig(`null`) }, "invalid configuration for node match-1"},
{"too many nodes", func(g *RuleGraph) {
for i := 0; i < 125; i++ {
g.Nodes = append(g.Nodes, RuleNode{ID: strings.Repeat("x", i+1), Type: RuleNodeBlock, Config: rawConfig(`{"status_code":403}`)})
}
}, "规则图节点数不能超过 128"},
}, "rule graph must not contain more than 128 nodes"},
{"too many edges", func(g *RuleGraph) {
for i := 0; i < 254; i++ {
g.Edges = append(g.Edges, RuleEdge{ID: strings.Repeat("e", i+5), Source: "start", SourceHandle: "next", Target: "allow"})
}
}, "规则图边数不能超过 256"},
}, "rule graph must not contain more than 256 edges"},
{"graph too large", func(g *RuleGraph) {
g.Nodes[0].Label = strings.Repeat("x", 256*1024)
}, "规则图大小不能超过 256 KiB"},
}, "rule graph must not exceed 256 KiB"},
}
for _, tt := range tests {
@@ -127,7 +127,7 @@ func TestValidateRuleGraphDetectsNodeWithoutTerminalPath(t *testing.T) {
nodes := []RuleNode{{ID: "start", Type: RuleNodeStart}, {ID: "match", Type: RuleNodeIPMatch}, {ID: "allow", Type: RuleNodeAllow}}
outgoing := map[string][]RuleEdge{"start": {{Source: "start", Target: "match"}}}
err := validateTerminalPaths(nodes, outgoing)
if err == nil || !strings.Contains(err.Error(), "节点 start 不存在通往终止节点的路径") {
if err == nil || !strings.Contains(err.Error(), "node start has no path to a terminal node") {
t.Fatalf("validateTerminalPaths() error = %v", err)
}
}