The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add localization support to deepview page (#3362)
Steven Tey23e7b14473f2
diff --git a/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/action-buttons.tsx b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/action-buttons.tsxindex 87ad4db096..77e83983bd 100644--- a/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/action-buttons.tsx+++ b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/action-buttons.tsx@@ -3,12 +3,16 @@import { Link } from "@dub/prisma/client";import { Button, IOSAppStore, useCopyToClipboard } from "@dub/ui";import { useSearchParams } from "next/navigation";+import { getTranslations, Language } from "./translations";export function DeepLinkActionButtons({link,+ language,}: {link: Pick<Link, "shortLink">;+ language: Language;}) {+ const t = getTranslations(language);const searchParams = useSearchParams();const searchParamsString = searchParams.toString();@@ -27,7 +31,7 @@ export function DeepLinkActionButtons({return (<div className="flex flex-col items-center gap-4"><Button- text="Open in the app"+ text={t.openInApp}className="h-12 w-full rounded-xl bg-neutral-900 text-white"variant="primary"onClick={() => handleClick({ withCopy: true })}@@ -38,7 +42,7 @@ export function DeepLinkActionButtons({onClick={() => handleClick()}className="text-sm text-neutral-500">- Open in the app without copying+ {t.openInAppWithoutCopying}</button></div>);diff --git a/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/page.tsx b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/page.tsxindex 2f465ca3bf..3e9ab79ec3 100644--- a/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/page.tsx+++ b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/page.tsx@@ -3,10 +3,12 @@ import { prisma } from "@dub/prisma";import { Grid, Wordmark } from "@dub/ui";import { ArrowRight, Copy, IOSAppStore, MobilePhone } from "@dub/ui/icons";import { cn } from "@dub/utils";+import { headers } from "next/headers";import Link from "next/link";import { redirect } from "next/navigation";import { DeepLinkActionButtons } from "./action-buttons";import { BrandLogoBadge } from "./brand-logo-badge";+import { getLanguage, getTranslations } from "./translations";export default async function DeepLinkPreviewPage(props: {params: Promise<{ domain: string; key: string }>;@@ -15,6 +17,12 @@ export default async function DeepLinkPreviewPage(props: {const domain = params.domain;const key = decodeURIComponent(params.key);+ // Detect language from Accept-Language header+ const headersList = await headers();+ const acceptLanguage = headersList.get("accept-language");+ const language = getLanguage(acceptLanguage);+ const t = getTranslations(language);+const link = await prisma.link.findUnique({where: {domain_key: {@@ -92,7 +100,7 @@ export default async function DeepLinkPreviewPage(props: {target="_blank"className="flex items-center gap-1 whitespace-nowrap text-sm font-medium text-neutral-900">- Powered by <Wordmark className="text-content-emphasis h-3.5" />+ {t.poweredBy} <Wordmark className="text-content-emphasis h-3.5" /></Link></div>@@ -102,7 +110,7 @@ export default async function DeepLinkPreviewPage(props: {<div className="flex h-40 w-full max-w-xs flex-col gap-6 rounded-xl border border-neutral-300 px-10 py-8"><p className="text-center text-sm font-normal leading-5 text-neutral-700">- Clicking below will copy this page and open it in the app.+ {t.description}</p><div className="flex items-center justify-center gap-3">@@ -115,7 +123,7 @@ export default async function DeepLinkPreviewPage(props: {</div></div>- <DeepLinkActionButtons link={link} />+ <DeepLinkActionButtons link={link} language={language} /></div></div></main>diff --git a/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/translations.ts b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/translations.tsnew file mode 100644index 0000000000..fec7d50221--- /dev/null+++ b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/translations.ts@@ -0,0 +1,63 @@+export const translations = {+ en: {+ poweredBy: "Powered by",+ description: "Clicking below will copy this page and open it in the app.",+ openInApp: "Open in the app",+ openInAppWithoutCopying: "Open in the app without copying",+ },+ zh: {+ poweredBy: "由",+ description: "点击下方将复制此页面并在应用中打开。",+ openInApp: "在应用中打开",+ openInAppWithoutCopying: "在应用中打开(不复制)",+ },+ es: {+ poweredBy: "Desarrollado por",+ description:+ "Al hacer clic a continuación, se copiará esta página y se abrirá en la aplicación.",+ openInApp: "Abrir en la aplicación",+ openInAppWithoutCopying: "Abrir en la aplicación sin copiar",+ },+ fr: {+ poweredBy: "Propulsé par",+ description:+ "En cliquant ci-dessous, cette page sera copiée et ouverte dans l'application.",+ openInApp: "Ouvrir dans l'application",+ openInAppWithoutCopying: "Ouvrir dans l'application sans copier",+ },+ tr: {+ poweredBy: "Tarafından desteklenmektedir",+ description:+ "Aşağıya tıklamak bu sayfayı kopyalayacak ve uygulamada açacaktır.",+ openInApp: "Uygulamada aç",+ openInAppWithoutCopying: "Kopyalamadan uygulamada aç",+ },+} as const;++export type Language = keyof typeof translations;++export function getLanguage(acceptLanguage?: string | null): Language {+ if (!acceptLanguage) return "en";++ const languages = acceptLanguage+ .toLowerCase()+ .split(",")+ .map((lang) => {+ const [code] = lang.trim().split(";");+ return code.split("-")[0]; // Extract base language code (e.g., "en" from "en-US")+ });++ // Check for supported languages in order of preference+ for (const lang of languages) {+ if (lang in translations) {+ return lang as Language;+ }+ }++ // Default to English if no match found+ return "en";+}++export function getTranslations(language: Language) {+ return translations[language];+}