diff --git a/CHANGELOG.md b/CHANGELOG.md index cb610feec..6c16de5b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/core/l10n.ts b/src/core/l10n.ts index 522974a59..2a2195ad7 100644 --- a/src/core/l10n.ts +++ b/src/core/l10n.ts @@ -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!; }, /*