mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 02:29:37 +08:00
Normalize regional response language codes consistently
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user