From f7c3644342bd9f7d260a1d1081c99cf2dc3408bb Mon Sep 17 00:00:00 2001 From: Ajay Kumbhare Date: Thu, 20 Jul 2023 21:45:32 +0530 Subject: [PATCH] refactor: add typeScript support to enforce valid translation keys (#6776) --- src/actions/actionExport.tsx | 10 +++++----- src/components/ColorPicker/PickerColorList.tsx | 8 ++++++-- src/components/ContextMenu.tsx | 10 +++++++--- src/components/Section.tsx | 2 +- src/components/Trans.test.tsx | 14 +++++++++----- src/components/Trans.tsx | 4 ++-- src/i18n.ts | 5 ++++- src/utility-types.ts | 4 ++++ 8 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/actions/actionExport.tsx b/src/actions/actionExport.tsx index d945ba95..2c94a986 100644 --- a/src/actions/actionExport.tsx +++ b/src/actions/actionExport.tsx @@ -65,7 +65,7 @@ export const actionChangeExportScale = register({ ); const scaleButtonTitle = `${t( - "buttons.scale", + "imageExportDialog.label.scale", )} ${s}x (${width}x${height})`; return ( @@ -102,7 +102,7 @@ export const actionChangeExportBackground = register({ checked={appState.exportBackground} onChange={(checked) => updateData(checked)} > - {t("labels.withBackground")} + {t("imageExportDialog.label.withBackground")} ), }); @@ -121,8 +121,8 @@ export const actionChangeExportEmbedScene = register({ checked={appState.exportEmbedScene} onChange={(checked) => updateData(checked)} > - {t("labels.exportEmbedScene")} - + {t("imageExportDialog.label.embedScene")} +
{questionCircle}
@@ -277,7 +277,7 @@ export const actionExportWithDarkMode = register({ onChange={(theme: Theme) => { updateData(theme === THEME.DARK); }} - title={t("labels.toggleExportColorScheme")} + title={t("imageExportDialog.label.darkMode")} /> ), diff --git a/src/components/ColorPicker/PickerColorList.tsx b/src/components/ColorPicker/PickerColorList.tsx index 2491afba..40f4bbeb 100644 --- a/src/components/ColorPicker/PickerColorList.tsx +++ b/src/components/ColorPicker/PickerColorList.tsx @@ -8,7 +8,7 @@ import { } from "./colorPickerUtils"; import HotkeyLabel from "./HotkeyLabel"; import { ColorPaletteCustom } from "../../colors"; -import { t } from "../../i18n"; +import { TranslationKeys, t } from "../../i18n"; interface PickerColorListProps { palette: ColorPaletteCustom; @@ -48,7 +48,11 @@ const PickerColorList = ({ (Array.isArray(value) ? value[activeShade] : value) || "transparent"; const keybinding = colorPickerHotkeyBindings[index]; - const label = t(`colors.${key.replace(/\d+/, "")}`, null, ""); + const label = t( + `colors.${key.replace(/\d+/, "")}` as unknown as TranslationKeys, + null, + "", + ); return (