From d1bf40e6d6f1fe9a0764237c44fef6879dd70603 Mon Sep 17 00:00:00 2001 From: TechQuery Date: Sun, 10 Nov 2024 05:37:03 +0800 Subject: [PATCH] [optimize] simplify i18n imports --- source/component/SummitCard.tsx | 4 +- source/component/TopNavBar.tsx | 6 +-- source/i18n/index.ts | 2 + source/page/2017/data.ts | 30 +++++------ source/page/2017/index.tsx | 26 +++++----- source/page/2018-Code4City/data.ts | 77 +++++++++++++--------------- source/page/2018-Code4City/index.tsx | 15 +++--- source/page/2018/data.ts | 41 +++++++-------- source/page/2018/index.tsx | 34 ++++++------ source/page/2019/PageAccount.tsx | 10 ++-- source/page/2019/index.tsx | 23 ++++----- source/page/Community.tsx | 18 +++---- source/page/Home.tsx | 5 +- source/page/data.ts | 7 +-- source/page/index.tsx | 16 ++++-- 15 files changed, 144 insertions(+), 170 deletions(-) diff --git a/source/component/SummitCard.tsx b/source/component/SummitCard.tsx index f8a4910..fa48241 100644 --- a/source/component/SummitCard.tsx +++ b/source/component/SummitCard.tsx @@ -9,12 +9,10 @@ import { import { FC, observer } from 'web-cell'; import { isXDomain } from 'web-utility'; -import { i18n } from '../i18n'; +import { t } from '../i18n'; import { summits } from '../page/data'; import * as style from './SummitCard.module.less'; -const { t } = i18n; - export type SummitCardProps = ReturnType[0] & CardProps; export const SummitCard: FC = observer( diff --git a/source/component/TopNavBar.tsx b/source/component/TopNavBar.tsx index 2a2866b..3748ab9 100644 --- a/source/component/TopNavBar.tsx +++ b/source/component/TopNavBar.tsx @@ -1,12 +1,12 @@ -import { FC, observer } from 'web-cell'; import { NavLink, NavLinkProps, OffcanvasNavbar, OffcanvasNavbarProps } from 'boot-cell'; +import { FC, observer } from 'web-cell'; -import { i18n, LanguageName } from '../i18n'; +import { i18n, LanguageName,t } from '../i18n'; export interface TopNavBarProps extends OffcanvasNavbarProps { menu?: NavLinkProps[]; @@ -14,8 +14,6 @@ export interface TopNavBarProps extends OffcanvasNavbarProps { const OriginalURLPattern = /^(https?|#)/; -const { t } = i18n; - export const TopNavBar: FC = observer( ({ menu = [], ...rest }) => ( import('./en-US') }); +export const { t } = i18n; + export const LanguageName: Record<(typeof i18n)['currentLanguage'], string> = { 'zh-CN': '简体中文', 'zh-TW': '正體中文', diff --git a/source/page/2017/data.ts b/source/page/2017/data.ts index 820fb69..0eaec4a 100644 --- a/source/page/2017/data.ts +++ b/source/page/2017/data.ts @@ -1,30 +1,26 @@ +import { t } from '../../i18n'; import avatars from './image/guests'; import { - QRGJ, - FCC_CDG, - BBD, - HCXY, _3W, - DevEco, + BBD, BW, + DevEco, + DKS, + FCC_CDG, + GDG, GT, - SYL, - QE, + HCXY, JueJin, + MZ, OSChina, + QE, + QRGJ, SF, - ZDK, - MZ, - GDG, - TW, + SYL, TH, + TW, WORK, - DKS -} from './image/logos'; - -import { i18n } from '../../i18n'; - -const { t } = i18n; + ZDK} from './image/logos'; export const title = () => t('chengdu_web_frontend_conference_2017'); diff --git a/source/page/2017/index.tsx b/source/page/2017/index.tsx index f65d2e7..5270840 100644 --- a/source/page/2017/index.tsx +++ b/source/page/2017/index.tsx @@ -1,20 +1,20 @@ -import { Card, CardBody, CardImg, CardTitle, Button, Ratio } from 'boot-cell'; +import { Button, Card, CardBody, CardImg, CardTitle, Ratio } from 'boot-cell'; import { Accordion, AccordionBody, AccordionHeader, AccordionItem } from 'boot-cell'; -import { i18n } from '../../i18n'; -import { LogoList } from './LogoList'; -import * as style from './index.module.less'; -import { guests, flows, logos, title } from './data'; -import { banner, qrcode } from './image'; +import { observer } from 'web-cell'; -const { t } = i18n; +import { t } from '../../i18n'; +import { flows, guests, logos, title } from './data'; +import { banner, qrcode } from './image'; +import * as style from './index.module.less'; +import { LogoList } from './LogoList'; -export default () => ( - <> +export default observer(() => ( +
@@ -32,7 +32,7 @@ export default () => (
{guests().map(({ avatar, name, description }) => ( -
+
@@ -106,7 +106,7 @@ export default () => (

{t('special_thanks')}  - + BBD - {t('wang_bo')}   @@ -119,5 +119,5 @@ export default () => ( /> - -); +

+)); diff --git a/source/page/2018-Code4City/data.ts b/source/page/2018-Code4City/data.ts index c50df7d..c382f60 100644 --- a/source/page/2018-Code4City/data.ts +++ b/source/page/2018-Code4City/data.ts @@ -1,57 +1,52 @@ -import gallery from './image/gallery'; -import { i18n } from '../../i18n'; +import { t } from '../../i18n'; +import { + BBD, + DevEco, + DKS, + FCC_CDG, + GDG, + GT, + HCXY, + JueJin, + OSChina, + SYL} from '../2017/image/logos'; import { - hushenquan, fanxiaobin, - shenchangkun, - maoyufeng, - wenqixiang, + hushenquan, + liangtongming, liwanpeng, + lvyan, + maoyufeng, qinglinbo, - zhangwei, - liangtongming, - lvyan -} from './image/avatar'; + shenchangkun, + wenqixiang, + zhangwei} from './image/avatar'; +import gallery from './image/gallery'; import { cdht, + cdhttv, cdkfx, - XinYaoHang, - JRsquare, - Monstarlab, + cdtv, + first, + fm940, github, - Microsoft, - tap4fun, jhspace, - SegmentFault, - ThoughtWorks, - tedxChengDu, - mikecrm, - first, jintai, + JRsquare, + kct, lvs, - yunpian, + Microsoft, + mikecrm, + Monstarlab, + scdaily, sctv, - cdtv, - cdhttv, + SegmentFault, sinasc, - scdaily, - fm940, - kct -} from './image/logo'; -import { - FCC_CDG, - BBD, - GDG, - DevEco, - GT, - SYL, - HCXY, - JueJin, - OSChina, - DKS -} from '../2017/image/logos'; - -const { t } = i18n; + tap4fun, + tedxChengDu, + ThoughtWorks, + XinYaoHang, + yunpian} from './image/logo'; export const awards = () => [ { diff --git a/source/page/2018-Code4City/index.tsx b/source/page/2018-Code4City/index.tsx index b739f79..128dfb4 100644 --- a/source/page/2018-Code4City/index.tsx +++ b/source/page/2018-Code4City/index.tsx @@ -1,16 +1,15 @@ -import { Container, Button, Image } from 'boot-cell'; +import { Button, Container, Image } from 'boot-cell'; import { Carousel, CarouselCaption, CarouselItem } from 'boot-cell'; +import { observer } from 'web-cell'; +import { t } from '../../i18n'; +import { awards, review, sponsors,vips } from './data'; import { GuestCard } from './GuestCard'; -import * as style from './index.module.less'; import BG_mountain from './image/BG-mountain.png'; import BG_points from './image/BG-points.png'; -import { review, awards, vips, sponsors } from './data'; - -import { i18n } from '../../i18n'; -const { t } = i18n; +import * as style from './index.module.less'; -export default () => ( +export default observer(() => (
(
-); +)); diff --git a/source/page/2018/data.ts b/source/page/2018/data.ts index 51cab9f..ccb9de2 100644 --- a/source/page/2018/data.ts +++ b/source/page/2018/data.ts @@ -1,38 +1,33 @@ +import { t } from '../../i18n'; +import { BW, JueJin, OSChina, SF,SYL } from '../2017/image/logos'; import { FCC_CDC } from './image'; -import { JueJin, BW, SYL, OSChina, SF } from '../2017/image/logos'; +import { + Guo_DaFeng, + Guo_LinShuo, + Huang_Yi, + Quincy_Larson, + Si_Yue, + Xiong_Jie, + Yu_Che} from './image/lecturer'; import { epubit, fezaoduke, + mikecrm, turing, - young, - mikecrm -} from './image/logo/partner'; + young} from './image/logo/partner'; import { BaiCiZhan, baozun, cocoet, sxl } from './image/logo/sponsor'; import { - Quincy_Larson, - Xiong_Jie, - Huang_Yi, - Si_Yue, - Yu_Che, - Guo_LinShuo, - Guo_DaFeng -} from './image/lecturer'; -import { + CD_LUG, + Covariant_Script, Deepin, - WebCell, - H5DS, Fun_loading, - UKylin, - Covariant_Script, + H5DS, + KaiYuanShe, PI6, React_Admin, - KaiYuanShe, + UKylin, Vena_Network, - CD_LUG -} from './image/project'; -import { i18n } from '../../i18n'; - -const { t } = i18n; + WebCell} from './image/project'; export const title = () => t('chengdu_web_frontend_conference_2018'); diff --git a/source/page/2018/index.tsx b/source/page/2018/index.tsx index bad7174..8c62acd 100644 --- a/source/page/2018/index.tsx +++ b/source/page/2018/index.tsx @@ -1,31 +1,29 @@ import { Container, Ratio, Table } from 'boot-cell'; import { Button, Image, Nav, NavLink } from 'boot-cell'; -import { Card, CardImg, CardBody, CardTitle } from 'boot-cell'; +import { Card, CardBody, CardImg, CardTitle } from 'boot-cell'; import { marked } from 'marked'; +import { observer } from 'web-cell'; import { TopNavBar } from '../../component/TopNavBar'; -import { LogoList } from './LogoList'; -import * as style from './index.module.less'; +import { t } from '../../i18n'; import { - title, - sections, + companies, + hosts, lecturers, - schedule, + partners, projects, - topics, review, - hosts, + schedule, + sections, sponsors, - partners, - companies -} from './data'; + title, + topics} from './data'; import { poster, undraw_01, undraw_04 } from './image'; import photos from './image/photos'; +import * as style from './index.module.less'; +import { LogoList } from './LogoList'; -import { i18n } from '../../i18n'; -const { t } = i18n; - -export default () => ( +export default observer(() => (
(
{projects().map( ({ type, URL, title, detail, logo }) => ( -
+
@@ -124,7 +122,7 @@ export default () => ( {title} @@ -293,4 +291,4 @@ export default () => (
-); +)); diff --git a/source/page/2019/PageAccount.tsx b/source/page/2019/PageAccount.tsx index ae58699..8830310 100644 --- a/source/page/2019/PageAccount.tsx +++ b/source/page/2019/PageAccount.tsx @@ -1,13 +1,11 @@ -import { WebCell, component, observer } from 'web-cell'; -import { parseTextTable } from 'web-utility'; import { Table } from 'boot-cell'; import { computed, observable } from 'mobx'; +import { component, observer,WebCell } from 'web-cell'; +import { parseTextTable } from 'web-utility'; -import { i18n } from '../../i18n'; +import { t } from '../../i18n'; import { PageFrame } from './PageFrame'; -const { t } = i18n; - type Account = Record<'item' | 'manager' | 'date' | 'remark', string> & Record<'price' | 'count', number>; @@ -56,7 +54,7 @@ export default class AccountPage extends HTMLElement implements WebCell { {count} {manager && ( - + @{manager} )} diff --git a/source/page/2019/index.tsx b/source/page/2019/index.tsx index b492ab1..340ab8d 100644 --- a/source/page/2019/index.tsx +++ b/source/page/2019/index.tsx @@ -1,13 +1,14 @@ -import groupBy from 'lodash.groupby'; -import { Jumbotron, Button, Tab, Tabs, Ratio, CountDown } from 'boot-cell'; +import { Button, CountDown,Jumbotron, Ratio, Tab, Tabs } from 'boot-cell'; import { Card, CardBody, CardImg, CardTitle } from 'boot-cell'; +import groupBy from 'lodash.groupby'; +import { observer } from 'web-cell'; +import { t } from '../../i18n'; +import BuyCode from './data/BuyCode.png'; +import data from './data/index.json'; import { PageFrame } from './PageFrame'; -import { TopicGroup, Topic } from './TopicGroup'; import { PartnerGroup } from './PartnerGroup'; - -import data from './data/index.json'; -import BuyCode from './data/BuyCode.png'; +import { Topic,TopicGroup } from './TopicGroup'; const topicGroups = Object.entries( groupBy(data.topics, ({ date, place }) => `${date} ${place}`) @@ -18,10 +19,7 @@ const topicGroups = Object.entries( ); const partnerGroups = Object.entries(groupBy(data.partners, 'title')); -import { i18n } from '../../i18n'; -const { t } = i18n; - -export default () => ( +export default observer(() => ( ( @{GitHub} @@ -121,5 +119,4 @@ export default () => ( src={BuyCode} /> -); -// +)); diff --git a/source/page/Community.tsx b/source/page/Community.tsx index 08390d9..2a268f8 100644 --- a/source/page/Community.tsx +++ b/source/page/Community.tsx @@ -1,16 +1,14 @@ import { Image } from 'boot-cell'; +import { observer } from 'web-cell'; -import { TopNavBar } from '../component/TopNavBar'; import { Feature } from '../component/Feature'; -import { common_menu, features } from './data'; +import { TopNavBar } from '../component/TopNavBar'; +import { t } from '../i18n'; import { FCC_CDC } from './2018/image'; +import { common_menu, features } from './data'; -import { i18n } from '../i18n'; - -const { t } = i18n; - -export default () => ( - <> +export default observer(() => ( +
( ))}
- -); +
+)); diff --git a/source/page/Home.tsx b/source/page/Home.tsx index 8ee8324..bc03f98 100644 --- a/source/page/Home.tsx +++ b/source/page/Home.tsx @@ -4,12 +4,9 @@ import { FC, observer } from 'web-cell'; import { SummitCard } from '../component/SummitCard'; import { TopNavBar } from '../component/TopNavBar'; +import { t } from '../i18n'; import { common_menu, summits } from './data'; -import { i18n } from '../i18n'; - -const { t } = i18n; - export const HomePage: FC = observer(props => (
diff --git a/source/page/data.ts b/source/page/data.ts index f7c0e7f..2c985bd 100644 --- a/source/page/data.ts +++ b/source/page/data.ts @@ -1,14 +1,11 @@ +import { t } from '../i18n'; import WeChat_QRC from '../image/FCC-CDG-WeChat.png'; import { wechatLogo as banner_2017 } from './2017/image'; +import { FCC_CDC, poster as banner_2018 } from './2018/image'; import gallery_Code4City from './2018-Code4City/image/gallery'; import banner_2018_React from './2018-React/React-ChengDu.jpg'; -import { FCC_CDC, poster as banner_2018 } from './2018/image'; import banner_2019 from './2019/data/banner.jpg'; -import { i18n } from '../i18n'; - -const { t } = i18n; - export const common_menu = () => [ { title: t('organizer_introduction'), href: 'community' }, { title: t('national_it_events'), href: 'activity' } diff --git a/source/page/index.tsx b/source/page/index.tsx index 3456784..6a0f55c 100644 --- a/source/page/index.tsx +++ b/source/page/index.tsx @@ -1,12 +1,10 @@ import { createRouter } from 'cell-router'; import { lazy, observer } from 'web-cell'; -import { i18n } from '../i18n'; +import { t } from '../i18n'; import WeChat_QRC from '../image/FCC-CDG-WeChat.png'; import { HomePage } from './Home'; -const { t } = i18n; - const CommunityPage = lazy(() => import('./Community')), ActivityPage = lazy(() => import('./Activity')), Page2017 = lazy(() => import('./2017')), @@ -41,14 +39,22 @@ const Footer = observer(() => (

{t('about_us')}

{t('nonprofit_organization')}   - + freeCodeCamp {' '}   {t('since2014')}

- + freeCodeCamp {t('chengdu_community')} {' '}