mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-29 22:47:52 +02:00
refactor(core): Use Intl native API to get locale direction, remove rtl-detect depend… (#10798)
This commit is contained in:
parent
092238d0fa
commit
e7a8c9db82
3 changed files with 11 additions and 14 deletions
|
@ -66,7 +66,6 @@
|
|||
"react-router": "^5.3.4",
|
||||
"react-router-config": "^5.1.1",
|
||||
"react-router-dom": "^5.3.4",
|
||||
"rtl-detect": "^1.0.4",
|
||||
"semver": "^7.5.4",
|
||||
"serve-handler": "^6.1.6",
|
||||
"shelljs": "^0.8.5",
|
||||
|
@ -84,7 +83,6 @@
|
|||
"@types/detect-port": "^1.3.3",
|
||||
"@types/react-dom": "^18.2.7",
|
||||
"@types/react-router-config": "^5.0.7",
|
||||
"@types/rtl-detect": "^1.0.0",
|
||||
"@types/serve-handler": "^6.1.4",
|
||||
"@types/update-notifier": "^6.0.4",
|
||||
"@types/webpack-bundle-analyzer": "^4.7.0",
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import logger from '@docusaurus/logger';
|
||||
import {getLangDir} from 'rtl-detect';
|
||||
import type {I18n, DocusaurusConfig, I18nLocaleConfig} from '@docusaurus/types';
|
||||
import type {LoadContextParams} from './site';
|
||||
|
||||
|
@ -69,11 +68,21 @@ function getDefaultCalendar(localeStr: string) {
|
|||
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 {
|
||||
try {
|
||||
return {
|
||||
label: getDefaultLocaleLabel(locale),
|
||||
direction: getLangDir(locale),
|
||||
direction: getDefaultDirection(locale),
|
||||
htmlLang: locale,
|
||||
calendar: getDefaultCalendar(locale),
|
||||
path: locale,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue