Browse Source

feat: Remove locale-provider (#39373)

* feat: remove locale-provider

* chore: fix lint

* Empty-Commit

* test: remove test

* Revert "test: remove test"

This reverts commit 4f6b59883f6bf078f21a10898ef913c9e2adb913.

* chore: 阶段性兼容

* fix lint

* fix: fix lint

* fix: add index

* docs: update docs

* docs: update

* docs: update

* docs: update
pull/39431/head
Amumu 2 years ago
committed by GitHub
parent
commit
d689c7b855
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      components/calendar/generateCalendar.tsx
  2. 4
      components/config-provider/__tests__/locale.test.tsx
  3. 2
      components/config-provider/context.tsx
  4. 6
      components/config-provider/index.tsx
  5. 6
      components/date-picker/__tests__/other.test.tsx
  6. 2
      components/date-picker/generatePicker/generateRangePicker.tsx
  7. 2
      components/date-picker/generatePicker/generateSinglePicker.tsx
  8. 2
      components/empty/index.tsx
  9. 2
      components/form/FormItemLabel.tsx
  10. 64
      components/locale-provider/LocaleReceiver.tsx
  11. 4
      components/locale-provider/__tests__/cached-context.test.tsx
  12. 2
      components/locale-provider/__tests__/config.test.tsx
  13. 140
      components/locale-provider/__tests__/index.test.tsx
  14. 3
      components/locale-provider/ar_EG.tsx
  15. 3
      components/locale-provider/az_AZ.tsx
  16. 3
      components/locale-provider/bg_BG.tsx
  17. 3
      components/locale-provider/bn_BD.tsx
  18. 3
      components/locale-provider/by_BY.tsx
  19. 3
      components/locale-provider/ca_ES.tsx
  20. 3
      components/locale-provider/cs_CZ.tsx
  21. 3
      components/locale-provider/da_DK.tsx
  22. 3
      components/locale-provider/de_DE.tsx
  23. 3
      components/locale-provider/el_GR.tsx
  24. 3
      components/locale-provider/en_GB.tsx
  25. 3
      components/locale-provider/en_US.tsx
  26. 3
      components/locale-provider/es_ES.tsx
  27. 3
      components/locale-provider/et_EE.tsx
  28. 3
      components/locale-provider/eu_ES.tsx
  29. 3
      components/locale-provider/fa_IR.tsx
  30. 3
      components/locale-provider/fi_FI.tsx
  31. 3
      components/locale-provider/fr_BE.tsx
  32. 3
      components/locale-provider/fr_CA.tsx
  33. 3
      components/locale-provider/fr_FR.tsx
  34. 3
      components/locale-provider/ga_IE.tsx
  35. 3
      components/locale-provider/gl_ES.tsx
  36. 3
      components/locale-provider/he_IL.tsx
  37. 3
      components/locale-provider/hi_IN.tsx
  38. 3
      components/locale-provider/hr_HR.tsx
  39. 3
      components/locale-provider/hu_HU.tsx
  40. 3
      components/locale-provider/hy_AM.tsx
  41. 3
      components/locale-provider/id_ID.tsx
  42. 6
      components/locale-provider/index.ts
  43. 3
      components/locale-provider/is_IS.tsx
  44. 3
      components/locale-provider/it_IT.tsx
  45. 3
      components/locale-provider/ja_JP.tsx
  46. 3
      components/locale-provider/ka_GE.tsx
  47. 3
      components/locale-provider/kk_KZ.tsx
  48. 3
      components/locale-provider/km_KH.tsx
  49. 3
      components/locale-provider/kmr_IQ.tsx
  50. 3
      components/locale-provider/kn_IN.tsx
  51. 3
      components/locale-provider/ko_KR.tsx
  52. 3
      components/locale-provider/ku_IQ.tsx
  53. 3
      components/locale-provider/lt_LT.tsx
  54. 3
      components/locale-provider/lv_LV.tsx
  55. 3
      components/locale-provider/mk_MK.tsx
  56. 3
      components/locale-provider/ml_IN.tsx
  57. 3
      components/locale-provider/mn_MN.tsx
  58. 3
      components/locale-provider/ms_MY.tsx
  59. 3
      components/locale-provider/nb_NO.tsx
  60. 3
      components/locale-provider/ne_NP.tsx
  61. 3
      components/locale-provider/nl_BE.tsx
  62. 3
      components/locale-provider/nl_NL.tsx
  63. 3
      components/locale-provider/pl_PL.tsx
  64. 3
      components/locale-provider/pt_BR.tsx
  65. 3
      components/locale-provider/pt_PT.tsx
  66. 3
      components/locale-provider/ro_RO.tsx
  67. 3
      components/locale-provider/ru_RU.tsx
  68. 3
      components/locale-provider/si_LK.tsx
  69. 3
      components/locale-provider/sk_SK.tsx
  70. 3
      components/locale-provider/sl_SI.tsx
  71. 3
      components/locale-provider/sr_RS.tsx
  72. 3
      components/locale-provider/sv_SE.tsx
  73. 3
      components/locale-provider/ta_IN.tsx
  74. 3
      components/locale-provider/th_TH.tsx
  75. 3
      components/locale-provider/tk_TK.tsx
  76. 3
      components/locale-provider/tr_TR.tsx
  77. 3
      components/locale-provider/uk_UA.tsx
  78. 3
      components/locale-provider/ur_PK.tsx
  79. 3
      components/locale-provider/vi_VN.tsx
  80. 3
      components/locale-provider/zh_CN.tsx
  81. 3
      components/locale-provider/zh_HK.tsx
  82. 3
      components/locale-provider/zh_TW.tsx
  83. 64
      components/locale/LocaleReceiver.tsx
  84. 2
      components/locale/ar_EG.tsx
  85. 2
      components/locale/az_AZ.tsx
  86. 2
      components/locale/bg_BG.tsx
  87. 2
      components/locale/bn_BD.tsx
  88. 2
      components/locale/by_BY.tsx
  89. 2
      components/locale/ca_ES.tsx
  90. 0
      components/locale/context.ts
  91. 2
      components/locale/cs_CZ.tsx
  92. 2
      components/locale/da_DK.tsx
  93. 2
      components/locale/de_DE.tsx
  94. 2
      components/locale/el_GR.tsx
  95. 2
      components/locale/en_GB.tsx
  96. 2
      components/locale/en_US.tsx
  97. 2
      components/locale/es_ES.tsx
  98. 2
      components/locale/et_EE.tsx
  99. 2
      components/locale/eu_ES.tsx
  100. 2
      components/locale/fa_IR.tsx

2
components/calendar/generateCalendar.tsx

@ -10,7 +10,7 @@ import type {
import useMergedState from 'rc-util/lib/hooks/useMergedState'; import useMergedState from 'rc-util/lib/hooks/useMergedState';
import * as React from 'react'; import * as React from 'react';
import { ConfigContext } from '../config-provider'; import { ConfigContext } from '../config-provider';
import LocaleReceiver from '../locale-provider/LocaleReceiver'; import LocaleReceiver from '../locale/LocaleReceiver';
import CalendarHeader from './Header'; import CalendarHeader from './Header';
import enUS from './locale/en_US'; import enUS from './locale/en_US';

4
components/config-provider/__tests__/locale.test.tsx

@ -2,8 +2,8 @@ import React from 'react';
import { closePicker, openPicker, selectCell } from '../../date-picker/__tests__/utils'; import { closePicker, openPicker, selectCell } from '../../date-picker/__tests__/utils';
import ConfigProvider from '..'; import ConfigProvider from '..';
import DatePicker from '../../date-picker'; import DatePicker from '../../date-picker';
import type { Locale } from '../../locale-provider'; import type { Locale } from '../../locale';
import LocaleProvider from '../../locale-provider'; import LocaleProvider from '../../locale';
import enUS from '../../locale/en_US'; import enUS from '../../locale/en_US';
import zhCN from '../../locale/zh_CN'; import zhCN from '../../locale/zh_CN';
import Modal from '../../modal'; import Modal from '../../modal';

2
components/config-provider/context.tsx

@ -1,7 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import type { DerivativeFunc } from '@ant-design/cssinjs'; import type { DerivativeFunc } from '@ant-design/cssinjs';
import type { RequiredMark } from '../form/Form'; import type { RequiredMark } from '../form/Form';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import type { AliasToken, MapToken, OverrideToken, SeedToken } from '../theme/interface'; import type { AliasToken, MapToken, OverrideToken, SeedToken } from '../theme/interface';
import type { RenderEmptyHandler } from './defaultRenderEmpty'; import type { RenderEmptyHandler } from './defaultRenderEmpty';
import type { SizeType } from './SizeContext'; import type { SizeType } from './SizeContext';

6
components/config-provider/index.tsx

@ -6,9 +6,9 @@ import useMemo from 'rc-util/lib/hooks/useMemo';
import * as React from 'react'; import * as React from 'react';
import type { ReactElement } from 'react'; import type { ReactElement } from 'react';
import type { RequiredMark } from '../form/Form'; import type { RequiredMark } from '../form/Form';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import LocaleProvider, { ANT_MARK } from '../locale-provider'; import LocaleProvider, { ANT_MARK } from '../locale';
import LocaleReceiver from '../locale-provider/LocaleReceiver'; import LocaleReceiver from '../locale/LocaleReceiver';
import defaultLocale from '../locale/en_US'; import defaultLocale from '../locale/en_US';
import { DesignTokenContext } from '../theme/internal'; import { DesignTokenContext } from '../theme/internal';
import defaultSeedToken from '../theme/themes/seed'; import defaultSeedToken from '../theme/themes/seed';

6
components/date-picker/__tests__/other.test.tsx

@ -4,9 +4,9 @@ import customParseFormat from 'dayjs/plugin/customParseFormat';
import React from 'react'; import React from 'react';
import DatePicker from '..'; import DatePicker from '..';
import ConfigProvider from '../../config-provider'; import ConfigProvider from '../../config-provider';
import type { Locale } from '../../locale-provider'; import type { Locale } from '../../locale';
import LocaleProvider from '../../locale-provider'; import LocaleProvider from '../../locale';
import locale from '../../locale-provider/zh_CN'; import locale from '../../locale/zh_CN';
import jaJP from '../../locale/ja_JP'; import jaJP from '../../locale/ja_JP';
import zhTW from '../locale/zh_TW'; import zhTW from '../locale/zh_TW';
import { render } from '../../../tests/utils'; import { render } from '../../../tests/utils';

2
components/date-picker/generatePicker/generateRangePicker.tsx

@ -14,7 +14,7 @@ import DisabledContext from '../../config-provider/DisabledContext';
import SizeContext from '../../config-provider/SizeContext'; import SizeContext from '../../config-provider/SizeContext';
import { FormItemInputContext } from '../../form/context'; import { FormItemInputContext } from '../../form/context';
import { useCompactItemContext } from '../../space/Compact'; import { useCompactItemContext } from '../../space/Compact';
import LocaleReceiver from '../../locale-provider/LocaleReceiver'; import LocaleReceiver from '../../locale/LocaleReceiver';
import { getMergedStatus, getStatusClassNames } from '../../_util/statusUtils'; import { getMergedStatus, getStatusClassNames } from '../../_util/statusUtils';
import enUS from '../locale/en_US'; import enUS from '../locale/en_US';
import { getRangePlaceholder, transPlacement2DropdownAlign } from '../util'; import { getRangePlaceholder, transPlacement2DropdownAlign } from '../util';

2
components/date-picker/generatePicker/generateSinglePicker.tsx

@ -14,7 +14,7 @@ import { ConfigContext } from '../../config-provider';
import DisabledContext from '../../config-provider/DisabledContext'; import DisabledContext from '../../config-provider/DisabledContext';
import SizeContext from '../../config-provider/SizeContext'; import SizeContext from '../../config-provider/SizeContext';
import { FormItemInputContext } from '../../form/context'; import { FormItemInputContext } from '../../form/context';
import LocaleReceiver from '../../locale-provider/LocaleReceiver'; import LocaleReceiver from '../../locale/LocaleReceiver';
import type { InputStatus } from '../../_util/statusUtils'; import type { InputStatus } from '../../_util/statusUtils';
import { getMergedStatus, getStatusClassNames } from '../../_util/statusUtils'; import { getMergedStatus, getStatusClassNames } from '../../_util/statusUtils';
import warning from '../../_util/warning'; import warning from '../../_util/warning';

2
components/empty/index.tsx

@ -1,7 +1,7 @@
import classNames from 'classnames'; import classNames from 'classnames';
import * as React from 'react'; import * as React from 'react';
import { ConfigContext } from '../config-provider'; import { ConfigContext } from '../config-provider';
import LocaleReceiver from '../locale-provider/LocaleReceiver'; import LocaleReceiver from '../locale/LocaleReceiver';
import DefaultEmptyImg from './empty'; import DefaultEmptyImg from './empty';
import SimpleEmptyImg from './simple'; import SimpleEmptyImg from './simple';

2
components/form/FormItemLabel.tsx

@ -3,7 +3,7 @@ import classNames from 'classnames';
import * as React from 'react'; import * as React from 'react';
import type { ColProps } from '../grid/col'; import type { ColProps } from '../grid/col';
import Col from '../grid/col'; import Col from '../grid/col';
import { useLocaleReceiver } from '../locale-provider/LocaleReceiver'; import { useLocaleReceiver } from '../locale/LocaleReceiver';
import defaultLocale from '../locale/en_US'; import defaultLocale from '../locale/en_US';
import type { TooltipProps } from '../tooltip'; import type { TooltipProps } from '../tooltip';
import Tooltip from '../tooltip'; import Tooltip from '../tooltip';

64
components/locale-provider/LocaleReceiver.tsx

@ -1,64 +1,6 @@
import * as React from 'react'; // locale-provider 文件夹的移除需要修改 @ant-design/tools 和 antd-img-crop
import type { Locale } from '.'; import LocaleReceiver from '../locale/LocaleReceiver';
import type { LocaleContextProps } from './context';
import LocaleContext from './context';
import defaultLocaleData from '../locale/en_US';
export type LocaleComponentName = Exclude<keyof Locale, 'locale'>; export * from '../locale/LocaleReceiver';
export interface LocaleReceiverProps<C extends LocaleComponentName = LocaleComponentName> {
componentName?: C;
defaultLocale?: Locale[C] | (() => Locale[C]);
children: (
locale: NonNullable<Locale[C]>,
localeCode: string,
fullLocale: Locale,
) => React.ReactElement;
}
const LocaleReceiver = <C extends LocaleComponentName = LocaleComponentName>(
props: LocaleReceiverProps<C>,
) => {
const { componentName = 'global' as C, defaultLocale, children } = props;
const antLocale = React.useContext<LocaleContextProps | undefined>(LocaleContext);
const getLocale = React.useMemo<NonNullable<Locale[C]>>(() => {
const locale = defaultLocale || defaultLocaleData[componentName];
const localeFromContext = antLocale?.[componentName] ?? {};
return {
...(locale instanceof Function ? locale() : locale),
...(localeFromContext || {}),
};
}, [componentName, defaultLocale, antLocale]);
const getLocaleCode = React.useMemo<string>(() => {
const localeCode = antLocale && antLocale.locale;
// Had use LocaleProvide but didn't set locale
if (antLocale && antLocale.exist && !localeCode) {
return defaultLocaleData.locale;
}
return localeCode!;
}, [antLocale]);
return children(getLocale, getLocaleCode, antLocale!);
};
export default LocaleReceiver; export default LocaleReceiver;
export const useLocaleReceiver = <C extends LocaleComponentName = LocaleComponentName>(
componentName: C,
defaultLocale?: Locale[C] | (() => Locale[C]),
): [Locale[C]] => {
const antLocale = React.useContext<LocaleContextProps | undefined>(LocaleContext);
const getLocale = React.useMemo<NonNullable<Locale[C]>>(() => {
const locale = defaultLocale || defaultLocaleData[componentName];
const localeFromContext = antLocale?.[componentName] ?? {};
return {
...(typeof locale === 'function' ? locale() : locale),
...(localeFromContext || {}),
};
}, [componentName, defaultLocale, antLocale]);
return [getLocale];
};

4
components/locale-provider/__tests__/cached-context.test.tsx

@ -1,7 +1,7 @@
import React, { memo, useContext } from 'react'; import React, { memo, useContext } from 'react';
import { fireEvent, pureRender } from '../../../tests/utils'; import { fireEvent, pureRender } from '../../../tests/utils';
import LocaleProvider from '..'; import LocaleProvider from '../../locale';
import LocaleContext from '../context'; import LocaleContext from '../../locale/context';
let innerCount = 0; let innerCount = 0;
let outerCount = 0; let outerCount = 0;

2
components/locale-provider/__tests__/config.test.tsx

@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
import { Modal } from '../..'; import { Modal } from '../..';
import { waitFakeTimer, render, fireEvent } from '../../../tests/utils'; import { waitFakeTimer, render, fireEvent } from '../../../tests/utils';
import ConfigProvider from '../../config-provider'; import ConfigProvider from '../../config-provider';
import zhCN from '../zh_CN'; import zhCN from '../../locale/zh_CN';
const Demo: React.FC<{ type: string }> = ({ type }) => { const Demo: React.FC<{ type: string }> = ({ type }) => {
useEffect(() => { useEffect(() => {

140
components/locale-provider/__tests__/index.test.tsx

@ -68,8 +68,8 @@ import preParsePostFormat from 'dayjs/plugin/preParsePostFormat';
import MockDate from 'mockdate'; import MockDate from 'mockdate';
import React from 'react'; import React from 'react';
import { render } from '../../../tests/utils'; import { render } from '../../../tests/utils';
import type { Locale } from '..'; import type { Locale } from '../../locale';
import LocaleProvider from '..'; import LocaleProvider from '../../locale';
import { import {
Calendar, Calendar,
DatePicker, DatePicker,
@ -82,74 +82,74 @@ import {
Transfer, Transfer,
} from '../..'; } from '../..';
import mountTest from '../../../tests/shared/mountTest'; import mountTest from '../../../tests/shared/mountTest';
import arEG from '../ar_EG'; import arEG from '../../locale/ar_EG';
import azAZ from '../az_AZ'; import azAZ from '../../locale/az_AZ';
import bgBG from '../bg_BG'; import bgBG from '../../locale/bg_BG';
import bnBD from '../bn_BD'; import bnBD from '../../locale/bn_BD';
import byBY from '../by_BY'; import byBY from '../../locale/by_BY';
import caES from '../ca_ES'; import caES from '../../locale/ca_ES';
import csCZ from '../cs_CZ'; import csCZ from '../../locale/cs_CZ';
import daDK from '../da_DK'; import daDK from '../../locale/da_DK';
import deDE from '../de_DE'; import deDE from '../../locale/de_DE';
import elGR from '../el_GR'; import elGR from '../../locale/el_GR';
import enGB from '../en_GB'; import enGB from '../../locale/en_GB';
import enUS from '../en_US'; import enUS from '../../locale/en_US';
import esES from '../es_ES'; import esES from '../../locale/es_ES';
import etEE from '../et_EE'; import etEE from '../../locale/et_EE';
import euES from '../eu_ES'; import euES from '../../locale/eu_ES';
import faIR from '../fa_IR'; import faIR from '../../locale/fa_IR';
import fiFI from '../fi_FI'; import fiFI from '../../locale/fi_FI';
import frBE from '../fr_BE'; import frBE from '../../locale/fr_BE';
import frCA from '../fr_CA'; import frCA from '../../locale/fr_CA';
import frFR from '../fr_FR'; import frFR from '../../locale/fr_FR';
import gaIE from '../ga_IE'; import gaIE from '../../locale/ga_IE';
import glES from '../gl_ES'; import glES from '../../locale/gl_ES';
import heIL from '../he_IL'; import heIL from '../../locale/he_IL';
import hiIN from '../hi_IN'; import hiIN from '../../locale/hi_IN';
import hrHR from '../hr_HR'; import hrHR from '../../locale/hr_HR';
import huHU from '../hu_HU'; import huHU from '../../locale/hu_HU';
import hyAM from '../hy_AM'; import hyAM from '../../locale/hy_AM';
import idID from '../id_ID'; import idID from '../../locale/id_ID';
import isIS from '../is_IS'; import isIS from '../../locale/is_IS';
import itIT from '../it_IT'; import itIT from '../../locale/it_IT';
import jaJP from '../ja_JP'; import jaJP from '../../locale/ja_JP';
import kaGE from '../ka_GE'; import kaGE from '../../locale/ka_GE';
import kkKZ from '../kk_KZ'; import kkKZ from '../../locale/kk_KZ';
import kmrIQ from '../kmr_IQ'; import kmrIQ from '../../locale/kmr_IQ';
import kmKH from '../km_KH'; import kmKH from '../../locale/km_KH';
import knIN from '../kn_IN'; import knIN from '../../locale/kn_IN';
import koKR from '../ko_KR'; import koKR from '../../locale/ko_KR';
import kuIQ from '../ku_IQ'; import kuIQ from '../../locale/ku_IQ';
import ltLT from '../lt_LT'; import ltLT from '../../locale/lt_LT';
import lvLV from '../lv_LV'; import lvLV from '../../locale/lv_LV';
import mkMK from '../mk_MK'; import mkMK from '../../locale/mk_MK';
import mlIN from '../ml_IN'; import mlIN from '../../locale/ml_IN';
import mnMN from '../mn_MN'; import mnMN from '../../locale/mn_MN';
import msMY from '../ms_MY'; import msMY from '../../locale/ms_MY';
import nbNO from '../nb_NO'; import nbNO from '../../locale/nb_NO';
import neNP from '../ne_NP'; import neNP from '../../locale/ne_NP';
import nlBE from '../nl_BE'; import nlBE from '../../locale/nl_BE';
import nlNL from '../nl_NL'; import nlNL from '../../locale/nl_NL';
import plPL from '../pl_PL'; import plPL from '../../locale/pl_PL';
import ptBR from '../pt_BR'; import ptBR from '../../locale/pt_BR';
import ptPT from '../pt_PT'; import ptPT from '../../locale/pt_PT';
import roRO from '../ro_RO'; import roRO from '../../locale/ro_RO';
import ruRU from '../ru_RU'; import ruRU from '../../locale/ru_RU';
import siLK from '../si_LK'; import siLK from '../../locale/si_LK';
import skSK from '../sk_SK'; import skSK from '../../locale/sk_SK';
import slSI from '../sl_SI'; import slSI from '../../locale/sl_SI';
import srRS from '../sr_RS'; import srRS from '../../locale/sr_RS';
import svSE from '../sv_SE'; import svSE from '../../locale/sv_SE';
import taIN from '../ta_IN'; import taIN from '../../locale/ta_IN';
import thTH from '../th_TH'; import thTH from '../../locale/th_TH';
import tkTK from '../tk_TK'; import tkTK from '../../locale/tk_TK';
import trTR from '../tr_TR'; import trTR from '../../locale/tr_TR';
import ukUA from '../uk_UA'; import ukUA from '../../locale/uk_UA';
import urPK from '../ur_PK'; import urPK from '../../locale/ur_PK';
import viVN from '../vi_VN'; import viVN from '../../locale/vi_VN';
import zhCN from '../zh_CN'; import zhCN from '../../locale/zh_CN';
import zhHK from '../zh_HK'; import zhHK from '../../locale/zh_HK';
import zhTW from '../zh_TW'; import zhTW from '../../locale/zh_TW';
dayjs.extend(preParsePostFormat); dayjs.extend(preParsePostFormat);

3
components/locale-provider/ar_EG.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ar_EG';
export default locale;

3
components/locale-provider/az_AZ.tsx

@ -1,3 +0,0 @@
import locale from '../locale/az_AZ';
export default locale;

3
components/locale-provider/bg_BG.tsx

@ -1,3 +0,0 @@
import locale from '../locale/bg_BG';
export default locale;

3
components/locale-provider/bn_BD.tsx

@ -1,3 +0,0 @@
import locale from '../locale/bn_BD';
export default locale;

3
components/locale-provider/by_BY.tsx

@ -1,3 +0,0 @@
import locale from '../locale/by_BY';
export default locale;

3
components/locale-provider/ca_ES.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ca_ES';
export default locale;

3
components/locale-provider/cs_CZ.tsx

@ -1,3 +0,0 @@
import locale from '../locale/cs_CZ';
export default locale;

3
components/locale-provider/da_DK.tsx

@ -1,3 +0,0 @@
import locale from '../locale/da_DK';
export default locale;

3
components/locale-provider/de_DE.tsx

@ -1,3 +0,0 @@
import locale from '../locale/de_DE';
export default locale;

3
components/locale-provider/el_GR.tsx

@ -1,3 +0,0 @@
import locale from '../locale/el_GR';
export default locale;

3
components/locale-provider/en_GB.tsx

@ -1,3 +0,0 @@
import locale from '../locale/en_GB';
export default locale;

3
components/locale-provider/en_US.tsx

@ -1,3 +0,0 @@
import locale from '../locale/en_US';
export default locale;

3
components/locale-provider/es_ES.tsx

@ -1,3 +0,0 @@
import locale from '../locale/es_ES';
export default locale;

3
components/locale-provider/et_EE.tsx

@ -1,3 +0,0 @@
import locale from '../locale/et_EE';
export default locale;

3
components/locale-provider/eu_ES.tsx

@ -1,3 +0,0 @@
import locale from '../locale/eu_ES';
export default locale;

3
components/locale-provider/fa_IR.tsx

@ -1,3 +0,0 @@
import locale from '../locale/fa_IR';
export default locale;

3
components/locale-provider/fi_FI.tsx

@ -1,3 +0,0 @@
import locale from '../locale/fi_FI';
export default locale;

3
components/locale-provider/fr_BE.tsx

@ -1,3 +0,0 @@
import locale from '../locale/fr_BE';
export default locale;

3
components/locale-provider/fr_CA.tsx

@ -1,3 +0,0 @@
import locale from '../locale/fr_CA';
export default locale;

3
components/locale-provider/fr_FR.tsx

@ -1,3 +0,0 @@
import locale from '../locale/fr_FR';
export default locale;

3
components/locale-provider/ga_IE.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ga_IE';
export default locale;

3
components/locale-provider/gl_ES.tsx

@ -1,3 +0,0 @@
import locale from '../locale/gl_ES';
export default locale;

3
components/locale-provider/he_IL.tsx

@ -1,3 +0,0 @@
import locale from '../locale/he_IL';
export default locale;

3
components/locale-provider/hi_IN.tsx

@ -1,3 +0,0 @@
import locale from '../locale/hi_IN';
export default locale;

3
components/locale-provider/hr_HR.tsx

@ -1,3 +0,0 @@
import locale from '../locale/hr_HR';
export default locale;

3
components/locale-provider/hu_HU.tsx

@ -1,3 +0,0 @@
import locale from '../locale/hu_HU';
export default locale;

3
components/locale-provider/hy_AM.tsx

@ -1,3 +0,0 @@
import locale from '../locale/hy_AM';
export default locale;

3
components/locale-provider/id_ID.tsx

@ -1,3 +0,0 @@
import locale from '../locale/id_ID';
export default locale;

6
components/locale-provider/index.ts

@ -0,0 +1,6 @@
// locale-provider 文件夹的移除需要修改 @ant-design/tools 和 antd-img-crop
import locale from '../locale';
export * from '../locale';
export default locale;

3
components/locale-provider/is_IS.tsx

@ -1,3 +0,0 @@
import locale from '../locale/is_IS';
export default locale;

3
components/locale-provider/it_IT.tsx

@ -1,3 +0,0 @@
import locale from '../locale/it_IT';
export default locale;

3
components/locale-provider/ja_JP.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ja_JP';
export default locale;

3
components/locale-provider/ka_GE.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ka_GE';
export default locale;

3
components/locale-provider/kk_KZ.tsx

@ -1,3 +0,0 @@
import locale from '../locale/kk_KZ';
export default locale;

3
components/locale-provider/km_KH.tsx

@ -1,3 +0,0 @@
import locale from '../locale/km_KH';
export default locale;

3
components/locale-provider/kmr_IQ.tsx

@ -1,3 +0,0 @@
import locale from '../locale/kmr_IQ';
export default locale;

3
components/locale-provider/kn_IN.tsx

@ -1,3 +0,0 @@
import locale from '../locale/kn_IN';
export default locale;

3
components/locale-provider/ko_KR.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ko_KR';
export default locale;

3
components/locale-provider/ku_IQ.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ku_IQ';
export default locale;

3
components/locale-provider/lt_LT.tsx

@ -1,3 +0,0 @@
import locale from '../locale/lt_LT';
export default locale;

3
components/locale-provider/lv_LV.tsx

@ -1,3 +0,0 @@
import locale from '../locale/lv_LV';
export default locale;

3
components/locale-provider/mk_MK.tsx

@ -1,3 +0,0 @@
import locale from '../locale/mk_MK';
export default locale;

3
components/locale-provider/ml_IN.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ml_IN';
export default locale;

3
components/locale-provider/mn_MN.tsx

@ -1,3 +0,0 @@
import locale from '../locale/mn_MN';
export default locale;

3
components/locale-provider/ms_MY.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ms_MY';
export default locale;

3
components/locale-provider/nb_NO.tsx

@ -1,3 +0,0 @@
import locale from '../locale/nb_NO';
export default locale;

3
components/locale-provider/ne_NP.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ne_NP';
export default locale;

3
components/locale-provider/nl_BE.tsx

@ -1,3 +0,0 @@
import locale from '../locale/nl_BE';
export default locale;

3
components/locale-provider/nl_NL.tsx

@ -1,3 +0,0 @@
import locale from '../locale/nl_NL';
export default locale;

3
components/locale-provider/pl_PL.tsx

@ -1,3 +0,0 @@
import locale from '../locale/pl_PL';
export default locale;

3
components/locale-provider/pt_BR.tsx

@ -1,3 +0,0 @@
import locale from '../locale/pt_BR';
export default locale;

3
components/locale-provider/pt_PT.tsx

@ -1,3 +0,0 @@
import locale from '../locale/pt_PT';
export default locale;

3
components/locale-provider/ro_RO.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ro_RO';
export default locale;

3
components/locale-provider/ru_RU.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ru_RU';
export default locale;

3
components/locale-provider/si_LK.tsx

@ -1,3 +0,0 @@
import locale from '../locale/si_LK';
export default locale;

3
components/locale-provider/sk_SK.tsx

@ -1,3 +0,0 @@
import locale from '../locale/sk_SK';
export default locale;

3
components/locale-provider/sl_SI.tsx

@ -1,3 +0,0 @@
import locale from '../locale/sl_SI';
export default locale;

3
components/locale-provider/sr_RS.tsx

@ -1,3 +0,0 @@
import locale from '../locale/sr_RS';
export default locale;

3
components/locale-provider/sv_SE.tsx

@ -1,3 +0,0 @@
import locale from '../locale/sv_SE';
export default locale;

3
components/locale-provider/ta_IN.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ta_IN';
export default locale;

3
components/locale-provider/th_TH.tsx

@ -1,3 +0,0 @@
import locale from '../locale/th_TH';
export default locale;

3
components/locale-provider/tk_TK.tsx

@ -1,3 +0,0 @@
import locale from '../locale/tk_TK';
export default locale;

3
components/locale-provider/tr_TR.tsx

@ -1,3 +0,0 @@
import locale from '../locale/tr_TR';
export default locale;

3
components/locale-provider/uk_UA.tsx

@ -1,3 +0,0 @@
import locale from '../locale/uk_UA';
export default locale;

3
components/locale-provider/ur_PK.tsx

@ -1,3 +0,0 @@
import locale from '../locale/ur_PK';
export default locale;

3
components/locale-provider/vi_VN.tsx

@ -1,3 +0,0 @@
import locale from '../locale/vi_VN';
export default locale;

3
components/locale-provider/zh_CN.tsx

@ -1,3 +0,0 @@
import locale from '../locale/zh_CN';
export default locale;

3
components/locale-provider/zh_HK.tsx

@ -1,3 +0,0 @@
import locale from '../locale/zh_HK';
export default locale;

3
components/locale-provider/zh_TW.tsx

@ -1,3 +0,0 @@
import locale from '../locale/zh_TW';
export default locale;

64
components/locale/LocaleReceiver.tsx

@ -0,0 +1,64 @@
import * as React from 'react';
import type { Locale } from '.';
import type { LocaleContextProps } from './context';
import LocaleContext from './context';
import defaultLocaleData from '../locale/en_US';
export type LocaleComponentName = Exclude<keyof Locale, 'locale'>;
export interface LocaleReceiverProps<C extends LocaleComponentName = LocaleComponentName> {
componentName?: C;
defaultLocale?: Locale[C] | (() => Locale[C]);
children: (
locale: NonNullable<Locale[C]>,
localeCode: string,
fullLocale: Locale,
) => React.ReactElement;
}
const LocaleReceiver = <C extends LocaleComponentName = LocaleComponentName>(
props: LocaleReceiverProps<C>,
) => {
const { componentName = 'global' as C, defaultLocale, children } = props;
const antLocale = React.useContext<LocaleContextProps | undefined>(LocaleContext);
const getLocale = React.useMemo<NonNullable<Locale[C]>>(() => {
const locale = defaultLocale || defaultLocaleData[componentName];
const localeFromContext = antLocale?.[componentName] ?? {};
return {
...(locale instanceof Function ? locale() : locale),
...(localeFromContext || {}),
};
}, [componentName, defaultLocale, antLocale]);
const getLocaleCode = React.useMemo<string>(() => {
const localeCode = antLocale && antLocale.locale;
// Had use LocaleProvide but didn't set locale
if (antLocale && antLocale.exist && !localeCode) {
return defaultLocaleData.locale;
}
return localeCode!;
}, [antLocale]);
return children(getLocale, getLocaleCode, antLocale!);
};
export default LocaleReceiver;
export const useLocaleReceiver = <C extends LocaleComponentName = LocaleComponentName>(
componentName: C,
defaultLocale?: Locale[C] | (() => Locale[C]),
): [Locale[C]] => {
const antLocale = React.useContext<LocaleContextProps | undefined>(LocaleContext);
const getLocale = React.useMemo<NonNullable<Locale[C]>>(() => {
const locale = defaultLocale || defaultLocaleData[componentName];
const localeFromContext = antLocale?.[componentName] ?? {};
return {
...(typeof locale === 'function' ? locale() : locale),
...(localeFromContext || {}),
};
}, [componentName, defaultLocale, antLocale]);
return [getLocale];
};

2
components/locale/ar_EG.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/ar_EG'; import Pagination from 'rc-pagination/lib/locale/ar_EG';
import Calendar from '../calendar/locale/ar_EG'; import Calendar from '../calendar/locale/ar_EG';
import DatePicker from '../date-picker/locale/ar_EG'; import DatePicker from '../date-picker/locale/ar_EG';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/ar_EG'; import TimePicker from '../time-picker/locale/ar_EG';
const typeTemplate = 'ليس ${label} من نوع ${type} صالحًا'; const typeTemplate = 'ليس ${label} من نوع ${type} صالحًا';

2
components/locale/az_AZ.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/az_AZ'; import Pagination from 'rc-pagination/lib/locale/az_AZ';
import Calendar from '../calendar/locale/az_AZ'; import Calendar from '../calendar/locale/az_AZ';
import DatePicker from '../date-picker/locale/az_AZ'; import DatePicker from '../date-picker/locale/az_AZ';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/az_AZ'; import TimePicker from '../time-picker/locale/az_AZ';
const typeTemplate = '${label}Hökmlü deyil${type}'; const typeTemplate = '${label}Hökmlü deyil${type}';

2
components/locale/bg_BG.tsx

@ -1,7 +1,7 @@
import Pagination from 'rc-pagination/lib/locale/bg_BG'; import Pagination from 'rc-pagination/lib/locale/bg_BG';
import Calendar from '../calendar/locale/bg_BG'; import Calendar from '../calendar/locale/bg_BG';
import DatePicker from '../date-picker/locale/bg_BG'; import DatePicker from '../date-picker/locale/bg_BG';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/bg_BG'; import TimePicker from '../time-picker/locale/bg_BG';
const localeValues: Locale = { const localeValues: Locale = {

2
components/locale/bn_BD.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/bn_BD'; import Pagination from 'rc-pagination/lib/locale/bn_BD';
import Calendar from '../calendar/locale/bn_BD'; import Calendar from '../calendar/locale/bn_BD';
import DatePicker from '../date-picker/locale/bn_BD'; import DatePicker from '../date-picker/locale/bn_BD';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/bn_BD'; import TimePicker from '../time-picker/locale/bn_BD';
const typeTemplate = '${label} টি সঠিক ${type} নয়।'; const typeTemplate = '${label} টি সঠিক ${type} নয়।';

2
components/locale/by_BY.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/by_BY'; import Pagination from 'rc-pagination/lib/locale/by_BY';
import Calendar from '../calendar/locale/by_BY'; import Calendar from '../calendar/locale/by_BY';
import DatePicker from '../date-picker/locale/by_BY'; import DatePicker from '../date-picker/locale/by_BY';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/by_BY'; import TimePicker from '../time-picker/locale/by_BY';
const typeTemplate: string = "${label} не з'яўляецца тыпам ${type}"; const typeTemplate: string = "${label} не з'яўляецца тыпам ${type}";

2
components/locale/ca_ES.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/ca_ES'; import Pagination from 'rc-pagination/lib/locale/ca_ES';
import Calendar from '../calendar/locale/ca_ES'; import Calendar from '../calendar/locale/ca_ES';
import DatePicker from '../date-picker/locale/ca_ES'; import DatePicker from '../date-picker/locale/ca_ES';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/ca_ES'; import TimePicker from '../time-picker/locale/ca_ES';
const typeTemplate = '${label} no és un ${type} vàlid'; const typeTemplate = '${label} no és un ${type} vàlid';

0
components/locale-provider/context.ts → components/locale/context.ts

2
components/locale/cs_CZ.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/cs_CZ'; import Pagination from 'rc-pagination/lib/locale/cs_CZ';
import Calendar from '../calendar/locale/cs_CZ'; import Calendar from '../calendar/locale/cs_CZ';
import DatePicker from '../date-picker/locale/cs_CZ'; import DatePicker from '../date-picker/locale/cs_CZ';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/cs_CZ'; import TimePicker from '../time-picker/locale/cs_CZ';
const typeTemplate = '${label} není platný ${type}'; const typeTemplate = '${label} není platný ${type}';

2
components/locale/da_DK.tsx

@ -1,7 +1,7 @@
import Pagination from 'rc-pagination/lib/locale/da_DK'; import Pagination from 'rc-pagination/lib/locale/da_DK';
import Calendar from '../calendar/locale/da_DK'; import Calendar from '../calendar/locale/da_DK';
import DatePicker from '../date-picker/locale/da_DK'; import DatePicker from '../date-picker/locale/da_DK';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/da_DK'; import TimePicker from '../time-picker/locale/da_DK';
const localeValues: Locale = { const localeValues: Locale = {

2
components/locale/de_DE.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/de_DE'; import Pagination from 'rc-pagination/lib/locale/de_DE';
import Calendar from '../calendar/locale/de_DE'; import Calendar from '../calendar/locale/de_DE';
import DatePicker from '../date-picker/locale/de_DE'; import DatePicker from '../date-picker/locale/de_DE';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/de_DE'; import TimePicker from '../time-picker/locale/de_DE';
const typeTemplate = '${label} ist nicht gültig. ${type} erwartet'; const typeTemplate = '${label} ist nicht gültig. ${type} erwartet';

2
components/locale/el_GR.tsx

@ -1,7 +1,7 @@
import Pagination from 'rc-pagination/lib/locale/el_GR'; import Pagination from 'rc-pagination/lib/locale/el_GR';
import Calendar from '../calendar/locale/el_GR'; import Calendar from '../calendar/locale/el_GR';
import DatePicker from '../date-picker/locale/el_GR'; import DatePicker from '../date-picker/locale/el_GR';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/el_GR'; import TimePicker from '../time-picker/locale/el_GR';
const localeValues: Locale = { const localeValues: Locale = {

2
components/locale/en_GB.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/en_GB'; import Pagination from 'rc-pagination/lib/locale/en_GB';
import Calendar from '../calendar/locale/en_GB'; import Calendar from '../calendar/locale/en_GB';
import DatePicker from '../date-picker/locale/en_GB'; import DatePicker from '../date-picker/locale/en_GB';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/en_GB'; import TimePicker from '../time-picker/locale/en_GB';
const typeTemplate = '${label} is not a valid ${type}'; const typeTemplate = '${label} is not a valid ${type}';

2
components/locale/en_US.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/en_US'; import Pagination from 'rc-pagination/lib/locale/en_US';
import Calendar from '../calendar/locale/en_US'; import Calendar from '../calendar/locale/en_US';
import DatePicker from '../date-picker/locale/en_US'; import DatePicker from '../date-picker/locale/en_US';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/en_US'; import TimePicker from '../time-picker/locale/en_US';
const typeTemplate = '${label} is not a valid ${type}'; const typeTemplate = '${label} is not a valid ${type}';

2
components/locale/es_ES.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/es_ES'; import Pagination from 'rc-pagination/lib/locale/es_ES';
import Calendar from '../calendar/locale/es_ES'; import Calendar from '../calendar/locale/es_ES';
import DatePicker from '../date-picker/locale/es_ES'; import DatePicker from '../date-picker/locale/es_ES';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/es_ES'; import TimePicker from '../time-picker/locale/es_ES';
const typeTemplate = '${label} no es un ${type} válido'; const typeTemplate = '${label} no es un ${type} válido';

2
components/locale/et_EE.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/et_EE'; import Pagination from 'rc-pagination/lib/locale/et_EE';
import Calendar from '../calendar/locale/et_EE'; import Calendar from '../calendar/locale/et_EE';
import DatePicker from '../date-picker/locale/et_EE'; import DatePicker from '../date-picker/locale/et_EE';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/et_EE'; import TimePicker from '../time-picker/locale/et_EE';
const typeTemplate = '${label} ei ole kehtiv ${type}'; const typeTemplate = '${label} ei ole kehtiv ${type}';

2
components/locale/eu_ES.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/eu_ES'; import Pagination from 'rc-pagination/lib/locale/eu_ES';
import Calendar from '../calendar/locale/eu_ES'; import Calendar from '../calendar/locale/eu_ES';
import DatePicker from '../date-picker/locale/eu_ES'; import DatePicker from '../date-picker/locale/eu_ES';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/eu_ES'; import TimePicker from '../time-picker/locale/eu_ES';
const typeTemplate = '${label} ez da ${type} balioduna'; const typeTemplate = '${label} ez da ${type} balioduna';

2
components/locale/fa_IR.tsx

@ -2,7 +2,7 @@
import Pagination from 'rc-pagination/lib/locale/fa_IR'; import Pagination from 'rc-pagination/lib/locale/fa_IR';
import Calendar from '../calendar/locale/fa_IR'; import Calendar from '../calendar/locale/fa_IR';
import DatePicker from '../date-picker/locale/fa_IR'; import DatePicker from '../date-picker/locale/fa_IR';
import type { Locale } from '../locale-provider'; import type { Locale } from '../locale';
import TimePicker from '../time-picker/locale/fa_IR'; import TimePicker from '../time-picker/locale/fa_IR';
const typeTemplate = '${label} از نوع ${type} معتبر نیست'; const typeTemplate = '${label} از نوع ${type} معتبر نیست';

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save