Skip to content

Commit

Permalink
Merge pull request #49 from angelod1as/i18n
Browse files Browse the repository at this point in the history
Add i18n functionalities, a major data overhaul
  • Loading branch information
angelod1as authored Jan 2, 2021
2 parents b000afa + 5a02090 commit fe31a57
Show file tree
Hide file tree
Showing 42 changed files with 588 additions and 150 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-explicit-any': 0,
'no-console': ['error', { allow: ['warn', 'error'] }],
'jsx-a11y/anchor-is-valid': [
'error',
{
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Current projects
1 change: 1 addition & 0 deletions getContentfulEnvironment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-console */
require('dotenv').config()
const contentfulManagement = require('contentful-management')

Expand Down
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ module.exports = {
},
]
},
i18n: {
locales: ['en', 'pt'],
defaultLocale: 'en',
},
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
"dependencies": {
"@contentful/rich-text-react-renderer": "^14.1.2",
"@contentful/rich-text-types": "^14.1.2",
"@types/uuid": "^8.3.0",
"contentful": "^7.15.0",
"contentful-management": "^7.3.0",
"contentful-typescript-codegen": "^3.2.1",
"dotenv": "^8.2.0",
"gray-matter": "^4.0.2",
"highlight.js": "^10.4.1",
"html-react-parser": "^0.14.2",
"i18next": "^19.8.4",
"nanoid": "^3.1.20",
"next": "10.0.2",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-i18next": "^11.8.5",
"react-icons": "^4.1.0",
"react-responsive-embed": "^2.1.0",
"remarkable": "^2.0.1",
Expand Down Expand Up @@ -57,6 +58,7 @@
"@types/node": "^14.14.9",
"@types/react": "^17.0.0",
"@types/styled-components": "^5.1.4",
"@types/uuid": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"@typescript-eslint/parser": "^4.8.2",
"babel-loader": "^8.2.2",
Expand Down
5 changes: 4 additions & 1 deletion src/components/atoms/Back/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useTranslation } from '@i18n/i18n'
import { useRouter } from 'next/router'
import { StyledBack } from './styles'

