mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
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
This commit is contained in:
parent
221e8bd804
commit
d689c7b855
@ -10,7 +10,7 @@ import type {
|
||||
import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
||||
import * as React from 'react';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||
import LocaleReceiver from '../locale/LocaleReceiver';
|
||||
import CalendarHeader from './Header';
|
||||
import enUS from './locale/en_US';
|
||||
|
||||
|
@ -2,8 +2,8 @@ import React from 'react';
|
||||
import { closePicker, openPicker, selectCell } from '../../date-picker/__tests__/utils';
|
||||
import ConfigProvider from '..';
|
||||
import DatePicker from '../../date-picker';
|
||||
import type { Locale } from '../../locale-provider';
|
||||
import LocaleProvider from '../../locale-provider';
|
||||
import type { Locale } from '../../locale';
|
||||
import LocaleProvider from '../../locale';
|
||||
import enUS from '../../locale/en_US';
|
||||
import zhCN from '../../locale/zh_CN';
|
||||
import Modal from '../../modal';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import type { DerivativeFunc } from '@ant-design/cssinjs';
|
||||
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 { RenderEmptyHandler } from './defaultRenderEmpty';
|
||||
import type { SizeType } from './SizeContext';
|
||||
|
@ -6,9 +6,9 @@ import useMemo from 'rc-util/lib/hooks/useMemo';
|
||||
import * as React from 'react';
|
||||
import type { ReactElement } from 'react';
|
||||
import type { RequiredMark } from '../form/Form';
|
||||
import type { Locale } from '../locale-provider';
|
||||
import LocaleProvider, { ANT_MARK } from '../locale-provider';
|
||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||
import type { Locale } from '../locale';
|
||||
import LocaleProvider, { ANT_MARK } from '../locale';
|
||||
import LocaleReceiver from '../locale/LocaleReceiver';
|
||||
import defaultLocale from '../locale/en_US';
|
||||
import { DesignTokenContext } from '../theme/internal';
|
||||
import defaultSeedToken from '../theme/themes/seed';
|
||||
|
@ -4,9 +4,9 @@ import customParseFormat from 'dayjs/plugin/customParseFormat';
|
||||
import React from 'react';
|
||||
import DatePicker from '..';
|
||||
import ConfigProvider from '../../config-provider';
|
||||
import type { Locale } from '../../locale-provider';
|
||||
import LocaleProvider from '../../locale-provider';
|
||||
import locale from '../../locale-provider/zh_CN';
|
||||
import type { Locale } from '../../locale';
|
||||
import LocaleProvider from '../../locale';
|
||||
import locale from '../../locale/zh_CN';
|
||||
import jaJP from '../../locale/ja_JP';
|
||||
import zhTW from '../locale/zh_TW';
|
||||
import { render } from '../../../tests/utils';
|
||||
|
@ -14,7 +14,7 @@ import DisabledContext from '../../config-provider/DisabledContext';
|
||||
import SizeContext from '../../config-provider/SizeContext';
|
||||
import { FormItemInputContext } from '../../form/context';
|
||||
import { useCompactItemContext } from '../../space/Compact';
|
||||
import LocaleReceiver from '../../locale-provider/LocaleReceiver';
|
||||
import LocaleReceiver from '../../locale/LocaleReceiver';
|
||||
import { getMergedStatus, getStatusClassNames } from '../../_util/statusUtils';
|
||||
import enUS from '../locale/en_US';
|
||||
import { getRangePlaceholder, transPlacement2DropdownAlign } from '../util';
|
||||
|
@ -14,7 +14,7 @@ import { ConfigContext } from '../../config-provider';
|
||||
import DisabledContext from '../../config-provider/DisabledContext';
|
||||
import SizeContext from '../../config-provider/SizeContext';
|
||||
import { FormItemInputContext } from '../../form/context';
|
||||
import LocaleReceiver from '../../locale-provider/LocaleReceiver';
|
||||
import LocaleReceiver from '../../locale/LocaleReceiver';
|
||||
import type { InputStatus } from '../../_util/statusUtils';
|
||||
import { getMergedStatus, getStatusClassNames } from '../../_util/statusUtils';
|
||||
import warning from '../../_util/warning';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import classNames from 'classnames';
|
||||
import * as React from 'react';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||
import LocaleReceiver from '../locale/LocaleReceiver';
|
||||
import DefaultEmptyImg from './empty';
|
||||
import SimpleEmptyImg from './simple';
|
||||
|
||||
|
@ -3,7 +3,7 @@ import classNames from 'classnames';
|
||||
import * as React from 'react';
|
||||
import type { ColProps } 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 type { TooltipProps } from '../tooltip';
|
||||
import Tooltip from '../tooltip';
|
||||
|
@ -1,64 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import type { Locale } from '.';
|
||||
import type { LocaleContextProps } from './context';
|
||||
import LocaleContext from './context';
|
||||
import defaultLocaleData from '../locale/en_US';
|
||||
// locale-provider 文件夹的移除需要修改 @ant-design/tools 和 antd-img-crop
|
||||
import LocaleReceiver from '../locale/LocaleReceiver';
|
||||
|
||||
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 * from '../locale/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];
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { memo, useContext } from 'react';
|
||||
import { fireEvent, pureRender } from '../../../tests/utils';
|
||||
import LocaleProvider from '..';
|
||||
import LocaleContext from '../context';
|
||||
import LocaleProvider from '../../locale';
|
||||
import LocaleContext from '../../locale/context';
|
||||
|
||||
let innerCount = 0;
|
||||
let outerCount = 0;
|
||||
|
@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
|
||||
import { Modal } from '../..';
|
||||
import { waitFakeTimer, render, fireEvent } from '../../../tests/utils';
|
||||
import ConfigProvider from '../../config-provider';
|
||||
import zhCN from '../zh_CN';
|
||||
import zhCN from '../../locale/zh_CN';
|
||||
|
||||
const Demo: React.FC<{ type: string }> = ({ type }) => {
|
||||
useEffect(() => {
|
||||
|
@ -68,8 +68,8 @@ import preParsePostFormat from 'dayjs/plugin/preParsePostFormat';
|
||||
import MockDate from 'mockdate';
|
||||
import React from 'react';
|
||||
import { render } from '../../../tests/utils';
|
||||
import type { Locale } from '..';
|
||||
import LocaleProvider from '..';
|
||||
import type { Locale } from '../../locale';
|
||||
import LocaleProvider from '../../locale';
|
||||
import {
|
||||
Calendar,
|
||||
DatePicker,
|
||||
@ -82,74 +82,74 @@ import {
|
||||
Transfer,
|
||||
} from '../..';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
import arEG from '../ar_EG';
|
||||
import azAZ from '../az_AZ';
|
||||
import bgBG from '../bg_BG';
|
||||
import bnBD from '../bn_BD';
|
||||
import byBY from '../by_BY';
|
||||
import caES from '../ca_ES';
|
||||
import csCZ from '../cs_CZ';
|
||||
import daDK from '../da_DK';
|
||||
import deDE from '../de_DE';
|
||||
import elGR from '../el_GR';
|
||||
import enGB from '../en_GB';
|
||||
import enUS from '../en_US';
|
||||
import esES from '../es_ES';
|
||||
import etEE from '../et_EE';
|
||||
import euES from '../eu_ES';
|
||||
import faIR from '../fa_IR';
|
||||
import fiFI from '../fi_FI';
|
||||
import frBE from '../fr_BE';
|
||||
import frCA from '../fr_CA';
|
||||
import frFR from '../fr_FR';
|
||||
import gaIE from '../ga_IE';
|
||||
import glES from '../gl_ES';
|
||||
import heIL from '../he_IL';
|
||||
import hiIN from '../hi_IN';
|
||||
import hrHR from '../hr_HR';
|
||||
import huHU from '../hu_HU';
|
||||
import hyAM from '../hy_AM';
|
||||
import idID from '../id_ID';
|
||||
import isIS from '../is_IS';
|
||||
import itIT from '../it_IT';
|
||||
import jaJP from '../ja_JP';
|
||||
import kaGE from '../ka_GE';
|
||||
import kkKZ from '../kk_KZ';
|
||||
import kmrIQ from '../kmr_IQ';
|
||||
import kmKH from '../km_KH';
|
||||
import knIN from '../kn_IN';
|
||||
import koKR from '../ko_KR';
|
||||
import kuIQ from '../ku_IQ';
|
||||
import ltLT from '../lt_LT';
|
||||
import lvLV from '../lv_LV';
|
||||
import mkMK from '../mk_MK';
|
||||
import mlIN from '../ml_IN';
|
||||
import mnMN from '../mn_MN';
|
||||
import msMY from '../ms_MY';
|
||||
import nbNO from '../nb_NO';
|
||||
import neNP from '../ne_NP';
|
||||
import nlBE from '../nl_BE';
|
||||
import nlNL from '../nl_NL';
|
||||
import plPL from '../pl_PL';
|
||||
import ptBR from '../pt_BR';
|
||||
import ptPT from '../pt_PT';
|
||||
import roRO from '../ro_RO';
|
||||
import ruRU from '../ru_RU';
|
||||
import siLK from '../si_LK';
|
||||
import skSK from '../sk_SK';
|
||||
import slSI from '../sl_SI';
|
||||
import srRS from '../sr_RS';
|
||||
import svSE from '../sv_SE';
|
||||
import taIN from '../ta_IN';
|
||||
import thTH from '../th_TH';
|
||||
import tkTK from '../tk_TK';
|
||||
import trTR from '../tr_TR';
|
||||
import ukUA from '../uk_UA';
|
||||
import urPK from '../ur_PK';
|
||||
import viVN from '../vi_VN';
|
||||
import zhCN from '../zh_CN';
|
||||
import zhHK from '../zh_HK';
|
||||
import zhTW from '../zh_TW';
|
||||
import arEG from '../../locale/ar_EG';
|
||||
import azAZ from '../../locale/az_AZ';
|
||||
import bgBG from '../../locale/bg_BG';
|
||||
import bnBD from '../../locale/bn_BD';
|
||||
import byBY from '../../locale/by_BY';
|
||||
import caES from '../../locale/ca_ES';
|
||||
import csCZ from '../../locale/cs_CZ';
|
||||
import daDK from '../../locale/da_DK';
|
||||
import deDE from '../../locale/de_DE';
|
||||
import elGR from '../../locale/el_GR';
|
||||
import enGB from '../../locale/en_GB';
|
||||
import enUS from '../../locale/en_US';
|
||||
import esES from '../../locale/es_ES';
|
||||
import etEE from '../../locale/et_EE';
|
||||
import euES from '../../locale/eu_ES';
|
||||
import faIR from '../../locale/fa_IR';
|
||||
import fiFI from '../../locale/fi_FI';
|
||||
import frBE from '../../locale/fr_BE';
|
||||
import frCA from '../../locale/fr_CA';
|
||||
import frFR from '../../locale/fr_FR';
|
||||
import gaIE from '../../locale/ga_IE';
|
||||
import glES from '../../locale/gl_ES';
|
||||
import heIL from '../../locale/he_IL';
|
||||
import hiIN from '../../locale/hi_IN';
|
||||
import hrHR from '../../locale/hr_HR';
|
||||
import huHU from '../../locale/hu_HU';
|
||||
import hyAM from '../../locale/hy_AM';
|
||||
import idID from '../../locale/id_ID';
|
||||
import isIS from '../../locale/is_IS';
|
||||
import itIT from '../../locale/it_IT';
|
||||
import jaJP from '../../locale/ja_JP';
|
||||
import kaGE from '../../locale/ka_GE';
|
||||
import kkKZ from '../../locale/kk_KZ';
|
||||
import kmrIQ from '../../locale/kmr_IQ';
|
||||
import kmKH from '../../locale/km_KH';
|
||||
import knIN from '../../locale/kn_IN';
|
||||
import koKR from '../../locale/ko_KR';
|
||||
import kuIQ from '../../locale/ku_IQ';
|
||||
import ltLT from '../../locale/lt_LT';
|
||||
import lvLV from '../../locale/lv_LV';
|
||||
import mkMK from '../../locale/mk_MK';
|
||||
import mlIN from '../../locale/ml_IN';
|
||||
import mnMN from '../../locale/mn_MN';
|
||||
import msMY from '../../locale/ms_MY';
|
||||
import nbNO from '../../locale/nb_NO';
|
||||
import neNP from '../../locale/ne_NP';
|
||||
import nlBE from '../../locale/nl_BE';
|
||||
import nlNL from '../../locale/nl_NL';
|
||||
import plPL from '../../locale/pl_PL';
|
||||
import ptBR from '../../locale/pt_BR';
|
||||
import ptPT from '../../locale/pt_PT';
|
||||
import roRO from '../../locale/ro_RO';
|
||||
import ruRU from '../../locale/ru_RU';
|
||||
import siLK from '../../locale/si_LK';
|
||||
import skSK from '../../locale/sk_SK';
|
||||
import slSI from '../../locale/sl_SI';
|
||||
import srRS from '../../locale/sr_RS';
|
||||
import svSE from '../../locale/sv_SE';
|
||||
import taIN from '../../locale/ta_IN';
|
||||
import thTH from '../../locale/th_TH';
|
||||
import tkTK from '../../locale/tk_TK';
|
||||
import trTR from '../../locale/tr_TR';
|
||||
import ukUA from '../../locale/uk_UA';
|
||||
import urPK from '../../locale/ur_PK';
|
||||
import viVN from '../../locale/vi_VN';
|
||||
import zhCN from '../../locale/zh_CN';
|
||||
import zhHK from '../../locale/zh_HK';
|
||||
import zhTW from '../../locale/zh_TW';
|
||||
|
||||
dayjs.extend(preParsePostFormat);
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ar_EG';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/az_AZ';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/bg_BG';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/bn_BD';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/by_BY';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ca_ES';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/cs_CZ';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/da_DK';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/de_DE';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/el_GR';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/en_GB';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/en_US';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/es_ES';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/et_EE';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/eu_ES';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/fa_IR';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/fi_FI';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/fr_BE';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/fr_CA';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/fr_FR';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ga_IE';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/gl_ES';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/he_IL';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/hi_IN';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/hr_HR';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/hu_HU';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/hy_AM';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/id_ID';
|
||||
|
||||
export default locale;
|
6
components/locale-provider/index.ts
Normal file
6
components/locale-provider/index.ts
Normal file
@ -0,0 +1,6 @@
|
||||
// locale-provider 文件夹的移除需要修改 @ant-design/tools 和 antd-img-crop
|
||||
import locale from '../locale';
|
||||
|
||||
export * from '../locale';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/is_IS';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/it_IT';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ja_JP';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ka_GE';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/kk_KZ';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/km_KH';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/kmr_IQ';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/kn_IN';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ko_KR';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ku_IQ';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/lt_LT';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/lv_LV';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/mk_MK';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ml_IN';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/mn_MN';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ms_MY';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/nb_NO';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ne_NP';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/nl_BE';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/nl_NL';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/pl_PL';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/pt_BR';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/pt_PT';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ro_RO';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ru_RU';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/si_LK';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/sk_SK';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/sl_SI';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/sr_RS';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/sv_SE';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ta_IN';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/th_TH';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/tk_TK';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/tr_TR';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/uk_UA';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/ur_PK';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/vi_VN';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/zh_CN';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/zh_HK';
|
||||
|
||||
export default locale;
|
@ -1,3 +0,0 @@
|
||||
import locale from '../locale/zh_TW';
|
||||
|
||||
export default locale;
|
64
components/locale/LocaleReceiver.tsx
Normal file
64
components/locale/LocaleReceiver.tsx
Normal file
@ -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,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/ar_EG';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = 'ليس ${label} من نوع ${type} صالحًا';
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/az_AZ';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = '${label}Hökmlü deyil${type}';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/bg_BG';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const localeValues: Locale = {
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/bn_BD';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = '${label} টি সঠিক ${type} নয়।';
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/by_BY';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate: string = "${label} не з'яўляецца тыпам ${type}";
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/ca_ES';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = '${label} no és un ${type} vàlid';
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/cs_CZ';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = '${label} není platný ${type}';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/da_DK';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const localeValues: Locale = {
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/de_DE';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = '${label} ist nicht gültig. ${type} erwartet';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/el_GR';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const localeValues: Locale = {
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/en_GB';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = '${label} is not a valid ${type}';
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/en_US';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = '${label} is not a valid ${type}';
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/es_ES';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = '${label} no es un ${type} válido';
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/et_EE';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = '${label} ei ole kehtiv ${type}';
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/eu_ES';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = '${label} ez da ${type} balioduna';
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Pagination from 'rc-pagination/lib/locale/fa_IR';
|
||||
import Calendar from '../calendar/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';
|
||||
|
||||
const typeTemplate = '${label} از نوع ${type} معتبر نیست';
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user