From f80c8817dc37d963490c8168fdc9f13330f163a8 Mon Sep 17 00:00:00 2001 From: Carolina Menezes Date: Thu, 13 Apr 2023 17:14:56 -0300 Subject: [PATCH] feat(next.config.js): set up locales --- next.config.js | 5 +- package.json | 6 +- src/components/contributors/index.tsx | 13 +- .../documentation-section-card/index.tsx | 12 +- .../documentation-section/index.tsx | 11 +- src/components/dropdown-menu/index.tsx | 6 +- src/components/education-section/index.tsx | 73 +++-- src/components/feedback-modal/index.tsx | 15 +- src/components/feedback-section/index.tsx | 23 +- src/components/footer/index.tsx | 83 +++--- src/components/header/hamburger-menu.tsx | 6 +- src/components/header/index.tsx | 12 +- src/components/icons/vtex-devportal-icon.tsx | 38 --- src/components/icons/vtex-helpcenter-icon.tsx | 23 ++ src/components/last-updates-section/index.tsx | 8 +- .../markdown-renderer/components.tsx | 5 +- src/components/newsletter-section/index.tsx | 28 +- src/components/on-this-page/index.tsx | 8 +- src/components/release-note/functions.tsx | 10 +- src/components/release-section/index.tsx | 8 +- .../search-filter-tab-bar/index.tsx | 6 +- src/components/search-input/results-box.tsx | 10 +- src/components/search-input/search-box.tsx | 9 +- src/components/search-results/index.tsx | 4 +- src/components/search-sections/index.tsx | 6 +- src/components/see-also-section/functions.ts | 4 +- .../sidebar-section-filter/index.tsx | 9 +- src/components/sidebar-section/index.tsx | 4 +- src/components/sidebar/index.tsx | 6 +- src/messages/{language.json => en.json} | 22 +- src/messages/es.json | 94 +++++++ src/messages/pt.json | 94 +++++++ src/pages/_app.tsx | 43 +-- src/pages/docs/guides/index.tsx | 26 +- src/pages/updates/announcements/index.tsx | 16 +- src/utils/constants.ts | 264 +++++++++++------- src/utils/get-messages.tsx | 20 +- 37 files changed, 668 insertions(+), 362 deletions(-) delete mode 100644 src/components/icons/vtex-devportal-icon.tsx create mode 100644 src/components/icons/vtex-helpcenter-icon.tsx rename src/messages/{language.json => en.json} (86%) create mode 100644 src/messages/es.json create mode 100644 src/messages/pt.json diff --git a/next.config.js b/next.config.js index b11a64ad..21daae8c 100644 --- a/next.config.js +++ b/next.config.js @@ -35,7 +35,8 @@ const nextConfig = { return config }, env: { - navigationJsonUrl: 'https://developers.vtex.com/navigation.json', + navigationJsonUrl: + 'https://leafy-mooncake-7c2e5e.netlify.app/navigation.json', contentOrg: '', contentRepo: '', contentBranch: '', @@ -44,7 +45,7 @@ const nextConfig = { return [] }, i18n: { - locales: ['en'], + locales: ['en', 'pt', 'es'], defaultLocale: 'en', }, } diff --git a/package.json b/package.json index d69c5f39..1bd88417 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "devportal", - "version": "1.9.8", + "version": "1.9.6", "private": true, "engines": { "npm": "please-use-yarn", @@ -31,7 +31,8 @@ "algoliasearch": "^4.14.2", "chalk": "^5.2.0", "copy-text-to-clipboard": "^3.0.1", - "googleapis": "^39.2.0", + "google-auth-library": "^8.7.0", + "googleapis": "^117.0.0", "highlight.js": "^11.6.0", "highlightjs-curl": "^1.3.0", "http-proxy": "^1.18.1", @@ -52,6 +53,7 @@ "react-dom": "^18.2.0", "react-instantsearch-dom": "^6.37.0", "react-intersection-observer": "^9.2.2", + "react-intl": "^6.3.2", "react-markdown": "^8.0.3", "react-toastify": "^9.1.1", "rehype-highlight": "^5.0.2", diff --git a/src/components/contributors/index.tsx b/src/components/contributors/index.tsx index 021b1650..151ef7b5 100644 --- a/src/components/contributors/index.tsx +++ b/src/components/contributors/index.tsx @@ -2,8 +2,7 @@ import { useEffect, useLayoutEffect, useRef, useState } from 'react' import { Box, Flex, Grid, IconCaret, Text } from '@vtex/brand-ui' import Tooltip from 'components/tooltip' - -import { getMessages } from 'utils/get-messages' +import { useIntl } from 'react-intl' import styles from './styles' import { ContributorsType } from 'utils/getFileContributors' @@ -14,7 +13,7 @@ interface Props { } const Contributors = ({ contributors }: Props) => { - const messages = getMessages() + const intl = useIntl() const [showAll, setShowAll] = useState(false) const [pageWidth, setPageWidth] = useState(0) @@ -46,7 +45,9 @@ const Contributors = ({ contributors }: Props) => { - {messages['api_guide_documentation_page_contributors.title']} + {intl.formatMessage({ + id: 'api_guide_documentation_page_contributors.title', + })} {contributors.length} @@ -87,7 +88,9 @@ const Contributors = ({ contributors }: Props) => { > {showAll - ? messages['api_guide_documentation_page_contributors.toggleText'] + ? intl.formatMessage({ + id: 'api_guide_documentation_page_contributors.toggleText', + }) : `+ ${ contributors.length - minRows * photosPerRow } contributors`} diff --git a/src/components/documentation-section-card/index.tsx b/src/components/documentation-section-card/index.tsx index 21ee5d5e..312ff99f 100644 --- a/src/components/documentation-section-card/index.tsx +++ b/src/components/documentation-section-card/index.tsx @@ -1,11 +1,11 @@ import Link from 'next/link' import { Flex, Text } from '@vtex/brand-ui' -import { getMessages } from 'utils/get-messages' import type { DocDataElement } from 'utils/typings/types' import Tooltip from 'components/tooltip' import styles from './styles' import { useEffect, useRef, useState } from 'react' +import { useIntl } from 'react-intl' const DocumentationSectionCard = ({ Icon, @@ -13,7 +13,7 @@ const DocumentationSectionCard = ({ description, link, }: DocDataElement) => { - const messages = getMessages() + const intl = useIntl() const [tooltipState, setTooltipState] = useState(false) const [tooltipDescription, setTooltipDescription] = useState(description) const descriptionRef = useRef() @@ -57,11 +57,9 @@ const DocumentationSectionCard = ({ sx={styles.quickStartedContainer} > - { - messages[ - 'landing_page_documentation_documentation_card.learnMoreText' - ] - } + {intl.formatMessage({ + id: 'landing_page_documentation_documentation_card.learnMoreText', + })} diff --git a/src/components/documentation-section/index.tsx b/src/components/documentation-section/index.tsx index b68f1828..54c8d4d2 100644 --- a/src/components/documentation-section/index.tsx +++ b/src/components/documentation-section/index.tsx @@ -2,22 +2,25 @@ import { Box, Flex, Text } from '@vtex/brand-ui' import DocumentationSectionCard from '../documentation-section-card' -import { messages } from 'utils/constants' -import { documentationData as cards } from 'utils/constants' +import { documentationData } from 'utils/constants' import styles from './styles' +import { useIntl } from 'react-intl' const DocumentationSection = () => { + const intl = useIntl() return ( - {messages['landing_page_documentation.title']} + {intl.formatMessage({ + id: 'landing_page_documentation.title', + })} - {cards.map((card) => ( + {documentationData(intl).map((card) => ( ))} diff --git a/src/components/dropdown-menu/index.tsx b/src/components/dropdown-menu/index.tsx index 22fd0282..a5fbcd10 100644 --- a/src/components/dropdown-menu/index.tsx +++ b/src/components/dropdown-menu/index.tsx @@ -2,10 +2,12 @@ import { Box } from '@vtex/brand-ui' import DocumentationCard from 'components/documentation-card' import { documentationData, updatesData } from 'utils/constants' +import { useIntl } from 'react-intl' import styles from './styles' const DropdownMenu = () => { + const intl = useIntl() return ( @@ -13,7 +15,7 @@ const DropdownMenu = () => { sx={styles.documentationContainer} data-cy="dropdown-menu-first-section" > - {documentationData.map((card) => ( + {documentationData(intl).map((card) => ( { sx={styles.updatesContainer} data-cy="dropdown-menu-second-section" > - {updatesData.map((card) => ( + {updatesData(intl).map((card) => ( { + const intl = useIntl() + + const educationChannels = [ + { + title: intl.formatMessage({ id: 'landing_page_education_github.title' }), + description: intl.formatMessage({ + id: 'landing_page_education_github.description', + }), + textLink: intl.formatMessage({ + id: 'landing_page_education_github.textLink', + }), + link: getGithubURL(), + icon: GithubIcon, + }, + { + title: intl.formatMessage({ + id: 'landing_page_education_developer_portal.title', + }), + description: intl.formatMessage({ + id: 'landing_page_education_developer_portal.description', + }), + textLink: intl.formatMessage({ + id: 'landing_page_education_developer_portal.textLink', + }), + link: getHelpCenterURL(), + icon: HelpCenterIcon, + }, + { + title: intl.formatMessage({ + id: 'landing_page_education_community.title', + }), + description: intl.formatMessage({ + id: 'landing_page_education_community.description', + }), + textLink: intl.formatMessage({ + id: 'landing_page_education_community.textLink', + }), + link: getCommunityURL(), + icon: CommunityIcon, + }, + ] return ( - {messages['landing_page_education.title']} + + {intl.formatMessage({ id: 'landing_page_education.title' })} + {educationChannels.map((channel) => ( { return ( () const { body, documentElement } = document const [comment, setComment] = useState('') + const intl = useIntl() const closeModal = () => { const feedback = modalState?.liked @@ -91,7 +90,11 @@ const FeedBackModal = ({ } data-cy="feedback-modal" > - {messages['feedback_modal.title']} + + {intl.formatMessage({ + id: 'feedback_modal.title', + })} +