ant-design/.dumi/hooks/useLocale.ts
lijianan ba999de764
chore: site code format (#39457)
* format: site code format

* Conflicting

* lint

* rename
2022-12-19 13:23:28 +08:00

15 lines
430 B
TypeScript

import { useLocale as useDumiLocale } from 'dumi';
export interface LocaleMap<Key extends string> {
cn: Record<Key, string>;
en: Record<Key, string>;
}
export default function useLocale<Key extends string>(
localeMap?: LocaleMap<Key>,
): [Record<Key, string>, 'cn' | 'en'] {
const { id } = useDumiLocale();
const localeType = id === 'zh-CN' ? 'cn' : ('en' as const);
return [localeMap?.[localeType]!, localeType];
}