From 2b6364478b856dc365f1280ef8b9b8c1e8d4a5bf Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 5 Mar 2023 09:45:41 +0100 Subject: [PATCH] refactor: Improve i18n for settings alias preferences --- public/locales/en-US/common.json | 3 +- .../locales/en-US/settings-preferences.json | 5 ++ public/locales/en-US/settings.json | 7 +++ public/locales/en-US/translation.json | 8 --- src/routes/SettingsAliasPreferencesRoute.tsx | 52 ++++++++----------- src/routes/SettingsRoute.tsx | 8 +-- 6 files changed, 41 insertions(+), 42 deletions(-) create mode 100644 public/locales/en-US/settings-preferences.json create mode 100644 public/locales/en-US/settings.json diff --git a/public/locales/en-US/common.json b/public/locales/en-US/common.json index 542e80e..c80c4b9 100644 --- a/public/locales/en-US/common.json +++ b/public/locales/en-US/common.json @@ -52,7 +52,8 @@ "yesLabel": "Yes", "noLabel": "No", "continueLabel": "Continue", - "unavailableValue": "Unavailable" + "unavailableValue": "Unavailable", + "experimentalFeatureExplanation": "This is an experimental feature." }, "noSearchResults": { "title": "Nothing found", diff --git a/public/locales/en-US/settings-preferences.json b/public/locales/en-US/settings-preferences.json new file mode 100644 index 0000000..fe30a4e --- /dev/null +++ b/public/locales/en-US/settings-preferences.json @@ -0,0 +1,5 @@ +{ + "title": "Alias Preferences", + "description": "Select default values for your aliases. This only affects aliases you haven't set a custom value for.", + "continueActionLabel": "Save preferences" +} diff --git a/public/locales/en-US/settings.json b/public/locales/en-US/settings.json new file mode 100644 index 0000000..7ab1855 --- /dev/null +++ b/public/locales/en-US/settings.json @@ -0,0 +1,7 @@ +{ + "title": "Settings", + "actions": { + "enable2fa": "Two-Factor-Authentication", + "aliasPreferences": "Alias Preferences" + } +} diff --git a/public/locales/en-US/translation.json b/public/locales/en-US/translation.json index b1128ab..d148f42 100644 --- a/public/locales/en-US/translation.json +++ b/public/locales/en-US/translation.json @@ -90,18 +90,10 @@ } }, "SettingsRoute": { - "title": "Settings", "forms": { "aliasPreferences": { - "title": "Alias Preferences", - "description": "Select default values for your aliases. This only affects aliases you haven't set a custom value for.", - "saveAction": "Save preferences" } }, - "actions": { - "enable2fa": "Two-Factor-Authentication", - "aliasPreferences": "Alias Preferences" - }, "2fa": { "title": "Two-Factor-Authentication", "alreadyEnabled": "You have successfully enabled 2FA!", diff --git a/src/routes/SettingsAliasPreferencesRoute.tsx b/src/routes/SettingsAliasPreferencesRoute.tsx index e8dd998..eb1609b 100644 --- a/src/routes/SettingsAliasPreferencesRoute.tsx +++ b/src/routes/SettingsAliasPreferencesRoute.tsx @@ -44,30 +44,26 @@ interface Form { } export default function SettingsAliasPreferencesRoute(): ReactElement { + const {t} = useTranslation(["aliases", "settings-preferences", "common"]) const {_updateUser} = useContext(AuthContext) const user = useUser() const {showError, showSuccess} = useErrorSuccessSnacks() - const {t} = useTranslation() const schema = yup.object().shape({ - removeTrackers: yup.boolean().label(t("relations.alias.settings.removeTrackers.label")), - createMailReport: yup - .boolean() - .label(t("relations.alias.settings.createMailReports.label")), - proxyImages: yup.boolean().label(t("relations.alias.settings.proxyImages.label")), + removeTrackers: yup.boolean().label(t("settings.fields.removeTrackers.label")), + createMailReport: yup.boolean().label(t("settings.fields.createMailReport.label")), + proxyImages: yup.boolean().label(t("settings.fields.proxyImages.label")), imageProxyFormat: yup .mixed() .oneOf(Object.values(ImageProxyFormatType)) .required() - .label(t("relations.alias.settings.imageProxyFormat.label")), + .label(t("settings.fields.imageProxyFormat.label")), proxyUserAgent: yup .mixed() .oneOf(Object.values(ProxyUserAgentType)) .required() - .label(t("relations.alias.settings.proxyUserAgent.label")), - expandUrlShorteners: yup - .boolean() - .label(t("relations.alias.settings.expandUrlShorteners.label")), + .label(t("settings.fields.proxyUserAgent.label")), + expandUrlShorteners: yup.boolean().label(t("settings.fields.expandUrlShorteners.label")), }) const {mutateAsync} = useMutation( @@ -121,8 +117,8 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { return (
} labelPlacement="start" - label={t("relations.alias.settings.removeTrackers.label")} + label={t("settings.fields.removeTrackers.label")} /> {(formik.touched.createMailReport && formik.errors.createMailReport) || - t("relations.alias.settings.removeTrackers.helperText")} + t("settings.fields.removeTrackers.helperText")} @@ -174,7 +170,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { /> } labelPlacement="start" - label={t("relations.alias.settings.createMailReports.label")} + label={t("settings.fields.createMailReport.label")} /> {(formik.touched.createMailReport && formik.errors.createMailReport) || - t("relations.alias.settings.createMailReports.helperText")} + t("settings.fields.createMailReport.helperText")} @@ -202,7 +198,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { /> } labelPlacement="start" - label={t("relations.alias.settings.proxyImages.label")} + label={t("settings.fields.proxyImages.label")} /> {(formik.touched.proxyImages && formik.errors.proxyImages) || - t("relations.alias.settings.proxyImages.helperText")} + t("settings.fields.proxyImages.helperText")} - {t("general.experimentalFeature")} + {t("general.experimentalFeatureExplanation", {ns: "common"})} @@ -242,9 +238,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { }} name="imageProxyFormat" id="imageProxyFormat" - label={t( - "relations.alias.settings.imageProxyFormat.label", - )} + label={t("settings.fields.imageProxyFormat.label")} value={formik.values.imageProxyFormat} onChange={formik.handleChange} disabled={formik.isSubmitting} @@ -286,7 +280,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { select name="proxyUserAgent" id="proxyUserAgent" - label={t("relations.alias.settings.proxyUserAgent.label")} + label={t("settings.fields.proxyUserAgent.label")} value={formik.values.proxyUserAgent} onChange={formik.handleChange} disabled={formik.isSubmitting} @@ -312,7 +306,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { )} > {(formik.touched.proxyUserAgent && formik.errors.proxyUserAgent) || - t("relations.alias.settings.proxyUserAgent.helperText")} + t("settings.fields.proxyUserAgent.helperText")} @@ -330,7 +324,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { /> } labelPlacement="start" - label={t("relations.alias.settings.expandUrlShorteners.label")} + label={t("settings.fields.expandUrlShorteners.label")} /> {(formik.touched.expandUrlShorteners && formik.errors.expandUrlShorteners) || - t("relations.alias.settings.expandUrlShorteners.helperText")} + t("settings.fields.expandUrlShorteners.helperText")} - {t("general.experimentalFeature")} + {t("general.experimentalFeatureExplanation", {ns: "common"})} @@ -357,7 +351,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { type="submit" startIcon={} > - {t("routes.SettingsRoute.forms.aliasPreferences.saveAction")} + {t("continueActionLabel", {ns: "settings-preferences"})}
diff --git a/src/routes/SettingsRoute.tsx b/src/routes/SettingsRoute.tsx index f3e7b27..bb0b06e 100644 --- a/src/routes/SettingsRoute.tsx +++ b/src/routes/SettingsRoute.tsx @@ -9,22 +9,22 @@ import {List, ListItemButton, ListItemIcon, ListItemText} from "@mui/material" import {SimplePageBuilder} from "~/components" export default function SettingsRoute(): ReactElement { - const {t} = useTranslation() + const {t} = useTranslation("settings") return ( - + - + - +