use splitScalar instead of hardcoding

Signed-off-by: Aaron Ruan <i@ar212.com>
This commit is contained in:
Aaron Ruan
2025-03-25 16:40:17 +08:00
parent 251915ab09
commit 4a446b7383

View File

@ -127,18 +127,20 @@ pub fn canonicalizeLocale(
} }
fn fixZhLocale(locale: []const u8) []const u8 { fn fixZhLocale(locale: []const u8) []const u8 {
if (locale.len == 10 and std.mem.eql(u8, locale[0..2], "zh")) { var it = std.mem.splitScalar(u8, locale, '-');
const script = locale[3..7]; const name = it.next() orelse return locale;
const region = locale[8..10]; if (!std.mem.eql(u8, name, "zh")) return locale;
if (std.mem.eql(u8, script, "Hans")) { const script = it.next() orelse return locale;
if (std.mem.eql(u8, region, "SG")) return "zh_SG"; const region = it.next() orelse return locale;
return "zh_CN";
} else if (std.mem.eql(u8, script, "Hant")) { if (std.mem.eql(u8, script, "Hans")) {
if (std.mem.eql(u8, region, "HK")) return "zh_HK"; if (std.mem.eql(u8, region, "SG")) return "zh_SG";
if (std.mem.eql(u8, region, "MO")) return "zh_MO"; return "zh_CN";
return "zh_TW"; } else if (std.mem.eql(u8, script, "Hant")) {
} if (std.mem.eql(u8, region, "MO")) return "zh_MO";
if (std.mem.eql(u8, region, "HK")) return "zh_HK";
return "zh_TW";
} }
return locale; return locale;