From 86e6ccf97e82cb72452967c4ad1953cc903e6b57 Mon Sep 17 00:00:00 2001 From: Marc Brooks Date: Fri, 14 Feb 2025 12:33:36 -0600 Subject: [PATCH] Clean up normalizeLocale for mono browser target Fixes #112573 --- src/mono/browser/runtime/globalization-locale.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mono/browser/runtime/globalization-locale.ts b/src/mono/browser/runtime/globalization-locale.ts index 1b95edfb6878a4..5bacd6cf4231ab 100644 --- a/src/mono/browser/runtime/globalization-locale.ts +++ b/src/mono/browser/runtime/globalization-locale.ts @@ -12,13 +12,13 @@ function normalizeLocale (locale: string | null) { if (!locale) return undefined; try { - locale = locale.toLocaleLowerCase(); - if (locale.includes("zh")) { - // browser does not recognize "zh-chs" and "zh-cht" as equivalents of "zh-HANS" "zh-HANT", we are helping, otherwise + locale = locale.toLocaleLowerCase().replace("_", "-"); + if (locale.startsWith("zh-")) { + // browser does not recognize "zh-chs" and "zh-cht" as equivalents of "zh-Hans" "zh-Hant", we are helping, otherwise // it would throw on getCanonicalLocales with "RangeError: Incorrect locale information provided" - locale = locale.replace("chs", "HANS").replace("cht", "HANT"); + locale = locale.replace("-chs", "-Hans").replace("-cht", "-Hant"); } - const canonicalLocales = (Intl as any).getCanonicalLocales(locale.replace("_", "-")); + const canonicalLocales = (Intl as any).getCanonicalLocales(locale); return canonicalLocales.length > 0 ? canonicalLocales[0] : undefined; } catch { return undefined;