diff --git a/package-lock.json b/package-lock.json index cdcaec9e..22d02159 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "phanpy", "version": "0.1.0", "dependencies": { + "@formatjs/intl-localematcher": "~0.2.32", "@github/text-expander-element": "~2.3.0", "@iconify-icons/mingcute": "~1.2.4", "@szhsin/react-menu": "~3.5.1", @@ -2508,6 +2509,14 @@ "node": ">=12" } }, + "node_modules/@formatjs/intl-localematcher": { + "version": "0.2.32", + "resolved": "https://registry.npmjs.org/@formatjs/intl-localematcher/-/intl-localematcher-0.2.32.tgz", + "integrity": "sha512-k/MEBstff4sttohyEpXxCmC3MqbUn9VvHGlZ8fauLzkbwXmVrEeyzS+4uhrvAk9DWU9/7otYWxyDox4nT/KVLQ==", + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@github/combobox-nav": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@github/combobox-nav/-/combobox-nav-2.1.5.tgz", @@ -8694,6 +8703,14 @@ "dev": true, "optional": true }, + "@formatjs/intl-localematcher": { + "version": "0.2.32", + "resolved": "https://registry.npmjs.org/@formatjs/intl-localematcher/-/intl-localematcher-0.2.32.tgz", + "integrity": "sha512-k/MEBstff4sttohyEpXxCmC3MqbUn9VvHGlZ8fauLzkbwXmVrEeyzS+4uhrvAk9DWU9/7otYWxyDox4nT/KVLQ==", + "requires": { + "tslib": "^2.4.0" + } + }, "@github/combobox-nav": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@github/combobox-nav/-/combobox-nav-2.1.5.tgz", diff --git a/package.json b/package.json index bc5bff5d..2ee389b7 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "sourcemap": "npx source-map-explorer dist/assets/*.js" }, "dependencies": { + "@formatjs/intl-localematcher": "~0.2.32", "@github/text-expander-element": "~2.3.0", "@iconify-icons/mingcute": "~1.2.4", "@szhsin/react-menu": "~3.5.1", diff --git a/src/components/compose.jsx b/src/components/compose.jsx index ca0ca335..0eafecf0 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -1,5 +1,6 @@ import './compose.css'; +import { match } from '@formatjs/intl-localematcher'; import '@github/text-expander-element'; import equal from 'fast-deep-equal'; import { forwardRef } from 'preact/compat'; @@ -84,7 +85,11 @@ const observer = new IntersectionObserver((entries) => { }); observer.observe(menu); -const DEFAULT_LANG = 'en'; +const DEFAULT_LANG = match( + [new Intl.DateTimeFormat().resolvedOptions().locale, ...navigator.languages], + supportedLanguages.map((l) => l[0]), + 'en', +); // https://github.com/mastodon/mastodon/blob/c4a429ed47e85a6bbf0d470a41cc2f64cf120c19/app/javascript/mastodon/features/compose/util/counter.js const urlRegexObj = new RegExp(urlRegex.source, urlRegex.flags);