From 067e99926ab6a49bb2b14452d23a21aae47f700f Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 5 Mar 2023 15:19:21 +0100 Subject: [PATCH] fix: Fix languages --- public/locales/de-DE/aliases.json | 2 +- public/locales/de-DE/login.json | 2 +- public/locales/de-DE/settings.json | 2 +- src/components/widgets/AliasTypeIndicator.tsx | 9 +++++--- src/constants/enum-mappings.ts | 11 --------- .../AliasDetailRoute/AliasPreferencesForm.tsx | 23 ++++++++++--------- .../AliasDetailRoute/SelectField.tsx | 12 +++++----- src/routes/ReportDetailRoute.tsx | 2 +- src/routes/ReportsRoute.tsx | 13 ++++++----- src/routes/SettingsAliasPreferencesRoute.tsx | 19 +++++++++------ src/utils/create-enum-map-from-translation.ts | 12 ++++++---- 11 files changed, 54 insertions(+), 53 deletions(-) delete mode 100644 src/constants/enum-mappings.ts diff --git a/public/locales/de-DE/aliases.json b/public/locales/de-DE/aliases.json index 4391d5a..bd677e6 100644 --- a/public/locales/de-DE/aliases.json +++ b/public/locales/de-DE/aliases.json @@ -66,7 +66,7 @@ }, "proxyUserAgent": { "label": "Weiterleitungs-User-Agent", - "helperText": "Ein User Agent ist ein Identifikator, den jeder Browser und E-Mail-Client beim Abrufen von Dateien, wie z.B. Bildern, sendet. Du kannst hier angeben, welcher User Agent verwendet werden soll, wenn wir deine Bilder weiterleiten. User Agents werden auf dem neuesten Stand gehalten." + "helperText": "Ein User Agent ist ein Identifikator, den jeder Browser und E-Mail-Client beim Abrufen von Dateien, wie z.B. Bildern, sendet. Du kannst hier angeben, welcher User Agent verwendet werden soll, wenn wir deine Bilder weiterleiten. User Agents werden auf dem neuesten Stand gehalten.", "values": { "apple-mail": "Apple Mail", "google-mail": "Google Mail", diff --git a/public/locales/de-DE/login.json b/public/locales/de-DE/login.json index 9b4c685..f910fe0 100644 --- a/public/locales/de-DE/login.json +++ b/public/locales/de-DE/login.json @@ -15,7 +15,7 @@ "code": { "label": "Anmelde-Code", "errors": { - "invalidChars": "Der Anmelde-Code ist ungültig", + "invalidChars": "Der Anmelde-Code ist ungültig" } } } diff --git a/public/locales/de-DE/settings.json b/public/locales/de-DE/settings.json index 48da686..bc710ff 100644 --- a/public/locales/de-DE/settings.json +++ b/public/locales/de-DE/settings.json @@ -2,6 +2,6 @@ "title": "Einstellungen", "actions": { "enable2fa": "Zwei-Faktor-Authentifizierung", - "aliasPreferences": "Alias Präferenzen" + "aliasPreferences": "Alias-Präferenzen" } } diff --git a/src/components/widgets/AliasTypeIndicator.tsx b/src/components/widgets/AliasTypeIndicator.tsx index 4a4b709..52ea6a9 100644 --- a/src/components/widgets/AliasTypeIndicator.tsx +++ b/src/components/widgets/AliasTypeIndicator.tsx @@ -16,14 +16,17 @@ export const ALIAS_TYPE_ICON_MAP: Record = { [AliasType.CUSTOM]: , } -const ALIAS_TYPE_TOOLTIP_MAP = createEnumMapFromTranslation("aliasTypeExplanation", AliasType) - export default function AliasTypeIndicator({type}: AliasTypeIndicatorProps): ReactElement { const {t} = useTranslation("aliases") + const aliasTypeTooltipMap = createEnumMapFromTranslation( + "aliasTypeExplanation", + AliasType, + )(key => t(key)) + return ( // @ts-ignore - + {ALIAS_TYPE_ICON_MAP[type]} diff --git a/src/constants/enum-mappings.ts b/src/constants/enum-mappings.ts deleted file mode 100644 index 1f8a448..0000000 --- a/src/constants/enum-mappings.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {ImageProxyFormatType, ProxyUserAgentType} from "~/server-types" -import {createEnumMapFromTranslation} from "~/utils" - -export const IMAGE_PROXY_FORMAT_TYPE_NAME_MAP = createEnumMapFromTranslation( - "settings.fields.imageProxyFormat.values", - ImageProxyFormatType, -) -export const PROXY_USER_AGENT_TYPE_NAME_MAP = createEnumMapFromTranslation( - "settings.fields.proxyUserAgent.values", - ProxyUserAgentType, -) diff --git a/src/route-widgets/AliasDetailRoute/AliasPreferencesForm.tsx b/src/route-widgets/AliasDetailRoute/AliasPreferencesForm.tsx index 9af8ce2..cba250c 100644 --- a/src/route-widgets/AliasDetailRoute/AliasPreferencesForm.tsx +++ b/src/route-widgets/AliasDetailRoute/AliasPreferencesForm.tsx @@ -13,11 +13,7 @@ import {QueryKey, useMutation} from "@tanstack/react-query" import {Alias, DecryptedAlias, ImageProxyFormatType, ProxyUserAgentType} from "~/server-types" import {UpdateAliasData, updateAlias} from "~/apis" -import {parseFastAPIError} from "~/utils" -import { - IMAGE_PROXY_FORMAT_TYPE_NAME_MAP, - PROXY_USER_AGENT_TYPE_NAME_MAP, -} from "~/constants/enum-mappings" +import {createEnumMapFromTranslation, parseFastAPIError} from "~/utils" import {useErrorSuccessSnacks} from "~/hooks" import {queryClient} from "~/constants/react-query" import {AuthContext, FormikAutoLockNavigation} from "~/components" @@ -48,6 +44,15 @@ export default function AliasPreferencesForm({ const {showSuccess, showError} = useErrorSuccessSnacks() const {_decryptUsingMasterPassword} = useContext(AuthContext) + const imageProxyMap = createEnumMapFromTranslation( + "settings.fields.imageProxyFormat.values", + ImageProxyFormatType, + )(key => t(key)) + const imageProxyUserAgentMap = createEnumMapFromTranslation( + "settings.fields.proxyUserAgent.values", + ProxyUserAgentType, + )(key => t(key)) + const schema = yup.object().shape({ removeTrackers: yup .mixed() @@ -164,9 +169,7 @@ export default function AliasPreferencesForm({ formik={formik} icon={} name="imageProxyFormat" - valueTextMap={ - IMAGE_PROXY_FORMAT_TYPE_NAME_MAP - } + valueTextMap={imageProxyMap} /> @@ -176,9 +179,7 @@ export default function AliasPreferencesForm({ )} formik={formik} name="proxyUserAgent" - valueTextMap={ - PROXY_USER_AGENT_TYPE_NAME_MAP - } + valueTextMap={imageProxyUserAgentMap} /> diff --git a/src/route-widgets/AliasDetailRoute/SelectField.tsx b/src/route-widgets/AliasDetailRoute/SelectField.tsx index beae57f..d4da56b 100644 --- a/src/route-widgets/AliasDetailRoute/SelectField.tsx +++ b/src/route-widgets/AliasDetailRoute/SelectField.tsx @@ -30,17 +30,17 @@ export default function SelectField({ valueTextMap: parentValueTextMap, }: SelectFieldProps): ReactElement { const user = useUser() - const {t} = useTranslation("components") + const {t} = useTranslation(["components", "aliases"]) const BOOLEAN_SELECT_TEXT_MAP: Record = { - true: "SelectField.values.true", - false: "SelectField.values.false", + true: t("SelectField.values.true"), + false: t("SelectField.values.false"), } const valueTextMap = parentValueTextMap ?? BOOLEAN_SELECT_TEXT_MAP const labelId = `${name}-label` const preferenceName = `alias${name.charAt(0).toUpperCase() + name.slice(1)}` const value = user.preferences[preferenceName as keyof User["preferences"]] - const defaultValueText = t(valueTextMap[value.toString()]) + const defaultValueText = valueTextMap[value.toString()] return ( @@ -81,7 +81,7 @@ export default function SelectField({ })} ) : ( - t(valueTextMap[value.toString()]) + valueTextMap[value.toString()] ) } > @@ -95,7 +95,7 @@ export default function SelectField({ {valueTextMap && Object.entries(valueTextMap).map(([value, translationString]) => ( - {t(translationString)} + {translationString} ))} diff --git a/src/routes/ReportDetailRoute.tsx b/src/routes/ReportDetailRoute.tsx index 67a2dd9..f6306ed 100644 --- a/src/routes/ReportDetailRoute.tsx +++ b/src/routes/ReportDetailRoute.tsx @@ -36,7 +36,7 @@ function ReportDetailRoute(): ReactElement { deleteReport(params.id!)} label={t("actions.delete.label")} - description={t("delete.description")} + description={t("actions.delete.description")} continueLabel={t("actions.delete.continueActionLabel")} navigateTo={"/reports"} successMessage={t("messages.report.deleted", {ns: "common"})} diff --git a/src/routes/ReportsRoute.tsx b/src/routes/ReportsRoute.tsx index 8948609..d23ba51 100644 --- a/src/routes/ReportsRoute.tsx +++ b/src/routes/ReportsRoute.tsx @@ -26,14 +26,15 @@ const SORTING_VIEW_ICON_MAP: Record = { [SortingView.List]: , [SortingView.GroupByAlias]: , } -const SORTING_VIEW_NAME_MAP: Record = createEnumMapFromTranslation( - "pageActions.sort.values", - SortingView, -) function ReportsRoute(): ReactElement { const {t} = useTranslation("reports") + const sortingViewNameMap = createEnumMapFromTranslation( + "pageActions.sort.values", + SortingView, + )(key => t(key)) + const query = useQuery, AxiosError>(["get_reports"], getReports) const [sortingView, setSortingView] = useState(SortingView.List) @@ -57,9 +58,9 @@ function ReportsRoute(): ReactElement { }} select > - {Object.keys(SORTING_VIEW_NAME_MAP).map(name => ( + {Object.keys(sortingViewNameMap).map(name => ( - {t(SORTING_VIEW_NAME_MAP[name as SortingView])} + {t(sortingViewNameMap[name as SortingView])} ))} diff --git a/src/routes/SettingsAliasPreferencesRoute.tsx b/src/routes/SettingsAliasPreferencesRoute.tsx index eb1609b..0dec109 100644 --- a/src/routes/SettingsAliasPreferencesRoute.tsx +++ b/src/routes/SettingsAliasPreferencesRoute.tsx @@ -25,11 +25,7 @@ import {LoadingButton} from "@mui/lab" import {ImageProxyFormatType, ProxyUserAgentType, SimpleDetailResponse} from "~/server-types" import {UpdatePreferencesData, updatePreferences} from "~/apis" import {useErrorSuccessSnacks, useUser} from "~/hooks" -import {parseFastAPIError} from "~/utils" -import { - IMAGE_PROXY_FORMAT_TYPE_NAME_MAP, - PROXY_USER_AGENT_TYPE_NAME_MAP, -} from "~/constants/enum-mappings" +import {createEnumMapFromTranslation, parseFastAPIError} from "~/utils" import {AuthContext, SimplePageBuilder} from "~/components" interface Form { @@ -49,6 +45,15 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { const user = useUser() const {showError, showSuccess} = useErrorSuccessSnacks() + const imageProxyMap = createEnumMapFromTranslation( + "settings.fields.imageProxyFormat.values", + ImageProxyFormatType, + )(key => t(key)) + const imageProxyUserAgentMap = createEnumMapFromTranslation( + "settings.fields.proxyUserAgent.values", + ProxyUserAgentType, + )(key => t(key)) + const schema = yup.object().shape({ removeTrackers: yup.boolean().label(t("settings.fields.removeTrackers.label")), createMailReport: yup.boolean().label(t("settings.fields.createMailReport.label")), @@ -251,7 +256,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { formik.errors.imageProxyFormat } > - {Object.entries(IMAGE_PROXY_FORMAT_TYPE_NAME_MAP).map( + {Object.entries(imageProxyMap).map( ([value, translationString]) => ( {t(translationString)} @@ -292,7 +297,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { formik.touched.proxyUserAgent && formik.errors.proxyUserAgent } > - {Object.entries(PROXY_USER_AGENT_TYPE_NAME_MAP).map( + {Object.entries(imageProxyUserAgentMap).map( ([value, translationString]) => ( {t(translationString)} diff --git a/src/utils/create-enum-map-from-translation.ts b/src/utils/create-enum-map-from-translation.ts index 294adec..fd9f31e 100644 --- a/src/utils/create-enum-map-from-translation.ts +++ b/src/utils/create-enum-map-from-translation.ts @@ -1,9 +1,11 @@ +type TranslationFunction = (key: string) => string + export default function createEnumMapFromTranslation>( prefix: string, TEnum: T, -): Record { - return Object.fromEntries(Object.values(TEnum).map(key => [key, `${prefix}.${key}`])) as Record< - keyof T, - string - > +): (callback: TranslationFunction) => Record { + return callback => + Object.fromEntries( + Object.values(TEnum).map(key => [key, callback(`${prefix}.${key}`)]), + ) as Record }