From a07ee2d74d8528b32b932eacbaf2b40f69a4aac6 Mon Sep 17 00:00:00 2001 From: Pablo Pettinari Date: Wed, 21 Sep 2022 23:23:50 -0300 Subject: [PATCH 001/108] refactor all the components --- src/components/BeaconChainActions.tsx | 40 +- src/components/Breadcrumbs.tsx | 12 +- src/components/ButtonDropdown.tsx | 8 +- src/components/EthExchanges.tsx | 33 +- src/components/FeedbackWidget.tsx | 19 +- src/components/FileContributors.tsx | 6 +- src/components/Footer.tsx | 8 +- src/components/Layer2/Layer2Onboard.tsx | 34 +- src/components/Layer2ProductCard.tsx | 14 +- src/components/Layout.tsx | 49 +- src/components/Link.tsx | 7 +- src/components/Logo.tsx | 10 +- src/components/MergeArticleList.tsx | 83 +-- src/components/MergeInfographic.tsx | 14 +- src/components/Nav/Dropdown.tsx | 11 +- src/components/Nav/Menu.tsx | 6 +- src/components/Nav/Mobile.tsx | 14 +- src/components/Nav/index.tsx | 9 +- src/components/PageMetadata.tsx | 12 +- src/components/Roadmap.tsx | 15 +- src/components/Search/Input.tsx | 7 +- src/components/Search/index.tsx | 6 +- src/components/ShardChainsList.tsx | 56 +- src/components/SideNav.tsx | 7 +- src/components/StablecoinAccordion.tsx | 71 +- src/components/StablecoinBoxGrid.tsx | 7 +- .../Staking/StakingCommunityCallout.tsx | 7 +- .../Staking/StakingLaunchpadWidget.tsx | 15 +- src/components/Staking/StakingStatsBox.tsx | 10 +- src/components/StatsBoxGrid.tsx | 54 +- src/components/Translation.tsx | 8 +- src/components/Trilemma.tsx | 13 +- src/components/TutorialMetadata.tsx | 6 +- src/pages-conditional/dapps.tsx | 619 +++++------------- src/pages-conditional/eth.tsx | 27 +- src/pages-conditional/wallets.tsx | 54 +- src/pages-conditional/what-is-ethereum.tsx | 80 +-- src/pages/assets.tsx | 255 +++----- src/pages/bug-bounty.tsx | 54 +- src/pages/community.tsx | 104 +-- .../translation-program/acknowledgements.tsx | 30 +- src/pages/developers/index.tsx | 18 +- src/pages/developers/learning-tools.tsx | 11 +- src/pages/developers/local-environment.tsx | 20 +- src/pages/developers/tutorials.tsx | 15 +- src/pages/get-eth.tsx | 48 +- src/pages/index.tsx | 136 ++-- src/pages/languages.tsx | 19 +- src/pages/layer-2.tsx | 136 ++-- src/pages/learn/index.tsx | 191 ++---- src/pages/run-a-node.tsx | 44 +- src/pages/stablecoins.tsx | 176 ++--- src/pages/staking/deposit-contract.tsx | 27 +- src/pages/staking/index.tsx | 58 +- src/pages/upgrades/get-involved/index.tsx | 17 +- src/pages/upgrades/index.tsx | 116 +--- src/pages/upgrades/vision.tsx | 17 +- src/pages/wallets/find-wallet.tsx | 12 +- src/scripts/mergeTranslations.ts | 2 +- src/templates/static.tsx | 8 +- src/templates/upgrade.tsx | 6 +- src/templates/use-cases.tsx | 2 - src/utils/translations.ts | 29 +- 63 files changed, 968 insertions(+), 2034 deletions(-) diff --git a/src/components/BeaconChainActions.tsx b/src/components/BeaconChainActions.tsx index 3725fcf9664..29f7eaa0a66 100644 --- a/src/components/BeaconChainActions.tsx +++ b/src/components/BeaconChainActions.tsx @@ -1,9 +1,8 @@ import React from "react" import { useStaticQuery, graphql } from "gatsby" import styled from "@emotion/styled" -import { useIntl } from "react-intl" +import { useTranslation } from "gatsby-plugin-react-i18next" -import { translateMessageId } from "../utils/translations" import { getImage, ImageDataLike } from "../utils/image" import CardList from "./CardList" @@ -88,7 +87,7 @@ type BeaconQueryTypes = { } const BeaconChainActions: React.FC = () => { - const intl = useIntl() + const { t } = useTranslation() const data = useStaticQuery(BeaconStaticQuery) const datapoints: Array = [ @@ -97,44 +96,32 @@ const BeaconChainActions: React.FC = () => { image: getImage(data.beaconscan)!, alt: "", link: "https://beaconscan.com", - description: translateMessageId("consensus-beaconscan-desc", intl), + description: t("consensus-beaconscan-desc"), }, { title: "beaconcha.in", image: getImage(data.beaconchain)!, alt: "", link: "https://beaconcha.in", - description: translateMessageId("consensus-beaconcha-in-desc", intl), + description: t("consensus-beaconcha-in-desc"), }, ] //TODO: we should refactor the naming here instead of using authors into the description field const reads: Array = [ { - title: translateMessageId( - "page-upgrade-article-title-two-point-oh", - intl - ), + title: t("page-upgrade-article-title-two-point-oh"), description: "Status", link: "https://our.status.im/two-point-oh-the-beacon-chain/", }, { - title: translateMessageId( - "page-upgrade-article-title-beacon-chain-explainer", - intl - ), + title: t("page-upgrade-article-title-beacon-chain-explainer"), description: "Ethos.dev", link: "https://ethos.dev/beacon-chain/", }, { - title: translateMessageId( - "page-upgrade-article-title-sharding-consensus", - intl - ), - description: translateMessageId( - "page-upgrade-article-author-ethereum-foundation", - intl - ), + title: t("page-upgrade-article-title-sharding-consensus"), + description: t("page-upgrade-article-author-ethereum-foundation"), link: "https://blog.ethereum.org/2020/03/27/sharding-consensus/", }, ] @@ -144,8 +131,8 @@ const BeaconChainActions: React.FC = () => { @@ -156,11 +143,8 @@ const BeaconChainActions: React.FC = () => { diff --git a/src/components/Breadcrumbs.tsx b/src/components/Breadcrumbs.tsx index be3ade28881..5460a050ca1 100644 --- a/src/components/Breadcrumbs.tsx +++ b/src/components/Breadcrumbs.tsx @@ -1,10 +1,10 @@ import React from "react" import styled from "@emotion/styled" -import { useIntl } from "react-intl" +import { useTranslation } from "gatsby-plugin-react-i18next" import Link from "./Link" -import { isLang, supportedLanguages } from "../utils/languages" -import { isTranslationKey, translateMessageId } from "../utils/translations" +import { isLang } from "../utils/languages" +import { isTranslationKey } from "../utils/translations" const ListContainer = styled.nav` margin-bottom: 2rem; @@ -71,7 +71,7 @@ const Breadcrumbs: React.FC = ({ startDepth = 0, ...restProps }) => { - const intl = useIntl() + const { t } = useTranslation() const slugChunk = slug.split("/") const sliced = slugChunk.filter((item) => !!item).slice(startDepth) @@ -79,9 +79,9 @@ const Breadcrumbs: React.FC = ({ const crumbs = sliced.map((path, idx) => { // If homepage (e.g. "en"), set text to "home" translation const text = isLang(path) - ? translateMessageId("page-index-meta-title", intl) + ? t("page-index-meta-title") : isTranslationKey(path) - ? translateMessageId(path, intl) + ? t(path) : "" return { diff --git a/src/components/ButtonDropdown.tsx b/src/components/ButtonDropdown.tsx index 501bcc139cb..cdbb6f74fe3 100644 --- a/src/components/ButtonDropdown.tsx +++ b/src/components/ButtonDropdown.tsx @@ -1,7 +1,7 @@ // Libraries import React, { useState, createRef } from "react" import styled from "@emotion/styled" -import { useIntl } from "react-intl" +import { useTranslation } from "gatsby-plugin-react-i18next" import { motion } from "framer-motion" import { MdMenu } from "react-icons/md" @@ -12,7 +12,7 @@ import Translation from "./Translation" // Utils import { useOnClickOutside } from "../hooks/useOnClickOutside" -import { translateMessageId, TranslationKey } from "../utils/translations" +import { TranslationKey } from "../utils/translations" import { trackCustomEvent } from "../utils/matomo" const Container = styled.div` @@ -120,7 +120,7 @@ export interface IProps { const ButtonDropdown: React.FC = ({ list, className }) => { const [isOpen, setIsOpen] = useState(false) - const intl = useIntl() + const { t } = useTranslation() const ref = createRef() useOnClickOutside(ref, () => setIsOpen(false)) @@ -136,7 +136,7 @@ const ButtonDropdown: React.FC = ({ list, className }) => { @@ -270,24 +266,21 @@ const FeedbackWidget: React.FC = ({ className }) => { )} - + diff --git a/src/components/FileContributors.tsx b/src/components/FileContributors.tsx index 8ea5765552a..57fddb7b889 100644 --- a/src/components/FileContributors.tsx +++ b/src/components/FileContributors.tsx @@ -1,5 +1,5 @@ import React, { useState } from "react" -import { useIntl } from "react-intl" +import { useI18next } from "gatsby-plugin-react-i18next" import { css, Theme } from "@emotion/react" import styled from "@emotion/styled" import { useQuery, gql } from "@apollo/client" @@ -259,7 +259,7 @@ const FileContributors: React.FC = ({ editPath, }) => { const [isModalOpen, setModalOpen] = useState(false) - const intl = useIntl() + const { language } = useI18next() const { loading, error, data } = useQuery(COMMIT_HISTORY, { variables: { relativePath }, @@ -332,7 +332,7 @@ const FileContributors: React.FC = ({ )} {!lastContributor.user && {lastContributor.name}},{" "} - {getLocaleTimestamp(intl.locale as Lang, lastCommit.committedDate)} + {getLocaleTimestamp(language as Lang, lastCommit.committedDate)} diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index fd447bd87b2..266dacc0d21 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -1,6 +1,6 @@ import React from "react" import styled from "@emotion/styled" -import { useIntl } from "react-intl" +import { useI18next } from "gatsby-plugin-react-i18next" import { StaticQuery, graphql } from "gatsby" import { Icon } from "@chakra-ui/react" import { FaDiscord, FaGithub, FaTwitter, FaYoutube } from "react-icons/fa" @@ -136,9 +136,9 @@ export interface LinkSection { export interface IProps {} const Footer: React.FC = () => { - const intl = useIntl() + const { language } = useI18next() - const isPageRightToLeft = isLangRightToLeft(intl.locale as Lang) + const isPageRightToLeft = isLangRightToLeft(language as Lang) const linkSections: Array = [ { @@ -377,7 +377,7 @@ const Footer: React.FC = () => { :{" "} {getLocaleTimestamp( - intl.locale as Lang, + language as Lang, data.allSiteBuildMetadata.edges[0].node.buildTime )} diff --git a/src/components/Layer2/Layer2Onboard.tsx b/src/components/Layer2/Layer2Onboard.tsx index f96d850307a..a75c28f8b93 100644 --- a/src/components/Layer2/Layer2Onboard.tsx +++ b/src/components/Layer2/Layer2Onboard.tsx @@ -2,7 +2,7 @@ import { GatsbyImage, IGatsbyImageData } from "gatsby-plugin-image" import React, { useState } from "react" import styled from "@emotion/styled" -import { useIntl } from "react-intl" +import { useTranslation } from "gatsby-plugin-react-i18next" // Components import ButtonLink from "../ButtonLink" @@ -15,7 +15,6 @@ import cexSupport from "../../data/layer-2/cex-layer-2-support.json" //Utils import { trackCustomEvent } from "../../utils/matomo" -import { translateMessageId } from "../../utils/translations" // Styles const Content = styled.div` @@ -201,7 +200,7 @@ const Layer2Onboard: React.FC = ({ ethIcon, ethIconAlt, }) => { - const intl = useIntl() + const { t } = useTranslation() const [selectedExchange, setSelectedExchange] = useState() const [selectedL2, setSelectedL2] = useState() @@ -262,30 +261,20 @@ const Layer2Onboard: React.FC = ({ }) setSelectedL2(selectedOption.l2) }} - placeholder={translateMessageId( - "layer-2-onboard-wallet-input-placeholder", - intl - )} + placeholder={t("layer-2-onboard-wallet-input-placeholder")} /> {selectedL2 && (

- {`${translateMessageId( - "layer-2-onboard-wallet-selected-1", - intl - )} ${selectedL2.name} ${translateMessageId( - "layer-2-onboard-wallet-selected-2", - intl - )}`} + {`${t("layer-2-onboard-wallet-selected-1")} ${ + selectedL2.name + } ${t("layer-2-onboard-wallet-selected-2")}`}

{selectedL2.bridgeWallets.join(", ")}

- {`${selectedL2.name} ${translateMessageId( - "layer-2-bridge", - intl - )}`} + {`${selectedL2.name} ${t("layer-2-bridge")}`}
@@ -318,10 +307,7 @@ const Layer2Onboard: React.FC = ({ }) setSelectedExchange(selectedOption.cex) }} - placeholder={translateMessageId( - "layer-2-onboard-exchange-input-placeholder", - intl - )} + placeholder={t("layer-2-onboard-exchange-input-placeholder")} /> @@ -353,9 +339,7 @@ const Layer2Onboard: React.FC = ({ - {`${translateMessageId("layer-2-go-to", intl)} ${ - selectedExchange.name - }`} + {`${t("layer-2-go-to")} ${selectedExchange.name}`} diff --git a/src/components/Layer2ProductCard.tsx b/src/components/Layer2ProductCard.tsx index 5113ca7035d..d82e6089143 100644 --- a/src/components/Layer2ProductCard.tsx +++ b/src/components/Layer2ProductCard.tsx @@ -1,7 +1,7 @@ // Libraries import React from "react" import { GatsbyImage, IGatsbyImageData } from "gatsby-plugin-image" -import { useIntl } from "react-intl" +import { useTranslation } from "gatsby-plugin-react-i18next" import { Box, Center, Flex, Heading, Image, Text } from "@chakra-ui/react" // Components @@ -38,7 +38,7 @@ const Layer2ProductCard: React.FC = ({ tokenLists, ecosystemPortal, }) => { - const intl = useIntl() + const { t } = useTranslation() return ( = ({ {note.length > 0 && ( - {translateMessageId("layer-2-note", intl)} {note} + {t("layer-2-note")} {note} )} {bridge && ( - {name} {translateMessageId("layer-2-bridge", intl)} + {name} {t("layer-2-bridge")} )} {ecosystemPortal && ( - {name} {translateMessageId("layer-2-ecosystem-portal", intl)} + {name} {t("layer-2-ecosystem-portal")} )} {tokenLists && ( - {name} {translateMessageId("layer-2-token-lists", intl)} + {name} {t("layer-2-token-lists")} )} - {translateMessageId("layer-2-explore", intl)} {name} + {t("layer-2-explore")} {name} diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 73fd604fd44..911608a62cb 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -3,8 +3,6 @@ import { ApolloProvider } from "@apollo/client" import { useColorModeValue } from "@chakra-ui/react" import { ThemeProvider } from "@emotion/react" import styled from "@emotion/styled" -import { IntlProvider } from "react-intl" -import { LocaleProvider } from "gatsby-theme-i18n" import { lightTheme, darkTheme } from "../theme" @@ -93,7 +91,6 @@ const Layout: React.FC = ({ const [isZenMode, setIsZenMode] = useState(false) const [shouldShowSideNav, setShouldShowSideNav] = useState(false) const locale = pageContext.locale - const messages = require(`../intl/${locale}.json`) // Exit Zen Mode on 'esc' click useKeyPress(`Escape`, () => handleZenModeChange(false)) @@ -141,31 +138,35 @@ const Layout: React.FC = ({ !isTranslationBannerIgnored return ( - - {/* our current react-intl types does not support react 18 */} - {/* TODO: once we upgrade react-intl to v6, remove this ts-ignore */} - {/* @ts-ignore */} - - - - - - - + + + + + + + +