feat: option to enforce language for bookingPage (#18782)

* feature eventType specific language or bookingPage language

* chore

* fix type checks

* chore

* chore: remove log

* improvement: this updates in DatePicker is not required with context provider method

* added e2e tests for InterfaceLanguage feature

* corrected prev merge conflict issues

* update to align with hooks usage pattern

* chore

* unrelated auto-formatting changes

* unrelated auto-formatting changes

* unrelated auto-formatting changes

* update to affect interfaceLanguage on success page

* undone prettier changes

* update test for success page translation

* chore

* return null from memo

* fix typecheck error due to atom imports in useLocale

* set default interfaceLanguage as null

* updated to use null instead of constant

* enhancements

* fix latest unit test, use prop instead of useSession hook

* fix build issue

* chore

* fix atom build issue

* fix unit test with reqd mock

* update to use server i18n rendering

* nit

* Move import localeOptions to EventSetupTabWebWrapper

* make sure we only display interface language option in web app

* using customI18nProvider

---------

Co-authored-by: amrit <[email protected]>
Co-authored-by: Tushar Bhatt <[email protected]>
Co-authored-by: Tushar <[email protected]>
Co-authored-by: Anik Dhabal Babu <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Ryukemeister <[email protected]>
Co-authored-by: Rajiv Sahal <[email protected]>
Co-authored-by: Benny Joo <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-05-18 01:12:26 -04:00
1 parent 6cb3bdc567
commit ec8f9d5f7a
26 files changed
+390 -21

No files matched your search

@@ -1,7 +1,10 @@
import { CustomI18nProvider } from "app/CustomI18nProvider";
import withEmbedSsrAppDir from "app/WithEmbedSSR";
import type { PageProps as ServerPageProps } from "app/_types";
import { cookies, headers } from "next/headers";
import { loadTranslations } from "@calcom/lib/server/i18n";
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import { getServerSideProps } from "@server/lib/[user]/[type]/getServerSideProps";
@@ -13,6 +16,18 @@ const getData = withEmbedSsrAppDir<ClientPageProps>(getServerSideProps);
const ServerPage = async ({ params, searchParams }: ServerPageProps) => {
const context = buildLegacyCtx(await headers(), await cookies(), await params, await searchParams);
const props = await getData(context);
const locale = props.eventData?.interfaceLanguage;
if (locale) {
const ns = "common";
const translations = await loadTranslations(locale, ns);
return (
<CustomI18nProvider translations={translations} locale={locale} ns={ns}>
<TypePage {...props} />
</CustomI18nProvider>
);
}
return <TypePage {...props} />;
};
@@ -1,9 +1,11 @@
import { CustomI18nProvider } from "app/CustomI18nProvider";
import { withAppDirSsr } from "app/WithAppDirSsr";
import type { PageProps } from "app/_types";
import { generateMeetingMetadata } from "app/_utils";
import { headers, cookies } from "next/headers";
import { getOrgFullOrigin } from "@calcom/features/ee/organizations/lib/orgDomains";
import { loadTranslations } from "@calcom/lib/server/i18n";
import { buildLegacyCtx, decodeParams } from "@lib/buildLegacyCtx";
@@ -55,6 +57,17 @@ const ServerPage = async ({ params, searchParams }: PageProps) => {
const legacyCtx = buildLegacyCtx(await headers(), await cookies(), await params, await searchParams);
const props = await getData(legacyCtx);
const locale = props.eventData?.interfaceLanguage;
if (locale) {
const ns = "common";
const translations = await loadTranslations(locale, ns);
return (
<CustomI18nProvider translations={translations} locale={locale} ns={ns}>
<LegacyPage {...props} />
</CustomI18nProvider>
);
}
return <LegacyPage {...props} />;
};
@@ -1,7 +1,10 @@
import { CustomI18nProvider } from "app/CustomI18nProvider";
import withEmbedSsrAppDir from "app/WithEmbedSSR";
import type { PageProps as ServerPageProps } from "app/_types";
import { cookies, headers } from "next/headers";
import { loadTranslations } from "@calcom/lib/server/i18n";
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import { getServerSideProps } from "@lib/org/[orgSlug]/[user]/[type]/getServerSideProps";
@@ -17,8 +20,32 @@ export type ClientPageProps = UserTypePageProps | TeamTypePageProps;
const ServerPage = async ({ params, searchParams }: ServerPageProps) => {
const context = buildLegacyCtx(await headers(), await cookies(), await params, await searchParams);
const props = await getData(context);
if ((props as TeamTypePageProps)?.teamId) return <TeamTypePage {...(props as TeamTypePageProps)} />;
return <UserTypePage {...(props as UserTypePageProps)} />;
const eventLocale = props.eventData?.interfaceLanguage;
const ns = "common";
let translations;
if (eventLocale) {
const ns = "common";
translations = await loadTranslations(eventLocale, ns);
}
if ((props as TeamTypePageProps)?.teamId) {
return eventLocale ? (
<CustomI18nProvider translations={translations} locale={eventLocale} ns={ns}>
<TeamTypePage {...(props as TeamTypePageProps)} />
</CustomI18nProvider>
) : (
<TeamTypePage {...(props as TeamTypePageProps)} />
);
}
return eventLocale ? (
<CustomI18nProvider translations={translations} locale={eventLocale} ns={ns}>
<UserTypePage {...(props as UserTypePageProps)} />
</CustomI18nProvider>
) : (
<UserTypePage {...(props as UserTypePageProps)} />
);
};
export default ServerPage;
@@ -1,9 +1,11 @@
import { CustomI18nProvider } from "app/CustomI18nProvider";
import { withAppDirSsr } from "app/WithAppDirSsr";
import type { PageProps } from "app/_types";
import { generateMeetingMetadata } from "app/_utils";
import { cookies, headers } from "next/headers";
import { getOrgFullOrigin } from "@calcom/features/ee/organizations/lib/orgDomains";
import { loadTranslations } from "@calcom/lib/server/i18n";
import { buildLegacyCtx, decodeParams } from "@lib/buildLegacyCtx";
import { getServerSideProps } from "@lib/org/[orgSlug]/[user]/[type]/getServerSideProps";
@@ -63,10 +65,32 @@ const ServerPage = async ({ params, searchParams }: PageProps) => {
const props = await getData(
buildLegacyCtx(await headers(), await cookies(), await params, await searchParams)
);
if ((props as TeamTypePageProps)?.teamId) {
return <TeamTypePage {...(props as TeamTypePageProps)} />;
const eventLocale = props.eventData?.interfaceLanguage;
const ns = "common";
let translations;
if (eventLocale) {
const ns = "common";
translations = await loadTranslations(eventLocale, ns);
}
return <UserTypePage {...(props as UserTypePageProps)} />;
if ((props as TeamTypePageProps)?.teamId) {
return eventLocale ? (
<CustomI18nProvider translations={translations} locale={eventLocale} ns={ns}>
<TeamTypePage {...(props as TeamTypePageProps)} />
</CustomI18nProvider>
) : (
<TeamTypePage {...(props as TeamTypePageProps)} />
);
}
return eventLocale ? (
<CustomI18nProvider translations={translations} locale={eventLocale} ns={ns}>
<UserTypePage {...(props as UserTypePageProps)} />
</CustomI18nProvider>
) : (
<UserTypePage {...(props as UserTypePageProps)} />
);
};
export default ServerPage;
@@ -1,7 +1,10 @@
import { CustomI18nProvider } from "app/CustomI18nProvider";
import withEmbedSsrAppDir from "app/WithEmbedSSR";
import type { PageProps as ServerPageProps } from "app/_types";
import { cookies, headers } from "next/headers";
import { loadTranslations } from "@calcom/lib/server/i18n";
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import { getServerSideProps } from "@lib/team/[slug]/[type]/getServerSideProps";
@@ -12,6 +15,18 @@ const getData = withEmbedSsrAppDir<ClientPageProps>(getServerSideProps);
const ServerPage = async ({ params, searchParams }: ServerPageProps) => {
const context = buildLegacyCtx(await headers(), await cookies(), await params, await searchParams);
const props = await getData(context);
const eventLocale = props.eventData?.interfaceLanguage;
if (eventLocale) {
const ns = "common";
const translations = await loadTranslations(eventLocale, ns);
return (
<CustomI18nProvider translations={translations} locale={eventLocale} ns={ns}>
<TypePage {...props} />
</CustomI18nProvider>
);
}
return <TypePage {...props} />;
};
@@ -1,9 +1,11 @@
import { CustomI18nProvider } from "app/CustomI18nProvider";
import { withAppDirSsr } from "app/WithAppDirSsr";
import type { PageProps } from "app/_types";
import { generateMeetingMetadata } from "app/_utils";
import { cookies, headers } from "next/headers";
import { getOrgFullOrigin } from "@calcom/features/ee/organizations/lib/orgDomains";
import { loadTranslations } from "@calcom/lib/server/i18n";
import { buildLegacyCtx, decodeParams } from "@lib/buildLegacyCtx";
import { getServerSideProps } from "@lib/team/[slug]/[type]/getServerSideProps";
@@ -54,6 +56,18 @@ const ServerPage = async ({ params, searchParams }: PageProps) => {
const props = await getData(
buildLegacyCtx(await headers(), await cookies(), await params, await searchParams)
);
const eventLocale = props.eventData?.interfaceLanguage;
if (eventLocale) {
const ns = "common";
const translations = await loadTranslations(eventLocale, ns);
return (
<CustomI18nProvider translations={translations} locale={eventLocale} ns={ns}>
<LegacyPage {...props} />
</CustomI18nProvider>
);
}
return <LegacyPage {...props} />;
};
export default ServerPage;
@@ -1,7 +1,10 @@
import { CustomI18nProvider } from "app/CustomI18nProvider";
import withEmbedSsrAppDir from "app/WithEmbedSSR";
import type { PageProps as ServerPageProps } from "app/_types";
import { cookies, headers } from "next/headers";
import { loadTranslations } from "@calcom/lib/server/i18n";
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import OldPage from "~/bookings/views/bookings-single-view";
@@ -15,6 +18,18 @@ const getEmbedData = withEmbedSsrAppDir<ClientPageProps>(getServerSideProps);
const ServerPage = async ({ params, searchParams }: ServerPageProps) => {
const context = buildLegacyCtx(await headers(), await cookies(), await params, await searchParams);
const props = await getEmbedData(context);
const eventLocale = props.eventType?.interfaceLanguage;
if (eventLocale) {
const ns = "common";
const translations = await loadTranslations(eventLocale, ns);
return (
<CustomI18nProvider translations={translations} locale={eventLocale} ns={ns}>
<OldPage {...props} />
</CustomI18nProvider>
);
}
return <OldPage {...props} />;
};
@@ -1,9 +1,11 @@
import { CustomI18nProvider } from "app/CustomI18nProvider";
import { withAppDirSsr } from "app/WithAppDirSsr";
import type { PageProps as _PageProps } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { cookies, headers } from "next/headers";
import { getOrgFullOrigin } from "@calcom/features/ee/organizations/lib/orgDomains";
import { loadTranslations } from "@calcom/lib/server/i18n";
import { BookingStatus } from "@calcom/prisma/enums";
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
@@ -36,6 +38,18 @@ const getData = withAppDirSsr<ClientPageProps>(getServerSideProps);
const ServerPage = async ({ params, searchParams }: _PageProps) => {
const context = buildLegacyCtx(await headers(), await cookies(), await params, await searchParams);
const props = await getData(context);
const eventLocale = props.eventType?.interfaceLanguage;
if (eventLocale) {
const ns = "common";
const translations = await loadTranslations(eventLocale, ns);
return (
<CustomI18nProvider translations={translations} locale={eventLocale} ns={ns}>
<OldPage {...props} />
</CustomI18nProvider>
);
}
return <OldPage {...props} />;
};
export default ServerPage;
+33
View File
@@ -0,0 +1,33 @@
"use client";
import { createContext, useMemo } from "react";
import type { ReactNode } from "react";
type CustomI18nContextType = {
translations: Record<string, string>;
ns: string;
locale: string;
};
export const CustomI18nContext = createContext<CustomI18nContextType | null>(null);
export function CustomI18nProvider({
children,
translations,
locale,
ns,
}: CustomI18nContextType & {
children: ReactNode;
}) {
// Memoize the value to prevent re-renders unless the data changes
const value = useMemo(
() => ({
translations,
locale,
ns,
}),
[locale, ns]
);
return <CustomI18nContext.Provider value={value}>{children}</CustomI18nContext.Provider>;
}
+1
View File
@@ -26,6 +26,7 @@ export const getEventTypesFromDB = async (id: number) => {
id: true,
title: true,
description: true,
interfaceLanguage: true,
length: true,
eventName: true,
recurringEvent: true,
@@ -141,6 +141,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
title: eventData.title,
users: eventHostsUserData,
hidden: eventData.hidden,
interfaceLanguage: eventData.interfaceLanguage,
},
booking,
user: teamSlug,
@@ -206,6 +207,7 @@ const getTeamWithEventsData = async (
hidden: true,
disableCancelling: true,
disableRescheduling: true,
interfaceLanguage: true,
hosts: {
take: 3,
select: {
+139
View File
@@ -421,6 +421,145 @@ test.describe("Event Types tests", () => {
await expect(offerSeatsToggle).toBeDisabled();
});
});
test.describe("Interface Language Tests", () => {
test.use({
locale: "en",
});
test("by default the Interface language has 'Visitor's browser language' selected", async ({
page,
users,
}) => {
await test.step("should create a en user", async () => {
const user = await users.create({
locale: "en",
});
await user.apiLogin();
await page.goto("/event-types");
await page.waitForSelector('[data-testid="event-types"]');
});
await test.step("should open first eventType and check Interface Language", async () => {
await gotoFirstEventType(page);
const interfaceLanguageValue = page
.getByTestId("event-interface-language")
.locator('div[class$="-singleValue"]');
await expect(interfaceLanguageValue).toHaveText("Visitor's browser language");
});
});
test("user can change the interface language to any other language and the booking page should be rendered in that language", async ({
page,
users,
}) => {
await test.step("should create a en user", async () => {
const user = await users.create({
locale: "en",
});
await user.apiLogin();
await page.goto("/event-types");
await page.waitForSelector('[data-testid="event-types"]');
});
await test.step("should open first eventType and change Interface Language to Deutsche", async () => {
await gotoFirstEventType(page);
await page.getByTestId("event-interface-language").click();
await page.locator(`text="Deutsch"`).click();
await saveEventType(page);
});
await test.step("should open corresponding booking page and ensure language rendered is Deutsche", async () => {
await gotoBookingPage(page);
//expect the slot selection page to be rendered in 'Deutsch'
await expect(page.locator(`text="So"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Mo"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Di"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Mi"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Do"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Fr"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Sa"`).nth(0)).toBeVisible();
await expect(page.locator(`text="12 Std"`).nth(0)).toBeVisible();
await expect(page.locator(`text="24 Std"`).nth(0)).toBeVisible();
await selectFirstAvailableTimeSlotNextMonth(page);
//expect the booking inputs page to be rendered in 'Deutsch'
await expect(page.locator(`text="Ihr Name"`).nth(0)).toBeVisible();
await expect(page.locator(`text="E-Mail Adresse"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Zusätzliche Notizen"`).nth(0)).toBeVisible();
await expect(page.locator(`text="+ Weitere Gäste"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Zurück"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Bestätigen"`).nth(0)).toBeVisible();
});
await test.step("should be able to book successfully and ensure success page is rendered in Deutsche", async () => {
await bookTimeSlot(page);
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
await expect(page.locator(`text="Dieser Termin ist geplant"`).nth(0)).toBeVisible();
});
});
test("user locale setting is overridden by event type language setting for booking page", async ({
page,
users,
}) => {
await test.step("should create a de user and ensure app is rendered in de", async () => {
const user = await users.create({
locale: "de",
});
await user.apiLogin();
await page.goto("/event-types");
await page.waitForSelector('[data-testid="event-types"]');
{
const locator = page.getByText("Ereignistypen", { exact: true }).first(); // "general"
await expect(locator).toBeVisible();
}
});
await test.step("should open first eventType and change Interface Language to Español", async () => {
await page.goto("/event-types");
await page.waitForSelector('[data-testid="event-types"]');
await gotoFirstEventType(page);
await page.getByTestId("event-interface-language").click();
await page.getByTestId("select-option-es").click();
await saveEventType(page);
});
await test.step("should go to booking page and verify the Interface language is Español", async () => {
await gotoBookingPage(page);
//expect the slot selection page to be rendered in 'Español'
await expect(page.locator(`text="dom"`).nth(0)).toBeVisible();
await expect(page.locator(`text="lun"`).nth(0)).toBeVisible();
await expect(page.locator(`text="mar"`).nth(0)).toBeVisible();
await expect(page.locator(`text="mié"`).nth(0)).toBeVisible();
await expect(page.locator(`text="jue"`).nth(0)).toBeVisible();
await expect(page.locator(`text="vie"`).nth(0)).toBeVisible();
await expect(page.locator(`text="sáb"`).nth(0)).toBeVisible();
await expect(page.locator(`text="12 h"`).nth(0)).toBeVisible();
await expect(page.locator(`text="24hs"`).nth(0)).toBeVisible();
await selectFirstAvailableTimeSlotNextMonth(page);
//expect the booking inputs page to be rendered in 'Español'
await expect(page.locator(`text="Tu Nombre"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Email"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Notas Adicionales"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Añadir invitados"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Atrás"`).nth(0)).toBeVisible();
await expect(page.locator(`text="Confirmar"`).nth(0)).toBeVisible();
await bookTimeSlot(page);
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
});
await test.step("ensure other components of the App is still rendered in de and not affected by setting eventType Interface Language to Español", async () => {
await page.goto("/event-types");
await page.waitForSelector('[data-testid="event-types"]');
{
const locator = page.getByText("Ereignistypen", { exact: true }).first(); // "general"
await expect(locator).toBeVisible();
}
});
});
});
});
const selectAttendeePhoneNumber = async (page: Page) => {
@@ -3118,6 +3118,8 @@
"could_not_find_slug_to_publish_org": "Could not find slug to publish the organization",
"picklist": "Picklist",
"most_cancelled_bookings": "Most Cancelled Bookings",
"interface_language": "Interface Language",
"visitors_browser_language": "Visitor's browser language",
"name_or_email": "Name or Email",
"salesforce_round_robin_skip_fallback_to_lead_owner": "If no contact is found, fallback to lead owner if it exists",
"credit_purchase_failed": "Credit purchase failed. Please try again or contact support.",