From 821843bc6c144153244c646f79bbc1ec2ef9a160 Mon Sep 17 00:00:00 2001 From: Kacper Date: Fri, 30 Aug 2024 18:07:10 +0200 Subject: [PATCH] Fallback to next app default language (en) when user didn't specify locale. (#16425) --- packages/features/ee/users/components/UserForm.tsx | 4 ++-- packages/lib/i18n.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/features/ee/users/components/UserForm.tsx b/packages/features/ee/users/components/UserForm.tsx index c88b481301..25fe21e338 100644 --- a/packages/features/ee/users/components/UserForm.tsx +++ b/packages/features/ee/users/components/UserForm.tsx @@ -4,7 +4,7 @@ import { Controller, useForm } from "react-hook-form"; import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl"; import { useLocale } from "@calcom/lib/hooks/useLocale"; -import { localeOptions } from "@calcom/lib/i18n"; +import { defaultLocaleOption, localeOptions } from "@calcom/lib/i18n"; import { nameOfDay } from "@calcom/lib/weekday"; import { Avatar, @@ -76,7 +76,7 @@ export const UserForm = ({ { value: "GOOGLE", label: "GOOGLE" }, { value: "SAML", label: "SAML" }, ]; - const defaultLocale = defaultValues?.locale || localeOptions[0].value; + const defaultLocale = defaultValues?.locale || defaultLocaleOption.value; const form = useForm({ defaultValues: { diff --git a/packages/lib/i18n.ts b/packages/lib/i18n.ts index ed2a33d07f..5de87507b0 100644 --- a/packages/lib/i18n.ts +++ b/packages/lib/i18n.ts @@ -8,3 +8,7 @@ export const localeOptions = locales.map((locale) => ({ value: locale, label: new Intl.DisplayNames(locale, { type: "language" }).of(locale) || "", })); + +export const defaultLocaleOption = localeOptions.find( + (locale) => locale.value === i18n.defaultLocale +) as (typeof localeOptions)[number];