Browse Source
* 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: updatepull/39431/head
Amumu
2 years ago
committed by
GitHub
170 changed files with 246 additions and 499 deletions
@ -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; |
@ -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; |
@ -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]; |
|||
}; |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue