π Open source, privacy-first web analytics β a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
feat: migrate i18n from ?lng= query to /{lang}/ path-based URLs
Blue Mouse2af79141c6ea
diff --git a/web/app/App.tsx b/web/app/App.tsxindex 78fa7bfe7..1eb8c89ea 100644--- a/web/app/App.tsx+++ b/web/app/App.tsx@@ -7,12 +7,14 @@ import { Toaster } from 'sonner'import Footer from '~/components/Footer'import Header from '~/components/Header'+import { stripLangFromPath } from '~/lib/constants'import routesPath from '~/utils/routes'import { useTheme } from './providers/ThemeProvider'const App = () => {- const { pathname } = useLocation()+ const { pathname: rawPathname } = useLocation()+ const pathname = stripLangFromPath(rawPathname)const { theme } = useTheme()const isOnboardingPage = pathname === routesPath.onboardingdiff --git a/web/app/components/ExitIntentPopup.tsx b/web/app/components/ExitIntentPopup.tsxindex 68bf092cf..b05fc700a 100644--- a/web/app/components/ExitIntentPopup.tsx+++ b/web/app/components/ExitIntentPopup.tsx@@ -1,7 +1,7 @@import { XIcon } from '@phosphor-icons/react'import { useEffect, useRef, useState } from 'react'import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { useAuth } from '~/providers/AuthProvider'import { Badge } from '~/ui/Badge'diff --git a/web/app/components/Footer/index.tsx b/web/app/components/Footer/index.tsxindex 0f3b0869f..ae9c27eb5 100644--- a/web/app/components/Footer/index.tsx+++ b/web/app/components/Footer/index.tsx@@ -34,7 +34,7 @@ import {import _map from 'lodash/map'import React, { memo, type FC } from 'react'import { Trans, useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { changeLanguage } from '~/i18n'import {diff --git a/web/app/components/Header/banners.tsx b/web/app/components/Header/banners.tsxindex c0b00805b..afc49a4bc 100644--- a/web/app/components/Header/banners.tsx+++ b/web/app/components/Header/banners.tsx@@ -1,6 +1,6 @@import { useEffect, useMemo, useState } from 'react'import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import dayjs from 'dayjs'import duration from 'dayjs/plugin/duration'import utc from 'dayjs/plugin/utc'diff --git a/web/app/components/Header/index.tsx b/web/app/components/Header/index.tsxindex dc3ef16fb..fd31d77d3 100644--- a/web/app/components/Header/index.tsx+++ b/web/app/components/Header/index.tsx@@ -43,7 +43,7 @@ import {} from '@phosphor-icons/react'import { memo, Fragment, useState, useRef } from 'react'import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { changeLanguage } from '~/i18n'import {diff --git a/web/app/components/LocaleLinks.tsx b/web/app/components/LocaleLinks.tsxindex d6e6a4a0c..8276fd636 100644--- a/web/app/components/LocaleLinks.tsx+++ b/web/app/components/LocaleLinks.tsx@@ -1,74 +1,53 @@import _map from 'lodash/map'import _some from 'lodash/some'import { useMemo } from 'react'-import { useLocation, Location } from 'react-router'+import { useLocation, type Location } from 'react-router'import {whitelist,whitelistWithCC,MAIN_URL,- defaultLanguage,+ localisePath,+ stripLangFromPath,} from '~/lib/constants'-const getUrlFromLocation = (location: Location) => {- const { pathname, search } = location- const urlObject = new URL(`${MAIN_URL}${pathname}${search}`)-- return urlObject+const buildHref = (lang: string, pathname: string, search: string): string => {+ const path = localisePath(pathname, lang)+ return `${MAIN_URL}${path}${search}`}const getAlternateLinks = (location: Location) => {- const urlObject = getUrlFromLocation(location)+ const unprefixedPathname = stripLangFromPath(location.pathname)+ const search = location.search ?? ''- // Ensure x-default always points to URL without the ?lng parameter- const urlWithoutLng = new URL(urlObject.toString())- urlWithoutLng.searchParams.delete('lng')- const lnglessUrl = urlWithoutLng.toString()+ const xDefault = `${MAIN_URL}${unprefixedPathname}${search}`- const alternateLinks = _map(whitelist, (lc) => {- const href =- lc === defaultLanguage- ? lnglessUrl- : (() => {- const tmp = new URL(lnglessUrl)- tmp.searchParams.set('lng', lc)- return tmp.toString()- })()+ const alternateLinks = _map(whitelist, (lc) => ({+ rel: 'alternate',+ hrefLang: lc,+ href: buildHref(lc, unprefixedPathname, search),+ }))- return {- rel: 'alternate',- hrefLang: lc,- href,- }- })-- const alternateLinksWithCountryCodes = _map(whitelistWithCC, (value, key) => {- const href =- key === defaultLanguage- ? lnglessUrl- : (() => {- const tmp = new URL(lnglessUrl)- tmp.searchParams.set('lng', key)- return tmp.toString()- })()-- return {+ const alternateLinksWithCountryCodes = _map(+ whitelistWithCC,+ (value, key) => ({rel: 'alternate',hrefLang: value,- href,- }- })+ href: buildHref(key, unprefixedPathname, search),+ }),+ )return {altLinks: [...alternateLinks, ...alternateLinksWithCountryCodes],- lnglessUrl,+ xDefault,}}const NO_ALTERNATE_LINKS = [/^\/blog/i]const getShouldBeIgnored = (location: Location) => {- return _some(NO_ALTERNATE_LINKS, (regex) => regex.test(location.pathname))+ const unprefixed = stripLangFromPath(location.pathname)+ return _some(NO_ALTERNATE_LINKS, (regex) => regex.test(unprefixed))}export const LocaleLinks = () => {@@ -81,7 +60,7 @@ export const LocaleLinks = () => {const altLinks = useMemo(() => getAlternateLinks(location), [location])if (shouldBeIgnored) {- return+ return null}return (@@ -89,7 +68,7 @@ export const LocaleLinks = () => {{_map(altLinks.altLinks, (link) => (<link key={link.hrefLang} {...link} />))}- <link rel='alternate' href={altLinks.lnglessUrl} hrefLang='x-default' />+ <link rel='alternate' href={altLinks.xDefault} hrefLang='x-default' /></>)}diff --git a/web/app/components/ToolsNav.tsx b/web/app/components/ToolsNav.tsxindex 8c1e79d72..557a68946 100644--- a/web/app/components/ToolsNav.tsx+++ b/web/app/components/ToolsNav.tsx@@ -17,8 +17,10 @@ import {PercentIcon,} from '@phosphor-icons/react'import { useState } from 'react'-import { Link, useLocation } from 'react-router'+import { Link } from '~/ui/Link'+import { useLocation } from 'react-router'+import { stripLangFromPath } from '~/lib/constants'import { Text } from '~/ui/Text'import { cn } from '~/utils/generic'@@ -146,7 +148,7 @@ export function ToolsNav({ className }: ToolsNavProps) {)}>{TOOLS.map((tool, index) => {- const isActive = location.pathname === tool.href+ const isActive = stripLangFromPath(location.pathname) === tool.hrefconst Icon = tool.iconreturn (@@ -193,7 +195,9 @@ export function ToolsNavMobile({ className }: ToolsNavProps) {const location = useLocation()const [isOpen, setIsOpen] = useState(false)- const currentTool = TOOLS.find((tool) => tool.href === location.pathname)+ const currentTool = TOOLS.find(+ (tool) => tool.href === stripLangFromPath(location.pathname),+ )const CurrentIcon = currentTool?.iconreturn (@@ -231,33 +235,33 @@ export function ToolsNavMobile({ className }: ToolsNavProps) {{isOpen && (<div className='border-t border-gray-100 dark:border-slate-700'>- {TOOLS.filter((tool) => tool.href !== location.pathname).map(- (tool, index) => {- const Icon = tool.icon+ {TOOLS.filter(+ (tool) => tool.href !== stripLangFromPath(location.pathname),+ ).map((tool, index) => {+ const Icon = tool.icon- return (- <Link- key={tool.id}- to={tool.href}- className={cn(- 'flex items-start gap-3 px-4 py-3 transition-colors hover:bg-gray-50 dark:hover:bg-slate-700/30',- index !== 0 &&- 'border-t border-gray-100 dark:border-slate-700',- )}- >- <Icon className='mt-0.5 h-5 w-5 shrink-0 text-gray-400 dark:text-gray-500' />- <div className='min-w-0'>- <Text as='p' size='sm' weight='medium' colour='muted'>- {tool.title}- </Text>- <Text as='p' size='xs' colour='muted'>- {tool.description}- </Text>- </div>- </Link>- )- },- )}+ return (+ <Link+ key={tool.id}+ to={tool.href}+ className={cn(+ 'flex items-start gap-3 px-4 py-3 transition-colors hover:bg-gray-50 dark:hover:bg-slate-700/30',+ index !== 0 &&+ 'border-t border-gray-100 dark:border-slate-700',+ )}+ >+ <Icon className='mt-0.5 h-5 w-5 shrink-0 text-gray-400 dark:text-gray-500' />+ <div className='min-w-0'>+ <Text as='p' size='sm' weight='medium' colour='muted'>+ {tool.title}+ </Text>+ <Text as='p' size='xs' colour='muted'>+ {tool.description}+ </Text>+ </div>+ </Link>+ )+ })}</div>)}</div>diff --git a/web/app/components/marketing/DitchGoogle.tsx b/web/app/components/marketing/DitchGoogle.tsxindex fa2240892..33426fd5d 100644--- a/web/app/components/marketing/DitchGoogle.tsx+++ b/web/app/components/marketing/DitchGoogle.tsx@@ -1,6 +1,6 @@import { ArrowRightIcon, CheckIcon } from '@phosphor-icons/react'import { Trans, useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import routes from '~/utils/routes'diff --git a/web/app/components/marketing/FAQ.tsx b/web/app/components/marketing/FAQ.tsxindex b5095eb57..f7244f9c5 100644--- a/web/app/components/marketing/FAQ.tsx+++ b/web/app/components/marketing/FAQ.tsx@@ -1,7 +1,7 @@import _map from 'lodash/map'import { useMemo } from 'react'import { Trans, useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import sanitizeHtml from 'sanitize-html'import { DOCS_URL, PLAN_LIMITS, TRIAL_DAYS, DISCORD_URL } from '~/lib/constants'diff --git a/web/app/components/marketing/WhySwitch.tsx b/web/app/components/marketing/WhySwitch.tsxindex eefebecc4..20fdd4fa6 100644--- a/web/app/components/marketing/WhySwitch.tsx+++ b/web/app/components/marketing/WhySwitch.tsx@@ -7,7 +7,7 @@ import {CaretRightIcon,} from '@phosphor-icons/react'import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { Text } from '~/ui/Text'import { cn } from '~/utils/generic'diff --git a/web/app/components/pricing/MarketingPricing.tsx b/web/app/components/pricing/MarketingPricing.tsxindex 1cb9aec5d..f9727597d 100644--- a/web/app/components/pricing/MarketingPricing.tsx+++ b/web/app/components/pricing/MarketingPricing.tsx@@ -3,7 +3,7 @@ import _round from 'lodash/round'import { ArrowRightIcon, QuestionIcon, CheckIcon } from '@phosphor-icons/react'import { useState, useMemo } from 'react'import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import {CURRENCIES,diff --git a/web/app/entry.client.tsx b/web/app/entry.client.tsxindex bd0a87b4c..ee9983917 100644--- a/web/app/entry.client.tsx+++ b/web/app/entry.client.tsx@@ -7,7 +7,7 @@ import { I18nextProvider, initReactI18next } from 'react-i18next'import { HydratedRouter } from 'react-router/dom'import { getInitialNamespaces } from 'remix-i18next/client'-import { I18N_CACHE_BREAKER } from '~/lib/constants'+import { I18N_CACHE_BREAKER, getLangFromPath } from '~/lib/constants'import i18n from './i18n'@@ -58,6 +58,11 @@ window.addEventListener('unhandledrejection', (event) => {})async function hydrate() {+ // The path is the source of truth for language now (/de/page > <html lang>).+ // We still fall back to the htmlTag detector for unprefixed pages where the+ // server-rendered <html lang="..."> reflects the cookie / Accept-Language.+ const pathLang = getLangFromPath(window.location.pathname)+// eslint-disable-next-line import/no-named-as-default-memberawait i18next.use(initReactI18next)@@ -66,6 +71,7 @@ async function hydrate() {.init({...i18n,ns: getInitialNamespaces(),+ ...(pathLang ? { lng: pathLang } : {}),backend: { loadPath: `/locales/{{lng}}.json?cv=${I18N_CACHE_BREAKER}` },detection: {order: ['htmlTag'],diff --git a/web/app/i18n.ts b/web/app/i18n.tsindex 2f63138a3..450a4a873 100644--- a/web/app/i18n.ts+++ b/web/app/i18n.ts@@ -1,7 +1,13 @@import { InitOptions } from 'i18next'import _includes from 'lodash/includes'-import { defaultLanguage, I18N_CACHE_BREAKER, whitelist } from '~/lib/constants'+import {+ defaultLanguage,+ getLangFromPath,+ I18N_CACHE_BREAKER,+ localisePath,+ whitelist,+} from '~/lib/constants'import { trackCustom } from '~/utils/analytics'import { setCookie } from '~/utils/cookie'@@ -19,9 +25,16 @@ const genericConfig: InitOptions = {}export function detectLanguage(request: Request): string {- // Stage 1: Getting the language from the query ?lng= parameterconst url = new URL(request.url)+ // Stage 1: Getting the language from the URL path prefix (/de/page).+ const pathLang = getLangFromPath(url.pathname)+ if (pathLang) {+ return pathLang+ }++ // Stage 2: Legacy ?lng= query parameter (kept so old links keep working+ // in the rare cases we don't redirect them to the path-based URL).if (url.searchParams.has('lng') &&_includes(whitelist, url.searchParams.get('lng'))@@ -29,15 +42,14 @@ export function detectLanguage(request: Request): string {return url.searchParams.get('lng') as string}- // Stage 2: Getting the language from the cookie+ // Stage 3: Cookie set the last time the user changed language.const cookie = request.headers.get('Cookie')const cookieLng = cookie?.match(/(?<=i18next=)[^;]*/)?.[0]-if (_includes(whitelist, cookieLng)) {return cookieLng as string}- // Stage 3: Getting the language from the Accept-Language header or fallback to default+ // Stage 4: Accept-Language header.if (request.headers.has('accept-language') &&_includes(whitelist, request.headers.get('accept-language'))@@ -45,14 +57,24 @@ export function detectLanguage(request: Request): string {return request.headers.get('accept-language') as string}- // Stage 4: Fallback to default+ // Stage 5: Fallback to the default language.return defaultLanguage}export const changeLanguage = (language: string) => {setCookie('i18next', language, 31536000, 'lax')trackCustom('CHANGE_LANGUAGE', { language })- window.location.reload()++ if (typeof window === 'undefined') return++ const { pathname, search, hash } = window.location+ const target = `${localisePath(pathname, language)}${search}${hash}`++ if (target === `${pathname}${search}${hash}`) {+ window.location.reload()+ } else {+ window.location.assign(target)+ }}export default genericConfigdiff --git a/web/app/lib/constants/index.ts b/web/app/lib/constants/index.tsindex 070917ba4..27b083efb 100644--- a/web/app/lib/constants/index.ts+++ b/web/app/lib/constants/index.ts@@ -467,6 +467,65 @@ export const paddleLanguageMapping = {uk: 'en',} as Record<string, string>+// Languages that get a URL prefix (/{lang}/...). The default language is served unprefixed.+export const localisedLanguages = whitelist.filter(+ (lng) => lng !== defaultLanguage,+)++// Pathname patterns that should NEVER receive a language prefix.+// Blog and blog-style content (rendered through routes/$.tsx) stays unlocalised,+// as do API routes and other internal endpoints.+const UNLOCALISED_PATH_PATTERNS: RegExp[] = [+ /^\/blog(\/|$)/,+ /^\/api(\/|$)/,+ /^\/backend(\/|$)/,+ /^\/_internal_data/,+ /^\/sitemap[^/]*\.xml$/,+ /^\/robots\.txt$/,+ /^\/ping$/,+ /^\/favicon/,+ /^\/locales\//,+ /^\/assets\//,+]++export const isUnlocalisedPath = (pathname: string): boolean =>+ UNLOCALISED_PATH_PATTERNS.some((re) => re.test(pathname))++// If the pathname starts with /{whitelisted-lang}, return that language code,+// otherwise null. The default language is never present in the path.+export const getLangFromPath = (pathname: string): string | null => {+ const match = pathname.match(/^\/([^/]+)(?:\/|$)/)+ if (!match) return null+ const candidate = match[1]+ if (candidate === defaultLanguage) return null+ if (localisedLanguages.includes(candidate)) return candidate+ return null+}++export const stripLangFromPath = (pathname: string): string => {+ const lang = getLangFromPath(pathname)+ if (!lang) return pathname+ const stripped = pathname.slice(`/${lang}`.length)+ return stripped.length === 0 ? '/' : stripped+}++// Build the canonical URL pathname for a given language. The default language+// is served unprefixed; other languages get a /{lang} prefix unless the path+// is one of the always-unprefixed routes (blog, api, etc.).+export const localisePath = (pathname: string, lang: string): string => {+ if (!pathname.startsWith('/')) return pathname++ const unprefixed = stripLangFromPath(pathname)++ if (isUnlocalisedPath(unprefixed)) return unprefixed+ if (lang === defaultLanguage || !localisedLanguages.includes(lang)) {+ return unprefixed+ }++ if (unprefixed === '/') return `/${lang}`+ return `/${lang}${unprefixed}`+}+// Increase this counter every time some major change is done within localisation files// This will prevent cached version or raw locale strings being displayed in productionexport const I18N_CACHE_BREAKER = 37diff --git a/web/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsx b/web/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsxindex c4d313238..9ae0c3132 100644--- a/web/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsx+++ b/web/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsx@@ -1,6 +1,7 @@import React, { useEffect } from 'react'import { useTranslation, Trans } from 'react-i18next'-import { Link, Form, useActionData, useNavigation } from 'react-router'+import { Link } from '~/ui/Link'+import { Form, useActionData, useNavigation } from 'react-router'import { toast } from 'sonner'import type { CreateNewPasswordActionData } from '~/routes/password-reset.$id'diff --git a/web/app/pages/Auth/ForgotPassword/ForgotPassword.tsx b/web/app/pages/Auth/ForgotPassword/ForgotPassword.tsxindex cb56d1ba8..c2555fb9f 100644--- a/web/app/pages/Auth/ForgotPassword/ForgotPassword.tsx+++ b/web/app/pages/Auth/ForgotPassword/ForgotPassword.tsx@@ -1,7 +1,7 @@import React, { useEffect } from 'react'import { useTranslation, Trans } from 'react-i18next'+import { Link } from '~/ui/Link'import {- Link,Form,useActionData,useNavigation,diff --git a/web/app/pages/Auth/Signin/Signin.tsx b/web/app/pages/Auth/Signin/Signin.tsxindex 0fe277175..4738f9ad7 100644--- a/web/app/pages/Auth/Signin/Signin.tsx+++ b/web/app/pages/Auth/Signin/Signin.tsx@@ -1,7 +1,7 @@import React, { useState, memo, useEffect } from 'react'import { useTranslation, Trans } from 'react-i18next'+import { Link } from '~/ui/Link'import {- Link,useNavigate,useSearchParams,Form,diff --git a/web/app/pages/Auth/Signup/InvitationSignup.tsx b/web/app/pages/Auth/Signup/InvitationSignup.tsxindex 6222f3e9b..4947b0c55 100644--- a/web/app/pages/Auth/Signup/InvitationSignup.tsx+++ b/web/app/pages/Auth/Signup/InvitationSignup.tsx@@ -1,13 +1,8 @@import { ArrowRightIcon } from '@phosphor-icons/react'import React, { useState, useEffect, memo } from 'react'import { useTranslation, Trans } from 'react-i18next'-import {- Link,- Form,- useActionData,- useNavigation,- useLoaderData,-} from 'react-router'+import { Link } from '~/ui/Link'+import { Form, useActionData, useNavigation, useLoaderData } from 'react-router'import { toast } from 'sonner'import { HAVE_I_BEEN_PWNED_URL, isSelfhosted } from '~/lib/constants'diff --git a/web/app/pages/Auth/Signup/Signup.tsx b/web/app/pages/Auth/Signup/Signup.tsxindex ccf40093c..20f2ce5f3 100644--- a/web/app/pages/Auth/Signup/Signup.tsx+++ b/web/app/pages/Auth/Signup/Signup.tsx@@ -7,13 +7,8 @@ import {} from '@phosphor-icons/react'import React, { useState, useEffect, memo } from 'react'import { useTranslation, Trans } from 'react-i18next'-import {- Link,- useNavigate,- Form,- useActionData,- useNavigation,-} from 'react-router'+import { Link } from '~/ui/Link'+import { useNavigate, Form, useActionData, useNavigation } from 'react-router'import { toast } from 'sonner'import GithubAuth from '~/components/GithubAuth'diff --git a/web/app/pages/Blog/Post.tsx b/web/app/pages/Blog/Post.tsxindex 2508586eb..60e7ccdda 100644--- a/web/app/pages/Blog/Post.tsx+++ b/web/app/pages/Blog/Post.tsx@@ -1,7 +1,8 @@import { CaretLeftIcon } from '@phosphor-icons/react'import { useEffect, useRef } from 'react'import { useTranslation } from 'react-i18next'-import { Link, useLoaderData, useLocation } from 'react-router'+import { Link } from '~/ui/Link'+import { useLoaderData, useLocation } from 'react-router'import ExitIntentPopup from '~/components/ExitIntentPopup'import NotFound from '~/pages/NotFound'diff --git a/web/app/pages/Captcha/index.tsx b/web/app/pages/Captcha/index.tsxindex e4074e32d..6faa28b58 100644--- a/web/app/pages/Captcha/index.tsx+++ b/web/app/pages/Captcha/index.tsx@@ -8,7 +8,7 @@ import {import _map from 'lodash/map'import { useEffect, useState } from 'react'import { useTranslation, Trans } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import Header from '~/components/Header'import { DitchGoogle } from '~/components/marketing/DitchGoogle'diff --git a/web/app/pages/Dashboard/ProjectCard.tsx b/web/app/pages/Dashboard/ProjectCard.tsxindex 6faebe2d0..24c37f3bc 100644--- a/web/app/pages/Dashboard/ProjectCard.tsx+++ b/web/app/pages/Dashboard/ProjectCard.tsx@@ -11,7 +11,8 @@ import {} from '@phosphor-icons/react'import React, { useState, useMemo, useCallback, useEffect, useRef } from 'react'import { useTranslation } from 'react-i18next'-import { Link, useFetcher, useNavigate } from 'react-router'+import { Link } from '~/ui/Link'+import { useFetcher, useNavigate } from 'react-router'import { toast } from 'sonner'import { OverallObject, Project } from '~/lib/models/Project'diff --git a/web/app/pages/ErrorTracking/index.tsx b/web/app/pages/ErrorTracking/index.tsxindex 90443da88..bf148e2b3 100644--- a/web/app/pages/ErrorTracking/index.tsx+++ b/web/app/pages/ErrorTracking/index.tsx@@ -1,7 +1,7 @@import { ArrowRightIcon } from '@phosphor-icons/react'import _map from 'lodash/map'import { useTranslation, Trans } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import Header from '~/components/Header'import { DitchGoogle } from '~/components/marketing/DitchGoogle'diff --git a/web/app/pages/Landings/Marketers.tsx b/web/app/pages/Landings/Marketers.tsxindex a78ac194f..270ce2bd9 100644--- a/web/app/pages/Landings/Marketers.tsx+++ b/web/app/pages/Landings/Marketers.tsx@@ -1,7 +1,7 @@import { ArrowRightIcon } from '@phosphor-icons/react'import _map from 'lodash/map'import { useTranslation, Trans } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import Header from '~/components/Header'import { ComparisonTable } from '~/components/marketing/ComparisonTable'diff --git a/web/app/pages/Landings/SmallBusinesses.tsx b/web/app/pages/Landings/SmallBusinesses.tsxindex 23e3f9bda..57832f082 100644--- a/web/app/pages/Landings/SmallBusinesses.tsx+++ b/web/app/pages/Landings/SmallBusinesses.tsx@@ -1,7 +1,7 @@import { ArrowRightIcon } from '@phosphor-icons/react'import _map from 'lodash/map'import { useTranslation, Trans } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import Header from '~/components/Header'import { ComparisonTable } from '~/components/marketing/ComparisonTable'diff --git a/web/app/pages/Landings/Startups.tsx b/web/app/pages/Landings/Startups.tsxindex cf8ec789a..979c100e1 100644--- a/web/app/pages/Landings/Startups.tsx+++ b/web/app/pages/Landings/Startups.tsx@@ -1,7 +1,7 @@import { ArrowRightIcon } from '@phosphor-icons/react'import _map from 'lodash/map'import { useTranslation, Trans } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import Header from '~/components/Header'import { ComparisonTable } from '~/components/marketing/ComparisonTable'diff --git a/web/app/pages/NotFound/index.tsx b/web/app/pages/NotFound/index.tsxindex 37e026dbb..223baf307 100644--- a/web/app/pages/NotFound/index.tsx+++ b/web/app/pages/NotFound/index.tsx@@ -1,5 +1,5 @@import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { isSelfhosted } from '~/lib/constants'import { Text } from '~/ui/Text'diff --git a/web/app/pages/OpenStartup/index.tsx b/web/app/pages/OpenStartup/index.tsxindex 14019d0d4..a00d51d92 100644--- a/web/app/pages/OpenStartup/index.tsx+++ b/web/app/pages/OpenStartup/index.tsx@@ -2,7 +2,7 @@import billboard, { bar, line } from 'billboard.js'import { useEffect } from 'react'import { useTranslation, Trans } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { LIVE_DEMO_URL } from '~/lib/constants'import { Stats } from '~/lib/models/Stats'diff --git a/web/app/pages/Organisations/OrganisationCard.tsx b/web/app/pages/Organisations/OrganisationCard.tsxindex dac21a062..654d53835 100644--- a/web/app/pages/Organisations/OrganisationCard.tsx+++ b/web/app/pages/Organisations/OrganisationCard.tsx@@ -6,7 +6,8 @@ import _size from 'lodash/size'import { SlidersHorizontalIcon } from '@phosphor-icons/react'import React, { useState, useMemo, useEffect } from 'react'import { useTranslation } from 'react-i18next'-import { Link, useFetcher } from 'react-router'+import { Link } from '~/ui/Link'+import { useFetcher } from 'react-router'import { DetailedOrganisation } from '~/lib/models/Organisation'import { useAuth } from '~/providers/AuthProvider'diff --git a/web/app/pages/Organisations/Settings/Projects.tsx b/web/app/pages/Organisations/Settings/Projects.tsxindex d59ced6c2..b0d380859 100644--- a/web/app/pages/Organisations/Settings/Projects.tsx+++ b/web/app/pages/Organisations/Settings/Projects.tsx@@ -10,7 +10,8 @@ import _map from 'lodash/map'import _replace from 'lodash/replace'import { useState, useEffect, useMemo } from 'react'import { useTranslation } from 'react-i18next'-import { Link, useFetcher } from 'react-router'+import { Link } from '~/ui/Link'+import { useFetcher } from 'react-router'import { toast } from 'sonner'import useDebounce from '~/hooks/useDebounce'diff --git a/web/app/pages/Organisations/Settings/index.tsx b/web/app/pages/Organisations/Settings/index.tsxindex dd1acb314..d376bc59e 100644--- a/web/app/pages/Organisations/Settings/index.tsx+++ b/web/app/pages/Organisations/Settings/index.tsx@@ -12,8 +12,8 @@ import {} from '@phosphor-icons/react'import React, { useState, useEffect, useMemo } from 'react'import { useTranslation } from 'react-i18next'+import { Link } from '~/ui/Link'import {- Link,useNavigate,useFetcher,useLoaderData,diff --git a/web/app/pages/Performance/index.tsx b/web/app/pages/Performance/index.tsxindex eb2b3fef0..ee8b8e281 100644--- a/web/app/pages/Performance/index.tsx+++ b/web/app/pages/Performance/index.tsx@@ -1,7 +1,7 @@import { ArrowRightIcon } from '@phosphor-icons/react'import _map from 'lodash/map'import { useTranslation, Trans } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import Header from '~/components/Header'import { DitchGoogle } from '~/components/marketing/DitchGoogle'diff --git a/web/app/pages/Project/Settings/Alerts/ProjectAlertsSettings.tsx b/web/app/pages/Project/Settings/Alerts/ProjectAlertsSettings.tsxindex b71a9c5b0..8c2cf82fe 100644--- a/web/app/pages/Project/Settings/Alerts/ProjectAlertsSettings.tsx+++ b/web/app/pages/Project/Settings/Alerts/ProjectAlertsSettings.tsx@@ -9,7 +9,8 @@ import _toNumber from 'lodash/toNumber'import _values from 'lodash/values'import React, { useEffect, useMemo, useRef, useState } from 'react'import { useTranslation, Trans } from 'react-i18next'-import { Link, useFetcher } from 'react-router'+import { Link } from '~/ui/Link'+import { useFetcher } from 'react-router'import { toast } from 'sonner'import { QUERY_CONDITION, QUERY_METRIC, QUERY_TIME } from '~/lib/constants'diff --git a/web/app/pages/Project/Settings/Alerts/ProjectAlertsView.tsx b/web/app/pages/Project/Settings/Alerts/ProjectAlertsView.tsxindex fedd24977..64232362c 100644--- a/web/app/pages/Project/Settings/Alerts/ProjectAlertsView.tsx+++ b/web/app/pages/Project/Settings/Alerts/ProjectAlertsView.tsx@@ -19,7 +19,8 @@ import {} from '@phosphor-icons/react'import { useMemo, useState, useEffect, useRef } from 'react'import { useTranslation } from 'react-i18next'-import { Link, useSearchParams, useFetcher } from 'react-router'+import { Link } from '~/ui/Link'+import { useSearchParams, useFetcher } from 'react-router'import { toast } from 'sonner'import { QUERY_METRIC, PLAN_LIMITS, DEFAULT_ALERTS_TAKE } from '~/lib/constants'diff --git a/web/app/pages/Project/Settings/ProjectSettings.tsx b/web/app/pages/Project/Settings/ProjectSettings.tsxindex 3bb201352..3f25708dc 100644--- a/web/app/pages/Project/Settings/ProjectSettings.tsx+++ b/web/app/pages/Project/Settings/ProjectSettings.tsx@@ -9,6 +9,7 @@ import _map from 'lodash/map'import _replace from 'lodash/replace'import _size from 'lodash/size'import _toUpper from 'lodash/toUpper'+import { Link } from '~/ui/Link'import {SlidersHorizontalIcon,ShieldIcon,@@ -30,7 +31,6 @@ import { Trans, useTranslation } from 'react-i18next'import {useLoaderData,useNavigate,- Link,useSearchParams,useFetcher,} from 'react-router'diff --git a/web/app/pages/Project/View/Panels.tsx b/web/app/pages/Project/View/Panels.tsxindex fd709f537..9d69d1a3e 100644--- a/web/app/pages/Project/View/Panels.tsx+++ b/web/app/pages/Project/View/Panels.tsx@@ -36,7 +36,8 @@ import React, {} from 'react'import { useTranslation } from 'react-i18next'import { createPortal } from 'react-dom'-import { Link, LinkProps, useNavigate } from 'react-router'+import { Link } from '~/ui/Link'+import { LinkProps, useNavigate } from 'react-router'import { useProjectDataCustomEventsProxy } from '~/hooks/useAnalyticsProxy'import { PROJECT_TABS } from '~/lib/constants'diff --git a/web/app/pages/Project/View/components/BackButton.tsx b/web/app/pages/Project/View/components/BackButton.tsxindex 43fff9955..38af9b257 100644--- a/web/app/pages/Project/View/components/BackButton.tsx+++ b/web/app/pages/Project/View/components/BackButton.tsx@@ -1,6 +1,6 @@import { CaretLeftIcon } from '@phosphor-icons/react'import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { cn } from '~/utils/generic'diff --git a/web/app/pages/Project/View/components/Filters.tsx b/web/app/pages/Project/View/components/Filters.tsxindex d9314989a..e6ad25983 100644--- a/web/app/pages/Project/View/components/Filters.tsx+++ b/web/app/pages/Project/View/components/Filters.tsx@@ -6,7 +6,8 @@ import _truncate from 'lodash/truncate'import { FunnelIcon, XIcon } from '@phosphor-icons/react'import { memo, MouseEvent, useMemo } from 'react'import { useTranslation } from 'react-i18next'-import { Link, useSearchParams } from 'react-router'+import { Link } from '~/ui/Link'+import { useSearchParams } from 'react-router'import { getLocaleDisplayName, cn } from '~/utils/generic'import countries from '~/utils/isoCountries'diff --git a/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx b/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsxindex 7823b5317..429c34afa 100644--- a/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx+++ b/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx@@ -2,7 +2,7 @@ import { CaretDownIcon, XIcon } from '@phosphor-icons/react'import _map from 'lodash/map'import React, { useState } from 'react'import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import type { LiveVisitorInfo } from '~/api/api.server'import { useLiveVisitorsProxy } from '~/hooks/useAnalyticsProxy'diff --git a/web/app/pages/Project/View/components/LockedDashboard.tsx b/web/app/pages/Project/View/components/LockedDashboard.tsxindex ed8ebdc99..6420f8728 100644--- a/web/app/pages/Project/View/components/LockedDashboard.tsx+++ b/web/app/pages/Project/View/components/LockedDashboard.tsx@@ -1,7 +1,7 @@import { LockIcon } from '@phosphor-icons/react'import { useMemo } from 'react'import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { DashboardBlockReason } from '~/lib/models/User'import { useAuth } from '~/providers/AuthProvider'diff --git a/web/app/pages/Project/View/components/PasswordRequiredModal.tsx b/web/app/pages/Project/View/components/PasswordRequiredModal.tsxindex 28f57c109..5d8e84a96 100644--- a/web/app/pages/Project/View/components/PasswordRequiredModal.tsx+++ b/web/app/pages/Project/View/components/PasswordRequiredModal.tsx@@ -3,7 +3,7 @@ import _isEmpty from 'lodash/isEmpty'import _size from 'lodash/size'import { useState, useEffect, useCallback, FormEvent } from 'react'import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import Button from '~/ui/Button'import Input from '~/ui/Input'diff --git a/web/app/pages/Project/View/components/ProjectSidebar.tsx b/web/app/pages/Project/View/components/ProjectSidebar.tsxindex fb3cb95c8..72b1aa2ad 100644--- a/web/app/pages/Project/View/components/ProjectSidebar.tsx+++ b/web/app/pages/Project/View/components/ProjectSidebar.tsx@@ -17,7 +17,8 @@ import React, {memo,} from 'react'import { useTranslation } from 'react-i18next'-import { Link, LinkProps } from 'react-router'+import { Link } from '~/ui/Link'+import { LinkProps } from 'react-router'import { PROJECT_TABS } from '~/lib/constants'import { Text } from '~/ui/Text'diff --git a/web/app/pages/Project/View/components/WaitingForAnEvent.tsx b/web/app/pages/Project/View/components/WaitingForAnEvent.tsxindex a10b020ef..f8eec0e5c 100644--- a/web/app/pages/Project/View/components/WaitingForAnEvent.tsx+++ b/web/app/pages/Project/View/components/WaitingForAnEvent.tsx@@ -1,5 +1,5 @@import { Trans, useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { useCurrentProject } from '~/providers/CurrentProjectProvider'import PulsatingCircle from '~/ui/icons/PulsatingCircle'diff --git a/web/app/pages/Project/tabs/Captcha/WaitingForCaptchaEvent.tsx b/web/app/pages/Project/tabs/Captcha/WaitingForCaptchaEvent.tsxindex 3c97cbc3e..e002710ae 100644--- a/web/app/pages/Project/tabs/Captcha/WaitingForCaptchaEvent.tsx+++ b/web/app/pages/Project/tabs/Captcha/WaitingForCaptchaEvent.tsx@@ -1,5 +1,5 @@import { Trans, useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { useCurrentProject } from '~/providers/CurrentProjectProvider'import CaptchaSetup from '~/ui/CaptchaSetup'diff --git a/web/app/pages/Project/tabs/Errors/ErrorDetails.tsx b/web/app/pages/Project/tabs/Errors/ErrorDetails.tsxindex b3c12c5eb..7c3c26345 100644--- a/web/app/pages/Project/tabs/Errors/ErrorDetails.tsx+++ b/web/app/pages/Project/tabs/Errors/ErrorDetails.tsx@@ -13,7 +13,8 @@ import {} from '@phosphor-icons/react'import { useMemo, useState, useEffect, useCallback, useRef } from 'react'import { useTranslation } from 'react-i18next'-import { Link, useLocation } from 'react-router'+import { Link } from '~/ui/Link'+import { useLocation } from 'react-router'import type {ErrorAffectedSession,diff --git a/web/app/pages/Project/tabs/Errors/ErrorsView.tsx b/web/app/pages/Project/tabs/Errors/ErrorsView.tsxindex dab09e94b..1d6701334 100644--- a/web/app/pages/Project/tabs/Errors/ErrorsView.tsx+++ b/web/app/pages/Project/tabs/Errors/ErrorsView.tsx@@ -26,8 +26,8 @@ import {use,} from 'react'import { useTranslation } from 'react-i18next'+import { Link } from '~/ui/Link'import {- Link,useLocation,useSearchParams,useNavigate,diff --git a/web/app/pages/Project/tabs/Errors/WaitingForAnError.tsx b/web/app/pages/Project/tabs/Errors/WaitingForAnError.tsxindex 004a9b9e4..02f78998a 100644--- a/web/app/pages/Project/tabs/Errors/WaitingForAnError.tsx+++ b/web/app/pages/Project/tabs/Errors/WaitingForAnError.tsx@@ -1,6 +1,6 @@import { WarningIcon } from '@phosphor-icons/react'import { Trans, useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { ERROR_TRACKING_DOCS_URL } from '~/lib/constants'import { Text } from '~/ui/Text'diff --git a/web/app/pages/Project/tabs/Experiments/ExperimentsView.tsx b/web/app/pages/Project/tabs/Experiments/ExperimentsView.tsxindex 5d1c89967..7a6c7ccbf 100644--- a/web/app/pages/Project/tabs/Experiments/ExperimentsView.tsx+++ b/web/app/pages/Project/tabs/Experiments/ExperimentsView.tsx@@ -17,7 +17,8 @@ import {} from '@phosphor-icons/react'import { useState, useEffect, useMemo, useRef, useCallback, memo } from 'react'import { useTranslation } from 'react-i18next'-import { Link, useFetcher, useLocation, useSearchParams } from 'react-router'+import { Link } from '~/ui/Link'+import { useFetcher, useLocation, useSearchParams } from 'react-router'import { toast } from 'sonner'import DashboardHeader from '~/pages/Project/View/components/DashboardHeader'diff --git a/web/app/pages/Project/tabs/FeatureFlags/FeatureFlagsView.tsx b/web/app/pages/Project/tabs/FeatureFlags/FeatureFlagsView.tsxindex ea2aa5fa6..687c5a800 100644--- a/web/app/pages/Project/tabs/FeatureFlags/FeatureFlagsView.tsx+++ b/web/app/pages/Project/tabs/FeatureFlags/FeatureFlagsView.tsx@@ -28,8 +28,8 @@ import {use,} from 'react'import { useTranslation } from 'react-i18next'+import { Link } from '~/ui/Link'import {- Link,useLocation,useSearchParams,useFetcher,diff --git a/web/app/pages/Project/tabs/Funnels/FunnelsList.tsx b/web/app/pages/Project/tabs/Funnels/FunnelsList.tsxindex 142893a64..4f4319ed7 100644--- a/web/app/pages/Project/tabs/Funnels/FunnelsList.tsx+++ b/web/app/pages/Project/tabs/Funnels/FunnelsList.tsx@@ -10,7 +10,8 @@ import {} from '@phosphor-icons/react'import { useMemo, useRef } from 'react'import { useTranslation } from 'react-i18next'-import { Link, useSearchParams } from 'react-router'+import { Link } from '~/ui/Link'+import { useSearchParams } from 'react-router'import { Funnel } from '~/lib/models/Project'import { useAuth } from '~/providers/AuthProvider'diff --git a/web/app/pages/Project/tabs/Funnels/FunnelsView.tsx b/web/app/pages/Project/tabs/Funnels/FunnelsView.tsxindex 541fa1227..3d7d8968a 100644--- a/web/app/pages/Project/tabs/Funnels/FunnelsView.tsx+++ b/web/app/pages/Project/tabs/Funnels/FunnelsView.tsx@@ -14,8 +14,8 @@ import {use,} from 'react'import { useTranslation } from 'react-i18next'+import { Link } from '~/ui/Link'import {- Link,useSearchParams,useFetcher,useLoaderData,diff --git a/web/app/pages/Project/tabs/Profiles/Profiles.tsx b/web/app/pages/Project/tabs/Profiles/Profiles.tsxindex 06e7f6b73..57fa62596 100644--- a/web/app/pages/Project/tabs/Profiles/Profiles.tsx+++ b/web/app/pages/Project/tabs/Profiles/Profiles.tsx@@ -11,7 +11,8 @@ import {} from '@phosphor-icons/react'import React, { useMemo } from 'react'import { useTranslation } from 'react-i18next'-import { Link, useLocation } from 'react-router'+import { Link } from '~/ui/Link'+import { useLocation } from 'react-router'import { ClientOnly } from 'remix-utils/client-only'import { BrowserIcon, OSIcon } from '../SharedIcons'diff --git a/web/app/pages/Project/tabs/SEO/SEOView.tsx b/web/app/pages/Project/tabs/SEO/SEOView.tsxindex 17ab90890..3c45c111b 100644--- a/web/app/pages/Project/tabs/SEO/SEOView.tsx+++ b/web/app/pages/Project/tabs/SEO/SEOView.tsx@@ -20,7 +20,8 @@ import React, {useState,} from 'react'import { Trans, useTranslation } from 'react-i18next'-import { Link, useLoaderData, useSearchParams } from 'react-router'+import { Link } from '~/ui/Link'+import { useLoaderData, useSearchParams } from 'react-router'import { useGSCDashboardProxy } from '~/hooks/useAnalyticsProxy'import type { TimeBucket } from '~/lib/constants'diff --git a/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsx b/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsxindex 328ca7602..5af94fb18 100644--- a/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsx+++ b/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsx@@ -14,7 +14,7 @@ import {} from '@phosphor-icons/react'import { useMemo, useState } from 'react'import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import {BROWSER_LOGO_MAP,diff --git a/web/app/pages/Project/tabs/Sessions/Sessions.tsx b/web/app/pages/Project/tabs/Sessions/Sessions.tsxindex 03d3b1476..4052624b7 100644--- a/web/app/pages/Project/tabs/Sessions/Sessions.tsx+++ b/web/app/pages/Project/tabs/Sessions/Sessions.tsx@@ -11,7 +11,8 @@ import {} from '@phosphor-icons/react'import React, { useMemo } from 'react'import { useTranslation } from 'react-i18next'-import { Link, useLocation } from 'react-router'+import { Link } from '~/ui/Link'+import { useLocation } from 'react-router'import { ClientOnly } from 'remix-utils/client-only'import { BrowserIcon, OSIcon } from '../SharedIcons'diff --git a/web/app/root.tsx b/web/app/root.tsxindex 4e4b71ee9..eec3baf0d 100644--- a/web/app/root.tsx+++ b/web/app/root.tsx@@ -39,6 +39,11 @@ import {isDevelopment,MAIN_URL,defaultLanguage,+ localisePath,+ isUnlocalisedPath,+ whitelist,+ stripLangFromPath,+ getLangFromPath,} from '~/lib/constants'import mainCss from '~/styles/index.css?url'import tailwindCss from '~/styles/tailwind.css?url'@@ -274,6 +279,57 @@ const removeMultipleLngParams = (url: string): string => {return _replace(url, /%3Flng%3D[^%]*/g, '')}+const readCookieLang = (request: Request): string | null => {+ const cookie = request.headers.get('Cookie')+ const match = cookie?.match(/(?<=i18next=)[^;]*/)?.[0]+ return match && whitelist.includes(match) ? match : null+}++// Decides whether to redirect an unprefixed URL to its localised counterpart+// so the URL is always the source of truth for the rendered language.+//+// Priority of "preferred language" signals:+// 1. Legacy `?lng=xx` query (301 β canonical migration of old links)+// 2. `i18next` cookie set by the language switcher (302 β per-user pref)+//+// We deliberately ignore `Accept-Language` here to avoid surprise redirects+// for bots, link previews, and shared screenshots.+const buildLocaliseRedirect = (+ request: Request,+ urlObject: URL,+): { url: string; status: 301 | 302 } | null => {+ const { searchParams, pathname } = urlObject++ // Already on a localised URL, or a path that should never be prefixed.+ if (getLangFromPath(pathname)) return null+ if (isUnlocalisedPath(pathname)) return null++ // /en/dashboard β /dashboard (default lang should never be prefixed).+ const firstSegment = pathname.match(/^\/([^/]+)(\/.*)?$/)+ if (firstSegment && firstSegment[1] === defaultLanguage) {+ const next = new URL(urlObject.toString())+ next.pathname = firstSegment[2] || '/'+ return { url: next.toString(), status: 301 }+ }++ const lngQuery = searchParams.get('lng')+ if (lngQuery && whitelist.includes(lngQuery)) {+ const next = new URL(urlObject.toString())+ next.searchParams.delete('lng')+ next.pathname = localisePath(pathname, lngQuery)+ return { url: next.toString(), status: 301 }+ }++ const cookieLng = readCookieLang(request)+ if (cookieLng && cookieLng !== defaultLanguage) {+ const next = new URL(urlObject.toString())+ next.pathname = localisePath(pathname, cookieLng)+ return { url: next.toString(), status: 302 }+ }++ return null+}+export async function loader({ request }: LoaderFunctionArgs) {const { url } = requestconst removedLng = removeMultipleLngParams(url)@@ -290,6 +346,11 @@ export async function loader({ request }: LoaderFunctionArgs) {return redirect(httpToHttps, 301)}+ const localiseRedirect = buildLocaliseRedirect(request, urlObject)+ if (localiseRedirect) {+ return redirect(localiseRedirect.url, localiseRedirect.status)+ }+const locale = detectLanguage(request)const theme = detectTheme(request)const hasTokens = hasAuthTokens(request)@@ -368,24 +429,21 @@ const Body = () => {}export default function App() {- const { locale, url, theme, REMIX_ENV } = useLoaderData<typeof loader>()+ const { locale, theme, REMIX_ENV } = useLoaderData<typeof loader>()const { pathname, search } = useLocation()const { i18n } = useTranslation('common')const [searchParams] = useSearchParams()- const urlObject = new URL(url)- urlObject.searchParams.delete('lng')-const isEmbedded = searchParams.get('embedded') === 'true'const canonicalUrl = (() => {- const url = new URL(`${MAIN_URL}${pathname}${search}`)- if (i18n.language === defaultLanguage) {- url.searchParams.delete('lng')- } else {- url.searchParams.set('lng', i18n.language)- }- return url.toString()+ const localisedPathname = localisePath(+ stripLangFromPath(pathname),+ i18n.language || defaultLanguage,+ )+ const next = new URL(`${MAIN_URL}${localisedPathname}${search}`)+ next.searchParams.delete('lng')+ return next.toString()})()return (diff --git a/web/app/routes.ts b/web/app/routes.tsindex d9f288d5a..07eddce55 100644--- a/web/app/routes.ts+++ b/web/app/routes.ts@@ -1,3 +1,71 @@import { flatRoutes } from '@react-router/fs-routes'+import type { RouteConfigEntry } from '@react-router/dev/routes'-export default flatRoutes()+import { localisedLanguages } from './lib/constants'++// Routes that should always stay unprefixed (no /{lang}/... variant).+// Blog content (and the catch-all that powers blog-style pages such as+// /imprint, /comparisons/* etc. through routes/$.tsx) keeps its canonical+// English URL so we don't fragment the SEO of long-form content.+// API and internal endpoints obviously have no localisation either.+const UNPREFIXED_PATH_PATTERNS: RegExp[] = [+ /^blog(\/|$)/,+ /^api(\/|$)/,+ /^backend(\/|$)/,+ /^_internal_data/,+ /^ping$/,+ /\.txt$/,+ /\.xml$/,+]++const isUnprefixedPath = (path: string | undefined): boolean => {+ if (path === '*' || path === undefined) return path === '*'+ return UNPREFIXED_PATH_PATTERNS.some((re) => re.test(path))+}++const cloneSubtreeIds = (+ entry: RouteConfigEntry,+ lang: string,+): RouteConfigEntry => {+ const baseId = entry.id ?? entry.file+ return {+ ...entry,+ id: `${lang}.${baseId}`,+ children: entry.children?.map((c) => cloneSubtreeIds(c, lang)),+ }+}++const cloneTopLevelForLanguage = (+ entry: RouteConfigEntry,+ lang: string,+): RouteConfigEntry => {+ const baseId = entry.id ?? entry.file+ // For the root index route (no path, index: true) we surface it as /{lang}.+ // For all other routes we prepend /{lang}/ to the existing path.+ const newPath = entry.path ? `${lang}/${entry.path}` : lang++ return {+ ...entry,+ id: `${lang}.${baseId}`,+ path: newPath,+ index: undefined,+ children: entry.children?.map((c) => cloneSubtreeIds(c, lang)),+ }+}++const buildRoutes = async (): Promise<RouteConfigEntry[]> => {+ const baseRoutes = await flatRoutes()++ const localisableRoutes = baseRoutes.filter((r) => !isUnprefixedPath(r.path))++ const localisedRoutes: RouteConfigEntry[] = []+ for (const lang of localisedLanguages) {+ for (const r of localisableRoutes) {+ localisedRoutes.push(cloneTopLevelForLanguage(r, lang))+ }+ }++ return [...baseRoutes, ...localisedRoutes]+}++export default buildRoutes()diff --git a/web/app/routes/$.tsx b/web/app/routes/$.tsxindex dd384fb94..a90f9fecf 100644--- a/web/app/routes/$.tsx+++ b/web/app/routes/$.tsx@@ -1,9 +1,9 @@import { useTranslation } from 'react-i18next'import type { LoaderFunctionArgs, MetaFunction } from 'react-router'-import { data, useLoaderData } from 'react-router'+import { data, redirect, useLoaderData } from 'react-router'import type { SitemapFunction } from 'remix-sitemap'-import { getOgImageUrl } from '~/lib/constants'+import { getLangFromPath, getOgImageUrl } from '~/lib/constants'import Post from '~/pages/Blog/Post'import NotFound from '~/pages/NotFound'import { getPost } from '~/utils/getPosts.server'@@ -43,6 +43,18 @@ export async function loader({ request, params }: LoaderFunctionArgs) {return data(null, { status: 404 })}+ // Blog-style content (rendered through this catch-all) lives under canonical+ // unprefixed URLs. If someone hits /de/imprint, redirect them to /imprint+ // rather than 404'ing β the language is still picked up from the cookie.+ const lang = getLangFromPath(`/${catchAllPath}`)+ if (lang) {+ const stripped = catchAllPath.slice(`${lang}/`.length)+ if (stripped) {+ const url = new URL(request.url)+ return redirect(`/${stripped}${url.search}`, 301)+ }+ }+const post = await getPost(request, catchAllPath, undefined, true)if (post) {diff --git a/web/app/routes/_index.tsx b/web/app/routes/_index.tsxindex b40f2f693..98d9f3703 100644--- a/web/app/routes/_index.tsx+++ b/web/app/routes/_index.tsx@@ -11,7 +11,8 @@ import {import React from 'react'import { useTranslation, Trans } from 'react-i18next'import type { LoaderFunctionArgs, MetaFunction } from 'react-router'-import { Link, redirect, useLoaderData } from 'react-router'+import { Link } from '~/ui/Link'+import { redirect, useLoaderData } from 'react-router'import type { SitemapFunction } from 'remix-sitemap'import { ClientOnly } from 'remix-utils/client-only'@@ -24,6 +25,7 @@ import MarketingPricing from '~/components/pricing/MarketingPricing'import useBreakpoint from '~/hooks/useBreakpoint'import {LIVE_DEMO_URL,+ defaultLanguage,isSelfhosted,isDisableMarketingPages,} from '~/lib/constants'@@ -314,7 +316,7 @@ const LiveDemoPreview = () => {<div className='group relative -mr-6 ml-auto w-[140%] overflow-hidden rounded-2xl bg-gray-50 shadow-lg ring-1 ring-black/5 transition-shadow ease-out will-change-transform sm:-mr-12 sm:w-[160%] lg:-mr-16 lg:w-[180%] xl:-mr-24 2xl:-mr-32 dark:bg-slate-950 dark:ring-white/10'><div className='pointer-events-none relative h-[580px] lg:h-[640px] xl:h-[700px]'><iframe- src={`https://swetrix.com/projects/STEzHcB1rALV?tab=traffic&theme=${theme}&embedded=true&lng=${language}`}+ src={`https://swetrix.com${language === defaultLanguage ? '' : `/${language}`}/projects/STEzHcB1rALV?tab=traffic&theme=${theme}&embedded=true`}className='size-full'title='Swetrix Analytics Live Demo'style={{ pointerEvents: 'none' }}diff --git a/web/app/routes/blog._index.tsx b/web/app/routes/blog._index.tsxindex 203d708c3..952c612cc 100644--- a/web/app/routes/blog._index.tsx+++ b/web/app/routes/blog._index.tsx@@ -4,7 +4,8 @@ import _map from 'lodash/map'import { CaretRightIcon } from '@phosphor-icons/react'import { useTranslation } from 'react-i18next'import type { LoaderFunctionArgs, MetaFunction } from 'react-router'-import { redirect, Link, useLoaderData } from 'react-router'+import { Link } from '~/ui/Link'+import { redirect, useLoaderData } from 'react-router'import { getBlogPosts } from '~/api/api.server'import {diff --git a/web/app/routes/google-analytics-alternative.tsx b/web/app/routes/google-analytics-alternative.tsxindex 2b3a65840..8558d9fd2 100644--- a/web/app/routes/google-analytics-alternative.tsx+++ b/web/app/routes/google-analytics-alternative.tsx@@ -13,7 +13,8 @@ import {} from '@phosphor-icons/react'import { useTranslation, Trans } from 'react-i18next'import type { LoaderFunctionArgs, MetaFunction } from 'react-router'-import { Link, redirect, useLoaderData } from 'react-router'+import { Link } from '~/ui/Link'+import { redirect, useLoaderData } from 'react-router'import type { SitemapFunction } from 'remix-sitemap'import { ClientOnly } from 'remix-utils/client-only'diff --git a/web/app/routes/tools._index.tsx b/web/app/routes/tools._index.tsxindex f5fd17822..dff068550 100644--- a/web/app/routes/tools._index.tsx+++ b/web/app/routes/tools._index.tsx@@ -1,6 +1,7 @@import { ArrowRightIcon } from '@phosphor-icons/react'import type { MetaFunction } from 'react-router'-import { Link, redirect } from 'react-router'+import { Link } from '~/ui/Link'+import { redirect } from 'react-router'import type { SitemapFunction } from 'remix-sitemap'import { DitchGoogle } from '~/components/marketing/DitchGoogle'diff --git a/web/app/ui/Link.tsx b/web/app/ui/Link.tsxnew file mode 100644index 000000000..1c5545554--- /dev/null+++ b/web/app/ui/Link.tsx@@ -0,0 +1,22 @@+import { forwardRef } from 'react'+import { useTranslation } from 'react-i18next'+import { Link as RRLink, type LinkProps } from 'react-router'++import { defaultLanguage } from '~/lib/constants'+import { localiseTo } from '~/utils/i18nHref'++/**+ * Drop-in replacement for `react-router`'s `<Link>` that automatically+ * prepends the current language to absolute paths (e.g. `/dashboard` becomes+ * `/de/dashboard` when the active language is German).+ *+ * Routes that should never be language-prefixed (blog, api, etc.) are+ * handled inside `localisePath` and remain untouched.+ */+export const Link = forwardRef<HTMLAnchorElement, LinkProps>(+ function LocalisedLink({ to, ...props }, ref) {+ const { i18n } = useTranslation()+ const lang = i18n.language || defaultLanguage+ return <RRLink ref={ref} to={localiseTo(to, lang)} {...props} />+ },+)diff --git a/web/app/ui/StatusPage.tsx b/web/app/ui/StatusPage.tsxindex c8e533f12..a3bb6be23 100644--- a/web/app/ui/StatusPage.tsx+++ b/web/app/ui/StatusPage.tsx@@ -1,7 +1,7 @@import { CheckCircleIcon, XCircleIcon, InfoIcon } from '@phosphor-icons/react'import type { ReactNode } from 'react'import { useTranslation } from 'react-i18next'-import { Link } from 'react-router'+import { Link } from '~/ui/Link'import { cn } from '~/utils/generic'diff --git a/web/app/utils/i18nHref.ts b/web/app/utils/i18nHref.tsnew file mode 100644index 000000000..f13638f58--- /dev/null+++ b/web/app/utils/i18nHref.ts@@ -0,0 +1,36 @@+import type { Path, To } from 'react-router'++import { localisePath } from '~/lib/constants'++const localiseString = (href: string, lang: string): string => {+ if (!href.startsWith('/')) return href++ const hashIdx = href.indexOf('#')+ const queryIdx = href.indexOf('?')+ const splitIdx =+ hashIdx === -1+ ? queryIdx+ : queryIdx === -1+ ? hashIdx+ : Math.min(hashIdx, queryIdx)++ if (splitIdx === -1) {+ return localisePath(href, lang)+ }++ const pathname = href.slice(0, splitIdx)+ const rest = href.slice(splitIdx)+ return `${localisePath(pathname, lang)}${rest}`+}++export const localiseTo = (to: To, lang: string): To => {+ if (typeof to === 'string') {+ return localiseString(to, lang)+ }++ if (!to.pathname || !to.pathname.startsWith('/')) return to++ const next: Partial<Path> = { ...to }+ next.pathname = localisePath(to.pathname, lang)+ return next as To+}