From c30e867147392a7778316a1fabc40bb36c474887 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Wed, 27 Sep 2023 10:53:17 +0100 Subject: [PATCH] Use given locale input or user locale when translating updateProfile --- .../server/routers/loggedInViewer/updateProfile.handler.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts b/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts index af16a06aa5..506e2c189a 100644 --- a/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts +++ b/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts @@ -33,6 +33,7 @@ type UpdateProfileOptions = { export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions) => { const { user } = ctx; const userMetadata = handleUserMetadata({ ctx, input }); + const locale = input.locale || user.locale; const data: Prisma.UserUpdateInput = { ...input, metadata: userMetadata, @@ -45,7 +46,7 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions) const layoutError = validateBookerLayouts(input?.metadata?.defaultBookerLayouts || null); if (layoutError) { - const t = await getTranslation("en", "common"); + const t = await getTranslation(locale, "common"); throw new TRPCError({ code: "BAD_REQUEST", message: t(layoutError) }); } @@ -57,7 +58,8 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions) const response = await checkUsername(username); isPremiumUsername = response.premium; if (!response.available) { - throw new TRPCError({ code: "BAD_REQUEST", message: response.message }); + const t = await getTranslation(locale, "common"); + throw new TRPCError({ code: "BAD_REQUEST", message: t("username_already_taken") }); } } }