mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-28 11:08:30 +08:00
23 lines
592 B
TypeScript
23 lines
592 B
TypeScript
import { useLocale as useDumiLocale } from 'dumi';
|
|
|
|
export interface LocaleMap<
|
|
K extends PropertyKey = PropertyKey,
|
|
V extends string | ((...params: any[]) => string) = string,
|
|
> {
|
|
cn: Record<K, V>;
|
|
en: Record<K, V>;
|
|
}
|
|
|
|
const useLocale = <
|
|
K extends PropertyKey = PropertyKey,
|
|
V extends string | ((...params: any[]) => string) = string,
|
|
>(
|
|
localeMap?: LocaleMap<K, V>,
|
|
): [Record<K, V>, 'cn' | 'en'] => {
|
|
const { id } = useDumiLocale();
|
|
const localeType = id === 'zh-CN' ? 'cn' : 'en';
|
|
return [localeMap?.[localeType]!, localeType] as const;
|
|
};
|
|
|
|
export default useLocale;
|