Skip to content

Commit 8de6e01

Browse files
authored
Clean up normalizeLocale for mono browser target (#112575)
1 parent d6cfa20 commit 8de6e01

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/mono/browser/runtime/globalization-locale.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ function normalizeLocale (locale: string | null) {
1212
if (!locale)
1313
return undefined;
1414
try {
15-
locale = locale.toLocaleLowerCase();
16-
if (locale.includes("zh")) {
17-
// browser does not recognize "zh-chs" and "zh-cht" as equivalents of "zh-HANS" "zh-HANT", we are helping, otherwise
15+
locale = locale.toLocaleLowerCase().replace("_", "-");
16+
if (locale.startsWith("zh-")) {
17+
// browser does not recognize "zh-chs" and "zh-cht" as equivalents of "zh-Hans" "zh-Hant", we are helping, otherwise
1818
// it would throw on getCanonicalLocales with "RangeError: Incorrect locale information provided"
19-
locale = locale.replace("chs", "HANS").replace("cht", "HANT");
19+
locale = locale.replace("-chs", "-Hans").replace("-cht", "-Hant");
2020
}
21-
const canonicalLocales = (Intl as any).getCanonicalLocales(locale.replace("_", "-"));
21+
const canonicalLocales = (Intl as any).getCanonicalLocales(locale);
2222
return canonicalLocales.length > 0 ? canonicalLocales[0] : undefined;
2323
} catch {
2424
return undefined;

0 commit comments

Comments
 (0)