From 031f6692bf6b92ebc6fbfcae13b9a89a79a8107f Mon Sep 17 00:00:00 2001 From: Ash Keel Date: Fri, 16 Dec 2022 14:51:42 +0100 Subject: [PATCH] feat: language selector works! --- frontend/src/locale/en/translation.json | 11 +-- frontend/src/ui/App.tsx | 12 ++- frontend/src/ui/components/PageList.tsx | 4 +- .../src/ui/components/forms/RadioGroup.tsx | 73 +++++++++++++++---- frontend/src/ui/pages/TwitchSettings.tsx | 4 +- frontend/src/ui/pages/UISettingsPage.tsx | 18 +++-- frontend/src/ui/theme/theme.ts | 3 + 7 files changed, 94 insertions(+), 31 deletions(-) diff --git a/frontend/src/locale/en/translation.json b/frontend/src/locale/en/translation.json index 369cefa..698d9fd 100644 --- a/frontend/src/locale/en/translation.json +++ b/frontend/src/locale/en/translation.json @@ -58,7 +58,6 @@ "apiguide-1": "You will need to create an application, here's how:", "apiguide-2": "Go to <1>https://dev.twitch.tv/console/apps/create", "apiguide-3": "Use the following data for the required fields:", - "oauth-redir-uri": "OAuth Redirect URLs", "apiguide-4": "Once made, create a <1>New Secret, then copy both fields below and save!", "app-client-id": "App Client ID", "app-client-secret": "App Client Secret", @@ -94,7 +93,9 @@ "auth-button": "Authenticate with Twitch", "auth-message": "Click the following button to authenticate {{APPNAME}} with your Twitch account:", "current-status": "Current status" - } + }, + "app-category": "Category", + "app-oauth-redirect-url": "OAuth Redirect URLs" }, "botcommands": { "title": "Bot commands", @@ -171,7 +172,7 @@ "enable": "Enable loyalty system", "currency-placeholder": "points", "currency-name": "Currency name", - "currency-name-hint": "This will be appended like this: \"user has X yourcurrency\" so choose a lowercase plural name", + "currency-name-hint": "This will be appended like this: \"user has X yourcurrency\" so choose a lowercase plural name (ex. points)", "bonus-points": "Bonus points for active users", "bonus-points-hint": "Extra amount of points awarded to people who have been chatting in the last set interval", "note": "Note: Unlike platform-native systems (eg. Twitch channel points), this relies on chat activity rather than actual viewing status.", @@ -223,12 +224,12 @@ "reward-desc": "Description", "reward-cost": "Cost", "reward-id-hint": "This is what viewers will have to write to claim, ie. \"!redeem reward-id-here\".", - "reward-name-hint": "This is what viewers will see they claimed ie. \"USER has claimed REWARDNAME", + "reward-name-hint": "This is what viewers will see they claimed ie. \"USER has claimed REWARDNAME\"", "reward-cooldown": "Cooldown", "reward-details-placeholder": "What extra details to ask the viewer for", "reward-details": "Require viewer details", "edit-reward": "Edit reward", - "remove-reward-title": "Remore reward \"{{name}}\"?", + "remove-reward-title": "Remove reward \"{{name}}\"?", "no-rewards": "There are no loyalty rewards, why not start with an Hydrate or Stretch?", "no-goals": "There are no goals configured", "create-goal": "Create goal", diff --git a/frontend/src/ui/App.tsx b/frontend/src/ui/App.tsx index c440727..01ed0c8 100644 --- a/frontend/src/ui/App.tsx +++ b/frontend/src/ui/App.tsx @@ -10,7 +10,7 @@ import { TimerIcon, } from '@radix-ui/react-icons'; import { EventsOff, EventsOn } from '@wailsapp/runtime/runtime'; -import { t } from 'i18next'; +import { useTranslation } from 'react-i18next'; import React, { useEffect, useState } from 'react'; import { Route, Routes, useLocation, useNavigate } from 'react-router-dom'; @@ -172,6 +172,7 @@ export default function App(): JSX.Element { const dispatch = useAppDispatch(); const location = useLocation(); const navigate = useNavigate(); + const [t, i18n] = useTranslation(); const connectToKV = async () => { const address = await GetKilovoltBind(); @@ -217,12 +218,15 @@ export default function App(): JSX.Element { } }, [ready, connected]); - const onboardingDone = uiConfig?.onboardingDone; + // Sync UI changes on key change useEffect(() => { - if (!onboardingDone) { + if (uiConfig?.language) { + void i18n.changeLanguage(uiConfig?.language ?? 'en'); + } + if (!uiConfig?.onboardingDone) { navigate('/setup'); } - }, [ready, onboardingDone]); + }, [ready, uiConfig]); if (connected === ConnectionStatus.NotConnected) { return ; diff --git a/frontend/src/ui/components/PageList.tsx b/frontend/src/ui/components/PageList.tsx index 30d01d9..6fd305c 100644 --- a/frontend/src/ui/components/PageList.tsx +++ b/frontend/src/ui/components/PageList.tsx @@ -86,7 +86,9 @@ function PageList({ -
{t('pagination.page')}
+
+ {t('pagination.page', { page: current })} +
{current > min ? ( + {props.values.map(({ id, label }) => (
- - - + + +
))} - +
); } diff --git a/frontend/src/ui/pages/TwitchSettings.tsx b/frontend/src/ui/pages/TwitchSettings.tsx index ce3a4ec..6cfa61d 100644 --- a/frontend/src/ui/pages/TwitchSettings.tsx +++ b/frontend/src/ui/pages/TwitchSettings.tsx @@ -230,12 +230,12 @@ function TwitchAPISettings() { 0 ? httpConfig.bind : `localhost${httpConfig?.bind ?? ':4337'}` }/twitch/callback`, - Category: 'Broadcasting Suite', + [t('pages.twitch-settings.app-category')]: 'Broadcasting Suite', }} /> diff --git a/frontend/src/ui/pages/UISettingsPage.tsx b/frontend/src/ui/pages/UISettingsPage.tsx index a3a10ac..4dec393 100644 --- a/frontend/src/ui/pages/UISettingsPage.tsx +++ b/frontend/src/ui/pages/UISettingsPage.tsx @@ -12,8 +12,13 @@ import { PageContainer, PageHeader, PageTitle, + styled, } from '../theme'; +const PartialWarning = styled('small', { + color: '$yellow11', +}); + export default function UISettingsPage(): React.ReactElement { const [uiConfig, setUiConfig] = useModule(modules.uiConfig); const [t, i18n] = useTranslation(); @@ -32,20 +37,23 @@ export default function UISettingsPage(): React.ReactElement { { + void dispatch(setUiConfig({ ...uiConfig, language: value })); + }} values={languages.map((lang) => ({ id: lang.code, label: ( {lang.name}{' '} {lang.keys < maxKeys ? ( - + {t('pages.uiconfig.partial-translation')} ( {((lang.keys / maxKeys) * 100).toFixed(1)}% - {lang.keys}/ {maxKeys}) - + ) : null} ), diff --git a/frontend/src/ui/theme/theme.ts b/frontend/src/ui/theme/theme.ts index efee80d..dbfb8fd 100644 --- a/frontend/src/ui/theme/theme.ts +++ b/frontend/src/ui/theme/theme.ts @@ -25,6 +25,9 @@ export const globalStyles = globalCss({ color: '$teal11', }, }, + p: { + lineHeight: 1.5, + }, }); export const { styled, theme } = createStitches({