Expand All @@ -11,9 +12,11 @@ export interface BackProps {
*/
export const Back = ({ inverted }: BackProps) => {
const router = useRouter()
const t = useTranslation(router.locale)

return (
<StyledBack onClick={() => router.back()} {...{ inverted }}>
back
{t('back')}
</StyledBack>
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/atoms/Back/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ export const StyledBack = styled.button<BackProps>`
font-size: 16px;
line-height: 25px;
padding-left: 15px;
transition: padding 0.3s ease;
cursor: pointer;
color: ${p => (p.inverted ? p.theme.color.white : p.theme.color.black)};
&:before {
transition: left 0.3s ease;
content: '‹';
position: absolute;
left: 0;
}
&:hover {
padding-left: 12px;
&:before {
left: 4px;
content: '«';
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/components/atoms/BottomBar/HomeButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useRouter } from 'next/router'
import { StyledHome, Wrapper } from './styles'

export default function HomeButton() {
const { push, asPath } = useRouter()

if (asPath !== '/') {
return (
<Wrapper>
<StyledHome onClick={() => push('/')}>Home</StyledHome>
</Wrapper>
)
}
return <div />
}
33 changes: 33 additions & 0 deletions src/components/atoms/BottomBar/HomeButton/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import styled from 'styled-components'

export const Wrapper = styled.div`
display: flex;
justify-content: flex-start;
`

export const StyledHome = styled.button`
position: relative;
background-color: transparent;
border: none;
font-family: 'Montserrat', sans-serif;
font-weight: 700;
font-size: 16px;
line-height: 25px;
cursor: pointer;
text-transform: lowercase;
color: ${p => p.theme.color.black};
&:before {
transition: left 0.3s ease;
content: '‹';
position: absolute;
left: -8px;
}
&:hover {
&:before {
left: -4px;
content: '«';
}
}
`
44 changes: 44 additions & 0 deletions src/components/atoms/BottomBar/LocaleSwitcher/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useRouter } from 'next/router'
import { Dispatch, SetStateAction } from 'react'
import { BG, Flag, Switch, Slider } from './styles'

interface LocaleSwitcherProps {
setLoading: Dispatch<SetStateAction<boolean>>
}

export default function LocaleSwitcher({ setLoading }: LocaleSwitcherProps) {
const router = useRouter()

const { locales, locale, asPath } = router

const changeLanguage = () => {
setLoading(true)
const newLocale = locales.filter(each => each !== locale)[0]
router
.push(asPath, asPath, { locale: newLocale })
.then(() => setLoading(false))
}

return (
<BG>
<Flag>
<span role="img" aria-label="Portuguese">
🇧🇷
</span>
</Flag>
<Switch>
<input
type="checkbox"
onChange={changeLanguage}
checked={locale !== 'pt'}
/>
<Slider />
</Switch>
<Flag>
<span role="img" aria-label="English">
🇬🇧
</span>
</Flag>
</BG>
)
}
52 changes: 52 additions & 0 deletions src/components/atoms/BottomBar/LocaleSwitcher/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import styled from 'styled-components'

export const BG = styled.div`
display: flex;
padding: 15px 0;
justify-content: center;
`

export const Flag = styled.div`
cursor: pointer;
margin: 0 10px;
font-size: 20px;
transition: transform 0.2s ease;
`

export const Slider = styled.span`
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: 0.2s;
border-radius: 34px;
&:before {
position: absolute;
content: '';
height: 16px;
width: 16px;
left: 3px;
bottom: 2px;
background-color: white;
transition: 0.2s;
border-radius: 50%;
}
`

export const Switch = styled.label`
position: relative;
width: 40px;
input {
opacity: 0;
width: 0;
height: 0;
}
input:checked + ${Slider}:before {
transform: translateX(18px);
}
`
17 changes: 17 additions & 0 deletions src/components/atoms/BottomBar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Dispatch, SetStateAction } from 'react'
import LocaleSwitcher from './LocaleSwitcher'
import HomeButton from './HomeButton'
import { Wrapper } from './styles'

interface BottomBarProps {
setLoading: Dispatch<SetStateAction<boolean>>
}

export default function BottomBar({ setLoading }: BottomBarProps) {
return (
<Wrapper>
<HomeButton />
<LocaleSwitcher {...{ setLoading }} />
</Wrapper>
)
}
16 changes: 16 additions & 0 deletions src/components/atoms/BottomBar/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import styled from 'styled-components'

export const Wrapper = styled.div`
position: fixed;
bottom: 0;
left: 0;
z-index: 10;
width: 100%;
/* display: flex;
justify-content: space-between;
align-items: center; */
display: grid;
grid-template-columns: repeat(3, 1fr);
background-color: ${p => p.theme.color.white};
padding: 0 20px;
`
1 change: 1 addition & 0 deletions src/components/atoms/Embed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const DangerDiv = styled.div`
iframe {
width: 100%;
}
margin: 20px 0;
`

export default function Embed({ embed }: EmbedProps) {
Expand Down
5 changes: 4 additions & 1 deletion src/components/atoms/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import makeSafeDate from '@components/utils/makeSafeDate'
import { useRouter } from 'next/router'
import {
FooterWrapper,
BlogPosts,
Expand Down Expand Up @@ -28,6 +30,7 @@ export interface FooterProps {
* Page footer with latest blog posts, newsletter and social icons
*/
export const Footer = ({ blogPosts, newsletter, social }: FooterProps) => {
const { locale } = useRouter()
return (
<FooterWrapper>
{blogPosts?.length > 0 && (
Expand All @@ -40,7 +43,7 @@ export const Footer = ({ blogPosts, newsletter, social }: FooterProps) => {
<h4>{title}</h4>
<p>
{lead}
<span>{date}</span>
<span>{makeSafeDate(date, locale)}</span>
</p>
</Post>
))}
Expand Down
13 changes: 9 additions & 4 deletions src/components/atoms/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
ExcerptSubtitle,
ExcerptText,
} from './styles'
import { useRouter } from 'next/router'
import { useTranslation } from '@i18n/i18n'

export interface HeaderProps {
// Title
Expand Down Expand Up @@ -36,22 +38,25 @@ export const Header = ({
slug,
type,
}: HeaderProps) => {
const { locale } = useRouter()
const t = useTranslation(locale)

return (
<Container {...{ slim }}>
<BackWrapper {...{ slim }}>
<Back inverted />
</BackWrapper>
<Title {...{ slim }}>
{hasIDo && !slim && type && "I'm angelo and I do "}
{hasIDo && !slim && type && t("I'm angelo and I do ")}
<span>{type ? title.toLowerCase() : title}</span>
</Title>
{type && excerpt && !slim ? (
<ExcerptWrapper>
<ExcerptTitle>Time is short</ExcerptTitle>
<ExcerptSubtitle>Read this first</ExcerptSubtitle>
<ExcerptTitle>{t('Time is short')}</ExcerptTitle>
<ExcerptSubtitle>{t('Read this first')}</ExcerptSubtitle>
<ExcerptText>{excerpt}</ExcerptText>
<Button to={`${slug}/about`} inverted>
click to continue reading
{t('click to continue reading')}
</Button>
</ExcerptWrapper>
) : (
Expand Down
4 changes: 1 addition & 3 deletions src/components/atoms/InlineEmbed/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Project, { ImageProps } from '@components/atoms/Project'
import makeSafeDate from '@components/utils/makeSafeDate'

export default function InlineEmbed({
description,
Expand All @@ -8,11 +7,10 @@ export default function InlineEmbed({
coverImage,
date,
}) {
const newDate = new Date(date)
return (
<Project
title={title}
safeDate={makeSafeDate(newDate)}
date={date}
to={slug}
lead={description}
image={coverImage as ImageProps[]}
Expand Down
17 changes: 17 additions & 0 deletions src/components/atoms/Loading/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useTranslation } from '@i18n/i18n'
import { useRouter } from 'next/router'
import { Wrapper, Square, Word, BG } from './styles'

export default function Loading() {
const { locale } = useRouter()
const t = useTranslation(locale)

return (
<Wrapper>
<Word>{t('loading')}</Word>
<Square>
<BG />
</Square>
</Wrapper>
)
}
Loading

1 comment on commit fe31a57

@vercel
Copy link

@vercel vercel bot commented on fe31a57 Jan 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.