Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
♻️ Render server-side Trans without context in remaining server components (#2827)
Luke Vellafae61d5de114
diff --git a/apps/web/src/app/[locale]/(auth)/reset-password/page.tsx b/apps/web/src/app/[locale]/(auth)/reset-password/page.tsxindex 6c574b842..590b4cb15 100644--- a/apps/web/src/app/[locale]/(auth)/reset-password/page.tsx+++ b/apps/web/src/app/[locale]/(auth)/reset-password/page.tsx@@ -1,7 +1,7 @@import type { Metadata } from "next";import { notFound } from "next/navigation";+import { Trans } from "react-i18next/TransWithoutContext";import { env } from "@/env";-import { Trans } from "@/i18n/client";import { getTranslation } from "@/i18n/server";import {AuthPageContainer,@@ -18,14 +18,24 @@ export default async function ResetPasswordPage() {if (env.EMAIL_LOGIN_ENABLED === "false") {notFound();}+ const { t, i18n } = await getTranslation();return (<AuthPageContainer><AuthPageHeader><AuthPageTitle>- <Trans i18nKey="resetPasswordTitle" defaults="Reset Password" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="resetPasswordTitle"+ defaults="Reset Password"+ /></AuthPageTitle><AuthPageDescription><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="resetPasswordDescription"defaults="Enter your new password below"/>@@ -36,6 +46,9 @@ export default async function ResetPasswordPage() {</AuthPageContent><AuthPageExternal><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="resetPasswordFooter"defaults="<a>Back to login</a>"components={{diff --git a/apps/web/src/app/[locale]/control-panel/branding/page.tsx b/apps/web/src/app/[locale]/control-panel/branding/page.tsxindex e138d5e29..a35bffaa3 100644--- a/apps/web/src/app/[locale]/control-panel/branding/page.tsx+++ b/apps/web/src/app/[locale]/control-panel/branding/page.tsx@@ -3,6 +3,7 @@ import { Input } from "@rallly/ui/input";import { Switch } from "@rallly/ui/switch";import { CodeIcon, GemIcon } from "lucide-react";import type { Metadata } from "next";+import { Trans } from "react-i18next/TransWithoutContext";import {PageSection,PageSectionContent,@@ -20,7 +21,6 @@ import {} from "@/components/settings-layout";import { getCustomBrandingConfig } from "@/features/branding/data";import { loadInstanceLicense } from "@/features/licensing/data";-import { Trans } from "@/i18n/client";import { getTranslation } from "@/i18n/server";async function loadData() {@@ -41,13 +41,17 @@ async function loadData() {};}-function SetEnvironmentVariableAlert({ variable }: { variable: string }) {+async function SetEnvironmentVariableAlert({ variable }: { variable: string }) {+ const { t, i18n } = await getTranslation();return (<Alert><CodeIcon /><AlertDescription><p><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="setEnvironmentVariable"defaults="This value can be changed by setting the <env /> environment variable."components={{@@ -71,15 +75,25 @@ export default async function BrandingPage() {hideAttribution,appName,} = await loadData();+ const { t, i18n } = await getTranslation();return (<SettingsPage><SettingsPageHeader><SettingsPageTitle>- <Trans i18nKey="branding" defaults="Branding" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="branding"+ defaults="Branding"+ /></SettingsPageTitle><SettingsPageDescription><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="brandingDescription"defaults="View your instance branding configuration"/>@@ -92,6 +106,9 @@ export default async function BrandingPage() {<AlertDescription className="flex gap-2"><p className="flex-1"><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="customBrandingAlertDescription"defaults="Custom branding is available to Enterprise license holders as a paid add-on."/>@@ -103,7 +120,13 @@ export default async function BrandingPage() {className="underline"rel="noreferrer">- <Trans i18nKey="learnMore" defaults="Learn more" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="learnMore"+ defaults="Learn more"+ /></a></p></AlertDescription>@@ -113,10 +136,19 @@ export default async function BrandingPage() {<PageSection variant="card"><PageSectionHeader><PageSectionTitle>- <Trans i18nKey="general" defaults="General" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="general"+ defaults="General"+ /></PageSectionTitle><PageSectionDescription><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="brandingDescription"defaults="View your instance branding configuration"/>@@ -125,7 +157,13 @@ export default async function BrandingPage() {<PageSectionContent><div className="space-y-2"><div className="text-muted-foreground text-xs">- <Trans i18nKey="name" defaults="App Name" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="name"+ defaults="App Name"+ /></div><Input value={appName} readOnly /><SetEnvironmentVariableAlert variable="APP_NAME" />@@ -135,10 +173,19 @@ export default async function BrandingPage() {<PageSection variant="card"><PageSectionHeader><PageSectionTitle>- <Trans i18nKey="colors" defaults="Colors" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="colors"+ defaults="Colors"+ /></PageSectionTitle><PageSectionDescription><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="colorsDescription"defaults="Primary colors used for theming"/>@@ -148,7 +195,13 @@ export default async function BrandingPage() {<div className="space-y-6"><div className="space-y-2"><div className="text-muted-foreground text-xs">- <Trans i18nKey="primaryColor" defaults="Primary Color" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="primaryColor"+ defaults="Primary Color"+ /></div><div className="flex items-center gap-2"><div@@ -164,6 +217,9 @@ export default async function BrandingPage() {<div className="space-y-2"><div className="text-muted-foreground text-xs"><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="primaryColorDark"defaults="Primary Color (Dark Mode)"/>@@ -185,10 +241,19 @@ export default async function BrandingPage() {<PageSection variant="card"><PageSectionHeader><PageSectionTitle>- <Trans i18nKey="logos" defaults="Logos" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="logos"+ defaults="Logos"+ /></PageSectionTitle><PageSectionDescription><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="logosDescription"defaults="Logo images used throughout the application"/>@@ -198,7 +263,13 @@ export default async function BrandingPage() {<div className="space-y-6"><div className="space-y-2"><div className="text-muted-foreground text-xs">- <Trans i18nKey="logo" defaults="Logo" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="logo"+ defaults="Logo"+ /></div><div className="flex items-center gap-4"><div className="flex w-48 items-center justify-center overflow-hidden rounded border bg-white">@@ -214,7 +285,13 @@ export default async function BrandingPage() {</div><div className="space-y-2"><div className="text-muted-foreground text-xs">- <Trans i18nKey="logoDark" defaults="Logo (Dark Mode)" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="logoDark"+ defaults="Logo (Dark Mode)"+ /></div><div className="flex items-center gap-4"><div className="flex w-48 items-center justify-center overflow-hidden rounded border bg-gray-900">@@ -230,7 +307,13 @@ export default async function BrandingPage() {</div><div className="space-y-2"><div className="text-muted-foreground text-xs">- <Trans i18nKey="logoIcon" defaults="Logo Icon" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="logoIcon"+ defaults="Logo Icon"+ /></div><div className="flex items-center gap-4"><div className="flex size-16 items-center justify-center overflow-hidden rounded border bg-white">@@ -250,10 +333,19 @@ export default async function BrandingPage() {<PageSection variant="card"><PageSectionHeader><PageSectionTitle>- <Trans i18nKey="attribution" defaults="Attribution" />+ <Trans+ t={t}+ i18n={i18n}+ ns="app"+ i18nKey="attribution"+ defaults="Attribution"+ /></PageSectionTitle><PageSectionDescription><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="attributionDescription"defaults="Control the visibility of the attribution text"/>@@ -263,6 +355,9 @@ export default async function BrandingPage() {<div className="space-y-2"><div className="text-muted-foreground text-xs"><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="hideAttribution"defaults="Hide Attribution"/>diff --git a/apps/web/src/features/licensing/components/license-limit-warning.tsx b/apps/web/src/features/licensing/components/license-limit-warning.tsxindex b70e9d235..a3d89d284 100644--- a/apps/web/src/features/licensing/components/license-limit-warning.tsx+++ b/apps/web/src/features/licensing/components/license-limit-warning.tsx@@ -1,8 +1,9 @@import Link from "next/link";+import { Trans } from "react-i18next/TransWithoutContext";import { DEFAULT_SEAT_LIMIT } from "@/features/licensing/constants";import { loadInstanceLicense } from "@/features/licensing/data";import { getUserCount } from "@/features/user/data";-import { Trans } from "@/i18n/client";+import { getTranslation } from "@/i18n/server";import { isSelfHosted } from "@/lib/constants";export async function LicenseLimitWarning() {@@ -21,9 +22,14 @@ export async function LicenseLimitWarning() {return null;}+ const { t, i18n } = await getTranslation();+return (<div className="m-1 rounded-md bg-muted p-2 text-center text-muted-foreground text-sm"><Trans+ t={t}+ i18n={i18n}+ ns="app"i18nKey="licenseLimitWarning"defaults="You have exceeded the limits of your license. Please <a>upgrade</a>."components={{diff --git a/apps/web/src/i18n/server.ts b/apps/web/src/i18n/server.tsindex 7bd6b6a18..9b3ce3d55 100644--- a/apps/web/src/i18n/server.ts+++ b/apps/web/src/i18n/server.ts@@ -1,9 +1,10 @@+import { cache } from "react";import { defaultNS } from "@/i18n/settings";import { initI18next } from "./i18n";import { getLocale } from "./server/get-locale";-export async function getTranslation(localeOverride?: string) {+export const getTranslation = cache(async (localeOverride?: string) => {let locale = localeOverride;if (!locale) {@@ -17,4 +18,4 @@ export async function getTranslation(localeOverride?: string) {t: i18n.getFixedT(locale, defaultNS),i18n,};-}+});