Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading