Normalize regional response language codes consistently

This commit is contained in:
Bingxi Zhao (Frank)
2026-10-31 18:19:15 +08:00
parent a396134d1b
commit dac764e198
2 changed files with 3 additions and 1 deletions

View File

@@ -136,7 +136,7 @@ export function resolveResponseLanguage(
value: string | null | undefined,
legacyLanguage: string | null | undefined = "en",
): ResponseLanguage {
const code = value?.trim().toLowerCase();
const code = value?.trim().toLowerCase().replaceAll("_", "-");
if ((SUPPORTED_RESPONSE_LANGUAGE_CODES as readonly string[]).includes(code ?? "")) {
return code as ResponseLanguage;
}

View File

@@ -54,6 +54,8 @@ test("response language accepts and normalizes the extended registry", () => {
assert.equal(resolveResponseLanguage("Japanese", "en"), "ja");
assert.equal(resolveResponseLanguage("zh-cn", "en"), "zh");
assert.equal(resolveResponseLanguage("pt-BR", "en"), "pt");
assert.equal(resolveResponseLanguage("pt_PT", "en"), "pt");
assert.equal(resolveResponseLanguage("vi_VN", "en"), "vi");
assert.equal(resolveResponseLanguage("Português", "en"), "pt");
assert.equal(resolveResponseLanguage("ms-MY", "en"), "ms");
assert.equal(resolveResponseLanguage("Malay", "en"), "ms");