Skip to content

Commit

Permalink
Clean up normalizeLocale for mono browser target (#112575)
Browse files Browse the repository at this point in the history
  • Loading branch information
IDisposable authored Feb 17, 2025
1 parent d6cfa20 commit 8de6e01
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/mono/browser/runtime/globalization-locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8de6e01

Please sign in to comment.