feat:组件框架
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// @ts-nocheck
|
||||
// This file is generated by Umi automatically
|
||||
// DO NOT CHANGE IT MANUALLY!
|
||||
import { history } from 'dumi';
|
||||
import React, { useState, useLayoutEffect, useCallback, type ReactNode } from 'react';
|
||||
import { RawIntlProvider, createIntl, createIntlCache } from '/Users/donghym/Desktop/day/UI/Nova/node_modules/.pnpm/react-intl@7.0.0_react@19.2.6_typescript@6.0.3/node_modules/react-intl';
|
||||
import { useIsomorphicLayoutEffect } from '/Users/donghym/Desktop/day/UI/Nova/node_modules/.pnpm/dumi@2.4.28_@babel+core@7.29.7_@swc+helpers@0.5.15_@types+node@25.9.1_@types+react@18.3_cf46fd6bbea4e97c0978eb785c920599/node_modules/dumi/dist/client/theme-api/utils.js'
|
||||
import { locales, messages } from './config';
|
||||
|
||||
const cache = createIntlCache();
|
||||
|
||||
const LocalesContainer: FC<{ children: ReactNode }> = (props) => {
|
||||
const getIntl = useCallback(() => {
|
||||
const base = ""
|
||||
const matched = locales.slice().reverse().find((locale) => (
|
||||
'suffix' in locale
|
||||
// suffix mode
|
||||
? history.location.pathname.replace(/([^/])\/$/, '$1').endsWith(locale.suffix)
|
||||
// base mode
|
||||
: history.location.pathname.replace(/([^/])\/$/, '$1')
|
||||
.startsWith(base + locale.base)
|
||||
));
|
||||
let locale = matched ? matched.id : locales[0].id;
|
||||
// using query on demos
|
||||
if(history.location.pathname.startsWith(base + '/~demos')){
|
||||
const params = new URLSearchParams(history.location.search);
|
||||
// match the locale of the query
|
||||
if (params.get('locale')){
|
||||
locale = params.get('locale');
|
||||
}
|
||||
}
|
||||
const localeMessages = messages[locale] || {};
|
||||
|
||||
// append internal message, for use intl as string template util
|
||||
localeMessages['$internal.edit.link'] = undefined;
|
||||
|
||||
localeMessages['$internal.api.sourceLink'] = undefined;
|
||||
|
||||
return createIntl({ locale, messages: localeMessages }, cache);
|
||||
}, []);
|
||||
const [intl, setIntl] = useState(() => getIntl());
|
||||
|
||||
useIsomorphicLayoutEffect(() => {
|
||||
return history.listen(() => {
|
||||
setIntl(getIntl());
|
||||
});
|
||||
}, []);
|
||||
|
||||
return <RawIntlProvider value={intl} key={intl.locale}>{props.children}</RawIntlProvider>;
|
||||
}
|
||||
|
||||
export function i18nProvider(container: Element) {
|
||||
return React.createElement(LocalesContainer, null, container);
|
||||
}
|
||||
Reference in New Issue
Block a user