refactor(core): Use Intl native API to get locale direction, remove rtl-detect depend… (#10798)

This commit is contained in:
Sébastien Lorber 2024-12-26 15:44:07 +01:00 committed by GitHub
parent 092238d0fa
commit e7a8c9db82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 14 deletions

View file

@ -66,7 +66,6 @@
"react-router": "^5.3.4", "react-router": "^5.3.4",
"react-router-config": "^5.1.1", "react-router-config": "^5.1.1",
"react-router-dom": "^5.3.4", "react-router-dom": "^5.3.4",
"rtl-detect": "^1.0.4",
"semver": "^7.5.4", "semver": "^7.5.4",
"serve-handler": "^6.1.6", "serve-handler": "^6.1.6",
"shelljs": "^0.8.5", "shelljs": "^0.8.5",
@ -84,7 +83,6 @@
"@types/detect-port": "^1.3.3", "@types/detect-port": "^1.3.3",
"@types/react-dom": "^18.2.7", "@types/react-dom": "^18.2.7",
"@types/react-router-config": "^5.0.7", "@types/react-router-config": "^5.0.7",
"@types/rtl-detect": "^1.0.0",
"@types/serve-handler": "^6.1.4", "@types/serve-handler": "^6.1.4",
"@types/update-notifier": "^6.0.4", "@types/update-notifier": "^6.0.4",
"@types/webpack-bundle-analyzer": "^4.7.0", "@types/webpack-bundle-analyzer": "^4.7.0",

View file

@ -6,7 +6,6 @@
*/ */
import logger from '@docusaurus/logger'; import logger from '@docusaurus/logger';
import {getLangDir} from 'rtl-detect';
import type {I18n, DocusaurusConfig, I18nLocaleConfig} from '@docusaurus/types'; import type {I18n, DocusaurusConfig, I18nLocaleConfig} from '@docusaurus/types';
import type {LoadContextParams} from './site'; import type {LoadContextParams} from './site';
@ -69,11 +68,21 @@ function getDefaultCalendar(localeStr: string) {
return 'gregory'; return 'gregory';
} }
function getDefaultDirection(localeStr: string) {
const locale = new Intl.Locale(localeStr);
// see https://github.com/tc39/proposal-intl-locale-info
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
// Node 18.0 implements a former version of the getTextInfo() proposal
// @ts-expect-error: The TC39 proposal was updated
const textInto = locale.getTextInfo?.() ?? locale.textInfo;
return textInto.direction;
}
export function getDefaultLocaleConfig(locale: string): I18nLocaleConfig { export function getDefaultLocaleConfig(locale: string): I18nLocaleConfig {
try { try {
return { return {
label: getDefaultLocaleLabel(locale), label: getDefaultLocaleLabel(locale),
direction: getLangDir(locale), direction: getDefaultDirection(locale),
htmlLang: locale, htmlLang: locale,
calendar: getDefaultCalendar(locale), calendar: getDefaultCalendar(locale),
path: locale, path: locale,

View file

@ -4259,11 +4259,6 @@
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d" resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA== integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==
"@types/rtl-detect@^1.0.0":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@types/rtl-detect/-/rtl-detect-1.0.3.tgz#2b9849ece923d767712e95efa01ca75724de0de5"
integrity sha512-qpstuHivwg/HoXxRrBo5/r/OVx5M2SkqJpVu2haasdLctt+jMGHWjqdbI0LL7Rk2wRmN/UHdHK4JZg9RUMcvKA==
"@types/rtlcss@^3.5.1": "@types/rtlcss@^3.5.1":
version "3.5.4" version "3.5.4"
resolved "https://registry.yarnpkg.com/@types/rtlcss/-/rtlcss-3.5.4.tgz#8db1e02fe911cf5b71f4cb42dafce8ccaef8e1e1" resolved "https://registry.yarnpkg.com/@types/rtlcss/-/rtlcss-3.5.4.tgz#8db1e02fe911cf5b71f4cb42dafce8ccaef8e1e1"
@ -15899,11 +15894,6 @@ rslog@^1.2.3:
resolved "https://registry.yarnpkg.com/rslog/-/rslog-1.2.3.tgz#9114d93056312fbe35c11b3fea3f2774a7debe56" resolved "https://registry.yarnpkg.com/rslog/-/rslog-1.2.3.tgz#9114d93056312fbe35c11b3fea3f2774a7debe56"
integrity sha512-antALPJaKBRPBU1X2q9t085K4htWDOOv/K1qhTUk7h0l1ePU/KbDqKJn19eKP0dk7PqMioeA0+fu3gyPXCsXxQ== integrity sha512-antALPJaKBRPBU1X2q9t085K4htWDOOv/K1qhTUk7h0l1ePU/KbDqKJn19eKP0dk7PqMioeA0+fu3gyPXCsXxQ==
rtl-detect@^1.0.4:
version "1.1.2"
resolved "https://registry.yarnpkg.com/rtl-detect/-/rtl-detect-1.1.2.tgz#ca7f0330af5c6bb626c15675c642ba85ad6273c6"
integrity sha512-PGMBq03+TTG/p/cRB7HCLKJ1MgDIi07+QU1faSjiYRfmY5UsAttV9Hs08jDAHVwcOwmVLcSJkpwyfXszVjWfIQ==
rtlcss@^4.1.0: rtlcss@^4.1.0:
version "4.3.0" version "4.3.0"
resolved "https://registry.yarnpkg.com/rtlcss/-/rtlcss-4.3.0.tgz#f8efd4d5b64f640ec4af8fa25b65bacd9e07cc97" resolved "https://registry.yarnpkg.com/rtlcss/-/rtlcss-4.3.0.tgz#f8efd4d5b64f640ec4af8fa25b65bacd9e07cc97"