Skip to content

Commit

Permalink
docs: change lang by lang (#38943)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Nov 24, 2022
1 parent 0c3ba12 commit 3d0a269
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 2 additions & 12 deletions .dumi/pages/index/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { type FC, useLayoutEffect } from 'react';
import React, { type FC } from 'react';
import { useLocale as useDumiLocale } from 'dumi';
import { css } from '@emotion/react';
import useLocale from '../../hooks/useLocale';
Expand All @@ -11,8 +11,6 @@ import BannerRecommends from './components/BannerRecommends';
import ComponentsList from './components/ComponentsList';
import DesignFramework from './components/DesignFramework';
import { ConfigProvider } from 'antd';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';

const useStyle = () => {
const { token } = useSiteToken();
Expand Down Expand Up @@ -45,22 +43,14 @@ const locales = {
};

const Homepage: FC = () => {
const [locale, lang] = useLocale(locales);
const [locale] = useLocale(locales);
const { id: localeId } = useDumiLocale();
const localeStr = localeId === 'zh-CN' ? 'cn' : 'en';

const [siteData, loading] = useSiteData();

const style = useStyle();

useLayoutEffect(() => {
if (lang === 'cn') {
dayjs.locale('zh-cn');
} else {
dayjs.locale('en');
}
}, []);

return (
<ConfigProvider theme={{ algorithm: undefined }}>
<section>
Expand Down
12 changes: 11 additions & 1 deletion .dumi/theme/layouts/DocLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { type FC, useEffect, useMemo, useRef } from 'react';
import React, { type FC, useEffect, useMemo, useRef, useLayoutEffect } from 'react';
import 'dayjs/locale/zh-cn';
import dayjs from 'dayjs';
import { useOutlet, useSearchParams, Helmet } from 'dumi';
import Header from 'dumi/theme/slots/Header';
import Footer from 'dumi/theme/slots/Footer';
Expand Down Expand Up @@ -52,6 +54,14 @@ const DocLayout: FC = () => {
setIsMobile(window.innerWidth < RESPONSIVE_MOBILE);
};

useLayoutEffect(() => {
if (lang === 'cn') {
dayjs.locale('zh-cn');
} else {
dayjs.locale('en');
}
}, []);

useEffect(() => {
const nprogressHiddenStyle = document.getElementById('nprogress-style');
if (nprogressHiddenStyle) {
Expand Down

0 comments on commit 3d0a269

Please sign in to comment.