From e41825a61417b39a3ce74d6f83a00ba673313593 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 5 Mar 2023 11:26:38 +0100 Subject: [PATCH] refactor: Improve i18n for decryption --- public/locales/en-US/common.json | 17 ++++- public/locales/en-US/decryption.json | 21 ++++++ public/locales/en-US/translation.json | 64 ------------------- .../DecryptionPasswordMissingAlert.tsx | 20 ++---- .../AuthenticateRoute/NavigationButton.tsx | 12 ++-- src/routes/AuthenticateRoute.tsx | 6 +- src/routes/AuthenticatedRoute.tsx | 4 +- src/routes/EnterDecryptionPassword.tsx | 21 +++--- 8 files changed, 63 insertions(+), 102 deletions(-) create mode 100644 public/locales/en-US/decryption.json diff --git a/public/locales/en-US/common.json b/public/locales/en-US/common.json index 242d6e4..4c0504a 100644 --- a/public/locales/en-US/common.json +++ b/public/locales/en-US/common.json @@ -19,7 +19,10 @@ }, "password": { "label": "Password", - "placeholder": "********" + "placeholder": "********", + "errors": { + "invalid": "Password is invalid." + } }, "passwordConfirmation": { "label": "Confirm Password", @@ -70,5 +73,17 @@ "noSearchResults": { "title": "Nothing found", "description": "We couldn't find anything for your search query. Try again with a different query." + }, + "navigation": { + "overview": "Overview", + "aliases": "Aliases", + "reports": "Reports", + "settings": "Settings", + "admin": "Admin" + }, + "routes": { + "signup": "Sign up", + "login": "Log in", + "logout": "Log out" } } diff --git a/public/locales/en-US/decryption.json b/public/locales/en-US/decryption.json new file mode 100644 index 0000000..5a2147e --- /dev/null +++ b/public/locales/en-US/decryption.json @@ -0,0 +1,21 @@ +{ + "actions": { + "enterDecryptionPassword": { + "title": "Decrypt Reports", + "description": "Please enter your password so that your reports can de decrypted.", + "cancelActionLabel": "Decrypt later" + }, + "passwordMissing": { + "unavailable": { + "title": "Encryption required", + "description": "You need to set up encryption to use this feature.", + "continueActionLabel": "Set up encryption" + }, + "passwordRequired": { + "title": "Password required", + "description": "Your decryption password is required to view this section.", + "continueActionLabel": "Enter password" + } + } + } +} diff --git a/public/locales/en-US/translation.json b/public/locales/en-US/translation.json index 3ade83d..0f28243 100644 --- a/public/locales/en-US/translation.json +++ b/public/locales/en-US/translation.json @@ -21,61 +21,13 @@ "appError": "We are sorry but there was an error. Please try again later." }, - "routes": { - "OverviewRoute": { - "title": "Overview", - "description": "Not much to see here, yet." - } - }, - "components": { - "NavigationButton": { - "overview": "Overview", - "aliases": "Aliases", - "reports": "Reports", - "settings": "Settings", - "admin": "Admin" - }, - "AuthenticateRoute": { - "signup": "Sign up", - "login": "Log in" - }, - "AuthenticatedRoute": { - "logout": "Logout" - }, - "EnterDecryptionPassword": { - "title": "Decrypt Reports", - "description": "Please enter your password so that your reports can de decrypted.", - "cancelAction": "Decrypt later", - "continueAction": "Continue", - "form": { - "password": { - "label": "Password", - "placeholder": "********", - "errors": { - "invalidPassword": "Password is invalid" - } - } - } - }, "ResendMailButton": { "label": "Resend Mail" }, "OpenMailButton": { "label": "Open Mail" }, - "DecryptionPasswordMissingAlert": { - "unavailable": { - "title": "Encryption required", - "description": "You need to set up encryption to use this feature.", - "continueAction": "Set up encryption" - }, - "passwordRequired": { - "title": "Password required", - "description": "Your decryption password is required to view this section.", - "continueAction": "Enter password" - } - }, "TimedButton": { "remainingTime_one": "({{count}})", "remainingTime_other": "({{count}})" @@ -111,20 +63,4 @@ } } }, - - "relations": { - "alias": { - "mutations": { - "success": { - "aliasCreation": "Created Alias successfully!", - "aliasUpdated": "Updated Alias successfully!", - "notesUpdated": "Updated & encrypted notes successfully!", - "aliasChangedToEnabled": "Alias has been enabled", - "aliasChangedToDisabled": "Alias has been disabled", - "addressCopiedToClipboard": "Address has been copied to your clipboard!", - "aliasDeleted": "Alias has been deleted!" - } - } - }, - } } diff --git a/src/components/widgets/DecryptionPasswordMissingAlert.tsx b/src/components/widgets/DecryptionPasswordMissingAlert.tsx index be8b59b..13ac737 100644 --- a/src/components/widgets/DecryptionPasswordMissingAlert.tsx +++ b/src/components/widgets/DecryptionPasswordMissingAlert.tsx @@ -15,7 +15,7 @@ export interface WithEncryptionRequiredProps { export default function DecryptionPasswordMissingAlert({ children = <>, }: WithEncryptionRequiredProps): JSX.Element { - const {t} = useTranslation() + const {t} = useTranslation("decryption") const {handleAnchorClick} = useContext(LockNavigationContext) const {encryptionStatus} = useContext(AuthContext) const theme = useTheme() @@ -33,12 +33,12 @@ export default function DecryptionPasswordMissingAlert({ > - {t("components.DecryptionPasswordMissingAlert.unavailable.title")} + {t("actions.passwordMissing.unavailable.title")} - {t("components.DecryptionPasswordMissingAlert.unavailable.description")} + {t("actions.passwordMissing.unavailable.description")} @@ -49,9 +49,7 @@ export default function DecryptionPasswordMissingAlert({ startIcon={} onClick={handleAnchorClick} > - {t( - "components.DecryptionPasswordMissingAlert.unavailable.continueAction", - )} + {t("actions.passwordMissing.unavailable.continueActionLabel")} @@ -70,14 +68,12 @@ export default function DecryptionPasswordMissingAlert({ > - {t("components.DecryptionPasswordMissingAlert.passwordRequired.title")} + {t("actions.passwordMissing.passwordRequired.title")} - {t( - "components.DecryptionPasswordMissingAlert.passwordRequired.description", - )} + {t("actions.passwordMissing.passwordRequired.description")} @@ -87,9 +83,7 @@ export default function DecryptionPasswordMissingAlert({ startIcon={} onClick={handleAnchorClick} > - {t( - "components.DecryptionPasswordMissingAlert.passwordRequired.continueAction", - )} + {t("actions.passwordMissing.passwordRequired.continueActionLabel")} diff --git a/src/route-widgets/AuthenticateRoute/NavigationButton.tsx b/src/route-widgets/AuthenticateRoute/NavigationButton.tsx index f7666ab..406cc13 100644 --- a/src/route-widgets/AuthenticateRoute/NavigationButton.tsx +++ b/src/route-widgets/AuthenticateRoute/NavigationButton.tsx @@ -30,11 +30,11 @@ const SECTION_ICON_MAP: Record = { } const SECTION_TEXT_MAP: Record = { - [NavigationSection.Overview]: "components.NavigationButton.overview", - [NavigationSection.Aliases]: "components.NavigationButton.aliases", - [NavigationSection.Reports]: "components.NavigationButton.reports", - [NavigationSection.Settings]: "components.NavigationButton.settings", - [NavigationSection.Admin]: "components.NavigationButton.admin", + [NavigationSection.Overview]: "navigation.overview", + [NavigationSection.Aliases]: "navigation.aliases", + [NavigationSection.Reports]: "navigation.reports", + [NavigationSection.Settings]: "navigation.settings", + [NavigationSection.Admin]: "navigation.admin", } const PATH_SECTION_MAP: Record = { @@ -46,7 +46,7 @@ const PATH_SECTION_MAP: Record = { } export default function NavigationButton({section}: NavigationButtonProps): ReactElement { - const {t} = useTranslation() + const {t} = useTranslation("common") const {handleAnchorClick} = useContext(LockNavigationContext) const location = useLocation() diff --git a/src/routes/AuthenticateRoute.tsx b/src/routes/AuthenticateRoute.tsx index 2bd1787..d75d2c5 100644 --- a/src/routes/AuthenticateRoute.tsx +++ b/src/routes/AuthenticateRoute.tsx @@ -8,7 +8,7 @@ import {Box, Button, Grid} from "@mui/material" import {LanguageButton} from "~/components" export default function AuthenticateRoute(): ReactElement { - const {t} = useTranslation() + const {t} = useTranslation("common") return ( } > - {t("components.AuthenticateRoute.signup")} + {t("routes.signup")} @@ -46,7 +46,7 @@ export default function AuthenticateRoute(): ReactElement { size="small" startIcon={} > - {t("components.AuthenticateRoute.login")} + {t("routes.login")} diff --git a/src/routes/AuthenticatedRoute.tsx b/src/routes/AuthenticatedRoute.tsx index f04ca7c..fb25b95 100644 --- a/src/routes/AuthenticatedRoute.tsx +++ b/src/routes/AuthenticatedRoute.tsx @@ -12,7 +12,7 @@ import NavigationButton, { } from "~/route-widgets/AuthenticateRoute/NavigationButton" export default function AuthenticatedRoute(): ReactElement { - const {t} = useTranslation() + const {t} = useTranslation("common") const theme = useTheme() const user = useUser() @@ -90,7 +90,7 @@ export default function AuthenticatedRoute(): ReactElement { to="/auth/logout" startIcon={} > - {t("components.AuthenticatedRoute.logout")} + {t("routes.logout")} diff --git a/src/routes/EnterDecryptionPassword.tsx b/src/routes/EnterDecryptionPassword.tsx index 5ff8445..17c10a1 100644 --- a/src/routes/EnterDecryptionPassword.tsx +++ b/src/routes/EnterDecryptionPassword.tsx @@ -17,7 +17,7 @@ interface Form { } export default function EnterDecryptionPassword(): ReactElement { - const {t} = useTranslation() + const {t} = useTranslation(["decryption", "common"]) const navigate = useNavigate() const navigateToNext = useNavigateToNext() const user = useUser() @@ -29,7 +29,7 @@ export default function EnterDecryptionPassword(): ReactElement { password: yup .string() .required() - .label(t("components.EnterDecryptionPassword.form.password.label")), + .label(t("fields.password.label", {ns: "common"})), }) const formik = useFormik
({ @@ -46,9 +46,7 @@ export default function EnterDecryptionPassword(): ReactElement { } catch (error) { // Password is incorrect setErrors({ - password: t( - "components.EnterDecryptionPassword.form.password.errors.invalidPassword", - ), + password: t("fields.password.errors,invalid", {ns: "common"}), }) } }, @@ -67,10 +65,9 @@ export default function EnterDecryptionPassword(): ReactElement { return ( @@ -81,10 +78,8 @@ export default function EnterDecryptionPassword(): ReactElement { autoFocus name="password" id="password" - label={t("components.EnterDecryptionPassword.form.password.label")} - placeholder={t( - "components.EnterDecryptionPassword.form.password.placeholder", - )} + label={t("fields.password.label", {ns: "common"})} + placeholder={t("fields.password.placeholder", {ns: "common"})} value={formik.values.password} onChange={formik.handleChange} disabled={formik.isSubmitting}