Skip to content
TanStack Start i18n

TanStack Start i18n — Full-Stack Localization

Add internationalization to your TanStack Start app with SSR support, automatic locale detection, and type-safe translations that work on both client and server.

Package
lefine
Entry
lefine/react
lefine
01Terminal
npm install lefine
02app/routes/__root.tsx
// app/lib/strings.tsimport { createServerFn } from '@tanstack/react-start';import { createStrings } from 'lefine/server';const strings = createStrings({ project: 'app_3f9c0e4b2a7d4e1f9b6c5a8d7e2f1a0b' });// Runs on the server only. Returns plain JSON: { locale, messages, timeZone }.export const loadStrings = createServerFn({ method: 'GET' })  .validator((locale: string) => locale)  .handler(({ data: locale }) => strings.load(locale, ['common', 'pages']));// app/routes/__root.tsxexport const Route = createRootRoute({  loader: ({ context }) => loadStrings({ data: context.locale ?? 'en' }),});
03app/routes/about.tsx
// app/routes/about.tsximport { useStrings } from 'lefine/react';export default function AboutPage() {  const t = useStrings('pages');  return (    <main>      <h1>{t('about.title')}</h1>      <p>{t('about.description')}</p>    </main>  );}
t('about.title')
About us
01/Setup

Set up in 4 steps

  1. 01

    Install packages

    Install @better-i18n/use-intl and use-intl. No additional build plugins or Babel transforms required.

    terminalbash
    npm install lefine
  2. 02

    Load messages server-side

    Fetch translations in the root loader so they are available on the very first server render. No separate API call from the client.

    app/routes/__root.tsx
    // app/lib/strings.tsimport { createServerFn } from '@tanstack/react-start';import { createStrings } from 'lefine/server';const strings = createStrings({ project: 'app_3f9c0e4b2a7d4e1f9b6c5a8d7e2f1a0b' });// Runs on the server only. Returns plain JSON: { locale, messages, timeZone }.export const loadStrings = createServerFn({ method: 'GET' })  .validator((locale: string) => locale)  .handler(({ data: locale }) => strings.load(locale, ['common', 'pages']));// app/routes/__root.tsxexport const Route = createRootRoute({  loader: ({ context }) => loadStrings({ data: context.locale ?? 'en' }),});
  3. 03

    Wrap with BetterI18nProvider

    Pass the loader data into BetterI18nProvider. The provider hydrates the client with the same messages loaded on the server.

    app/routes/__root.tsx
    // app/routes/__root.tsx (continued)import { StringsProvider } from 'lefine/react';export function RootComponent() {  const props = Route.useLoaderData();  return (    <StringsProvider {...props}>      <Outlet />    </StringsProvider>  );}
  4. 04

    Use in routes

    Call useTranslations() in any route component. The same hook works during server rendering and in the browser.

    app/routes/about.tsx
    // app/routes/about.tsximport { useStrings } from 'lefine/react';export default function AboutPage() {  const t = useStrings('pages');  return (    <main>      <h1>{t('about.title')}</h1>      <p>{t('about.description')}</p>    </main>  );}
02/Capabilities

Why use Lefine with TanStack Start?

  • SSR hydration — server-loaded messages hydrate client without re-fetch
  • No content flash — translated content on the very first render
  • Dynamic locale — language list from CDN manifest, no hardcoding
  • Path-based routing — /tr/about, /de/about URL structure
  • Full-stack type safety — loader and component share the same type system
  • Cookie + header detection — URL → cookie → Accept-Language fallback chain
Get started

Start free.

Build a multilingual TanStack Start app

Manage all your translations in one dashboard with AI-powered suggestions, context-aware translations, and CDN delivery.