Skip to content

Commit

Permalink
fix: correctly handle es-419 locale in Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
arnog committed Jul 16, 2024
1 parent 8fa90e0 commit 7922aa9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

### Issues Resolved

- When using Chrome in some locale (such as `es-419`), the context menu would
not be displayed.
- When the `MathfieldElement.isFunction` handler is updated, re-render all
the mathfields on the page to take it into account.
- **#2415** A content change event is now dispatched when the value of the
Expand Down
20 changes: 16 additions & 4 deletions src/core/l10n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,22 @@ export const l10n: L10n = {
},

get numberFormatter(): Intl.NumberFormat {
if (!l10n._numberFormatter)
l10n._numberFormatter = new Intl.NumberFormat(l10n.locale);

return l10n._numberFormatter;
if (!l10n._numberFormatter) {
try {
l10n._numberFormatter = new Intl.NumberFormat(l10n.locale);
} catch (e) {
try {
// On Chrome, the navigator.locale can be returned as `es-419`,
// but it's not a valid locale for the Intl.NumberFormat constructor
l10n._numberFormatter = new Intl.NumberFormat(
l10n.locale.slice(0, 2)
);
} catch (e) {
l10n._numberFormatter = new Intl.NumberFormat('en-US');
}
}
}
return l10n._numberFormatter!;
},

/*
Expand Down

0 comments on commit 7922aa9

Please sign in to comment.