From d310aa5382aad5826b4a1637fcc84f49b17d90f4 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 5 Jun 2024 09:12:41 -0500 Subject: [PATCH] Add i18n support with react-i18next --- package.json | 2 + public/locales/en/common.json | 35 ++++++++- src/components/Homepage/Hero.tsx | 21 +++-- src/pages/_app.tsx | 94 ++++++++++++----------- src/pages/dashboard/features/advanced.tsx | 8 +- src/pages/dashboard/features/chat.tsx | 8 +- src/pages/dashboard/features/index.tsx | 8 +- src/pages/dashboard/features/overlay.tsx | 8 +- src/pages/dashboard/index.tsx | 32 ++++---- src/pages/overlay/index.tsx | 8 +- 10 files changed, 135 insertions(+), 89 deletions(-) diff --git a/package.json b/package.json index 1887719e..379fcdb1 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "clsx": "^2.1.1", "focus-visible": "^5.2.0", "framer-motion": "^11.2.4", + "i18next": "^21.8.10", "lucide-react": "^0.378.0", "mantine-flagpack": "^4.0.1", "next": "14.2.3", @@ -50,6 +51,7 @@ "react-countdown": "^2.3.5", "react-countdown-circle-timer": "^3.2.1", "react-dom": "18.3.1", + "react-i18next": "^11.18.6", "react-redux": "^9.1.2", "redux": "^5.0.1", "redux-socket.io-middleware": "^1.0.4", diff --git a/public/locales/en/common.json b/public/locales/en/common.json index b6f2111f..c99c641c 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -4,5 +4,36 @@ "title": "Welcome, streamer", "description": "Unlock the Ultimate Dota 2 Streaming Experience with Dotabod! Boost your stream's engagement, showcase real-time stats, and delight your audience with our all-in-one streaming toolkit. Elevate your game and become the streamer you were meant to be!" }, - "live": "Live" -} \ No newline at end of file + "live": "Live", + "setup": { + "title": "Setup", + "subtitle": "Let's get Dotabod working for you right away", + "step1": "Twitch", + "step2": "Dota 2", + "step3": "OBS", + "step4": "All done!", + "finalNote": "That's it! You're all set up." + }, + "features": { + "main": { + "title": "Main features", + "subtitle": "Customize the options your stream receives." + }, + "chat": { + "title": "Chatter", + "subtitle": "The bot can post some random messages as you play your game." + }, + "advanced": { + "title": "Advanced features", + "subtitle": "Looking for even more? They'll be here 😎" + }, + "overlay": { + "title": "Overlay", + "subtitle": "This stuff will show up on your stream" + } + }, + "troubleshoot": { + "title": "Live preview", + "subtitle": "Take a peak to see if your OBS is showing the correct overlay. Try joining a bot match to have this preview show the pick blocker, for example." + } +} diff --git a/src/components/Homepage/Hero.tsx b/src/components/Homepage/Hero.tsx index 576c8d29..09ef7d13 100644 --- a/src/components/Homepage/Hero.tsx +++ b/src/components/Homepage/Hero.tsx @@ -12,6 +12,7 @@ import { CursorArrowRaysIcon } from '@heroicons/react/24/outline' import useSWR from 'swr' import { fetcher } from '@/lib/fetcher' import TwitchSvg from 'src/images/logos/twitch.svg' +import { useTranslation } from 'react-i18next'; const featuredUsers = [ { @@ -132,6 +133,7 @@ const TwitchUser = ({ } export function Hero() { + const { t } = useTranslation(); const session = useSession() const name = session.data?.user?.name || 'streamers' const { nonSupporters } = grouped @@ -147,7 +149,7 @@ export function Hero() {

- Welcome, {name} + {t('hero.title', 'Welcome, streamer')}

- Unlock the Ultimate Dota 2 Streaming Experience with Dotabod! - Boost your stream's engagement, showcase real-time stats, and - delight your audience with our all-in-one streaming toolkit. - Elevate your game and become the streamer you were meant to be! + {t('hero.description', "Unlock the Ultimate Dota 2 Streaming Experience with Dotabod! Boost your stream's engagement, showcase real-time stats, and delight your audience with our all-in-one streaming toolkit. Elevate your game and become the streamer you were meant to be!")}

@@ -167,9 +166,9 @@ export function Hero() {
{session?.status === 'authenticated' ? ( - Go to dashboard + {t('hero.dashboard', 'Go to dashboard')} ) : ( - Get started + {t('hero.getStarted', 'Get started')} )}
@@ -181,7 +180,7 @@ export function Hero() { >
discord - Join Discord + {t('hero.joinDiscord', 'Join Discord')}
@@ -211,7 +210,7 @@ export function Hero() { height={18} alt="twitch logo" /> - Featured in over 15,000 Twitch streamers + {t('hero.featuredStreamers', 'Featured in over 15,000 Twitch streamers')}