From bca465c594913ce245a0bdcb8a498f151b97485f Mon Sep 17 00:00:00 2001 From: Samuel Plumppu <6125097+Greenheart@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:40:47 +0200 Subject: [PATCH] Translate footer and add eslint rule to avoid import mistake --- .eslintrc.js | 6 ++++++ components/Footer/Footer.tsx | 19 +++++++++++-------- components/Footer/FooterNewsletterForm.tsx | 11 ++++++----- components/Footer/FooterSocialLinks.tsx | 6 ++++-- next-i18next.config.js | 4 +++- pages/[dataset]/[dataView]/index.tsx | 2 +- pages/[dataset]/index.tsx | 2 +- pages/index.tsx | 2 +- public/locales/sv/footer.json | 18 ++++++++++++++++++ 9 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 public/locales/sv/footer.json diff --git a/.eslintrc.js b/.eslintrc.js index 2fb8cda9..ce37830e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -32,5 +32,11 @@ module.exports = { 'import/no-extraneous-dependencies': 'off', // fixme revisit and refactor files when there's time to spare 'react/react-in-jsx-scope': 'off', 'react/jsx-one-expression-per-line': 'warn', + 'no-restricted-imports': ['error', { + paths: [{ + name: 'react-i18next', + message: 'Please import useTranslation from next-i18next.', + }], + }], }, } diff --git a/components/Footer/Footer.tsx b/components/Footer/Footer.tsx index 2a5b3580..2ddf99ec 100644 --- a/components/Footer/Footer.tsx +++ b/components/Footer/Footer.tsx @@ -1,4 +1,5 @@ import styled from 'styled-components' +import { useTranslation } from 'next-i18next' import { H5, Paragraph } from '../Typography' import { devices } from '../../utils/devices' import NewsletterSubscribe from './FooterNewsletterSubscribe' @@ -78,14 +79,16 @@ const SocialLinksContainer = styled.div` ` function Footer() { + const { t } = useTranslation(['common', 'footer']) + return ( <> - Med stöd från + {t('footer:supportedBy')} - Partners + {t('footer:partners')} @@ -93,28 +96,28 @@ function Footer() { - Klimatkollen är en medborgarplattform som tillgängliggör klimatdata + {t('footer:tagline')} - CC BY-SA - - {' '} + {t('footer:creative-commons.abbreviation')} + {' - '} - Attribution-ShareAlike 4.0 International license + {t('footer:creative-commons.license')} - Klimatkollen är utvecklad med + {t('footer:developedWith')} {' '} - öppen källkod + {t('footer:open-source')} diff --git a/components/Footer/FooterNewsletterForm.tsx b/components/Footer/FooterNewsletterForm.tsx index 40164d67..bbeaf28f 100644 --- a/components/Footer/FooterNewsletterForm.tsx +++ b/components/Footer/FooterNewsletterForm.tsx @@ -1,5 +1,6 @@ import { useState, FC, useEffect } from 'react' import styled from 'styled-components' +import { useTranslation } from 'next-i18next' import { EmailFormFields } from 'react-mailchimp-subscribe' import { H5, Paragraph } from '../Typography' import { devices } from '../../utils/devices' @@ -102,6 +103,7 @@ const NewsletterForm: FC = ({ status, onValidated }) => { const [error, setError] = useState('') const [email, setEmail] = useState('') const [showThanks, setThanks] = useState(false) + const { t } = useTranslation() useEffect(() => { if (status === 'success' || status === 'error') { @@ -129,24 +131,23 @@ const NewsletterForm: FC = ({ status, onValidated }) => { return ( -
Vill du få nyheter om Klimatkollen?
+
{t('footer:signup-form.title')}
- Med vårt nyhetsbrev får du uppdateringar om hur det går med utsläppen och - omställningen direkt i din mejl. + {t('footer:signup-form.info')}
{showThanks ? ( - Tack för ditt intresse! + {t('footer:signup-form.thanks')} ) : ( <> setEmail(event.target.value)} type="email" - placeholder="Ange mailadress" + placeholder={t('footer:signup-form.placeholder')} value={email} required disabled={showThanks} diff --git a/components/Footer/FooterSocialLinks.tsx b/components/Footer/FooterSocialLinks.tsx index cca96c33..e048e5c9 100644 --- a/components/Footer/FooterSocialLinks.tsx +++ b/components/Footer/FooterSocialLinks.tsx @@ -1,4 +1,5 @@ import styled from 'styled-components' +import { useTranslation } from 'next-i18next' import { devices } from '../../utils/devices' const ContactList = styled.ul` @@ -50,13 +51,14 @@ export function SocialListItem({ } function SocialList() { + const { t } = useTranslation() return ( permanent: true, }, props: { - ...await serverSideTranslations(locale as string, ['common']), + ...await serverSideTranslations(locale as string, ['common', 'footer']), }, } } diff --git a/public/locales/sv/footer.json b/public/locales/sv/footer.json new file mode 100644 index 00000000..6430424b --- /dev/null +++ b/public/locales/sv/footer.json @@ -0,0 +1,18 @@ +{ + "creative-commons": { + "abbreviation": "CC BY-SA", + "license": "Attribution-ShareAlike 4.0 International license" + }, + "developedWith": "Klimatkollen är utvecklad med", + "email-us": "Maila oss", + "open-source": "öppen källkod", + "partners": "Partners", + "signup-form": { + "info": "Med vårt nyhetsbrev får du uppdateringar om hur det går med utsläppen och omställningen direkt i din mejl.", + "placeholder": "Ange mailadress", + "thanks": "Tack för ditt intresse!", + "title": "Vill du få nyheter om Klimatkollen?" + }, + "supportedBy": "Med stöd från", + "tagline": "Klimatkollen är en medborgarplattform som tillgängliggör klimatdata" +}