Introducing a new way to review your PRs.

Read the announcement

generaltranslation / gt

Full-stack localization for every framework

View on GitHub

22 documents · Updated Nov 23, 2026

docs / alternative-framework-integrations

Vue, React Native, and TanStack Start integrations

These adapters bring General Translation into Vue 3, React Native, and TanStack Start through each framework's normal rendering and request model. Vue uses an application plugin and composables. React Native uses a device-aware provider. TanStack Start joins request state with browser state so translated output stays consistent across server rendering and navigation. See Application framework integrations, React integration, and Next.js integration for related adapters.

Integration model

Each adapter places translation state at the boundary its framework can observe. Application code keeps using framework-native rendering and localization APIs while the adapter manages locale state, condition data, and catalog loading.

AdapterRendering boundaryLocale and condition sourceSetup boundary
VueVue plugin, components, and composablesCookie or an explicit request localeInstall createGT() or the preloaded initializeGTSPA() plugin
React NativeReact provider and shared React componentsNative storage, device preferences, or browser storage on webCall initializeGT() and render under GTProvider
TanStack StartShared React components and isomorphic functionsRequest path, cookie, Accept-Language, or browser cookieInitialize the server or client runtime and register gtMiddleware

All three adapters use the default locale as source-text fallback. They load translated catalogs for target locales. Their state scopes differ because Vue owns an application plugin, React Native owns device-backed provider state, and TanStack Start must isolate server state for each request.

The diagram shows how each adapter creates a locale-aware rendering context for application code.

flowchart LR
  Config[GT configuration] --> Adapter{Framework adapter}
  Adapter --> Vue[Vue plugin and composables]
  Adapter --> Native[React Native provider]
  Adapter --> Start[TanStack Start setup and middleware]
  Catalogs[Locale catalogs] --> Adapter
  Vue --> Render[Framework-native translated rendering]
  Native --> Render
  Start --> Render

Vue runtime

The Vue runtime supplies catalog-backed string and rich-content translation through Vue 3's plugin and composable model. It supports request-scoped rendering and a browser-only single-page application flow.

Vue plugin setup

gt-vue supports Vue 3.3 and later. createGT() creates an isolated plugin for one Vue application. The application installs it with app.use(), and a loader supplies catalogs for non-default locales. The default locale uses source text as its fallback and does not need a catalog load (packages/…/state.ts• L37-66, packages/…/index.ts• L56-80, packages/…/package.json• L13-20).

For a browser single-page application, initializeGTSPA() preloads the active catalog before the rest of the application starts. The application must install the exact plugin that it returns because module-level t() calls and component lookups must use the same runtime (packages/…/spa.ts• L18-64, packages/…/README.md• L87-151).

For server rendering, the application creates createGT({ locale }) per request and preloads that request's catalog before rendering. This keeps one user's locale out of another request. A request can also provide custom locale mappings (packages/…/state.ts• L41-51, packages/…/README.md• L286-294).

References: packages/…/state.ts• L37-66 packages/…/spa.ts• L18-64 packages/…/index.ts• L56-80 packages/…/package.json• L13-20

Vue rendering components

Vue rendering components preserve the authored component tree while the adapter replaces translatable content. T handles rich content from its default slot. Var marks runtime values. Branch and Plural select conditional content. Num, DateTime, and Currency format typed values for the active locale (packages/…/T.ts• L36-90, packages/…/variables.ts• L28-58, packages/…/branches.ts• L27-44).

Vue templates and JSX use the same rich-content contract as the React runtime. Static custom-component slots remain part of the translated content, while runtime values stay outside the catalog identity. This lets Vue catalogs and React-created catalogs represent the same authored content (packages/…/components.test.ts• L254-370, packages/…/reactRuntimeContract.test.ts• L254-370).

Plain strings represent source content rather than a general formatting language. When a catalog entry is missing, the adapter renders source text. Runtime values and conditional content remain explicit through the dedicated components (packages/…/strings.ts• L12-27).

References: packages/…/T.ts• L36-90 packages/…/variables.ts• L28-58 packages/…/branches.ts• L27-44 packages/…/strings.ts• L12-27 packages/…/components.test.ts• L254-370 packages/…/reactRuntimeContract.test.ts• L254-370

Vue localization APIs

Vue applications use useGT() for synchronous plain-string lookup and useMessages() for strings registered with msg(). useLocale() exposes the active reactive locale. useSetLocale() changes it through the installed plugin (packages/…/strings.ts• L12-60, packages/…/locale.ts• L4-30, packages/…/msg.ts• L4-34).

The ordinary plugin loads and caches a missing catalog before it updates reactive consumers. The SPA runtime persists the locale in a configurable cookie and reloads the page so module-level t() calls run against the new catalog. These SPA APIs are browser-only and require initialization before t() is called (packages/…/state.ts• L109-157, packages/…/spa.ts• L67-85, packages/…/spa.ts• L171-209).

An explicit locale takes priority during hydration so the server and client can start with the same catalog. customMapping changes the locale used for formatting and plural rules without changing the stored locale key (packages/…/index.ts• L56-80, packages/…/state.ts• L194-215).

References: packages/…/strings.ts• L12-60 packages/…/locale.ts• L4-30 packages/…/state.ts• L109-157 packages/…/spa.ts• L67-85 packages/…/package.json• L13-20

React Native runtime

The React Native runtime carries the shared React translation model into native applications and React Native web. Its provider loads the active catalog and exposes locale, region, and internationalization state through a device-aware condition store.

React Native provider setup

gt-react-native supports React 19 and React Native 0.78 or later. The application calls initializeGT() once with its configuration and catalog loader. It then renders under GTProvider, which loads the active catalog and shows the supplied fallback while the catalog is not ready (packages/…/README.md• L25-67, packages/…/GTProvider.tsx• L42-105, packages/…/package.json• L98-115).

The provider supplies native condition state so locale, region, and internationalization changes update the React tree without passing condition data through each component. In server-rendered applications, server-provided condition props are the rendered state. Setters persist changes and request a reload so the next request can render with matching conditions (packages/…/NativeGTProvider.tsx• L19-39, packages/…/GTProvider.tsx• L50-80, packages/…/CHANGELOG.md• L188-194).

Initialization also prepares shared internationalization settings and the translation cache. If a catalog load fails, the adapter uses an empty translation snapshot so the application can fall back to source content (packages/…/initializeGT.ts• L1-8, packages/…/loadTranslations.ts• L7-33).

On web, the native module resolves to null instead of being required during import. Native platforms still require the registered GtReactNative module. This keeps React Native web and Expo web imports safe while preserving a hard failure for a misconfigured native build (packages/…/NativeGtReactNative.test.ts• L33-106).

The current package publishes named root, plugin, and internal entry points. Its peer range requires React 19 and React Native 0.78 or later (packages/…/package.json• L8-26, packages/…/package.json• L98-115).

References: packages/…/GTProvider.tsx• L22-123 packages/…/NativeGTProvider.tsx• L11-41 packages/…/initializeGT.ts• L1-8 packages/…/loadTranslations.ts• L7-33 packages/…/NativeGtReactNative.test.ts• L33-106 packages/…/CHANGELOG.md• L188-194 packages/…/package.json• L8-26 packages/…/package.json• L98-115

React Native rendering components

The adapter exports the shared React translation components and hooks. T handles rich content. Var handles runtime values. Format and branch components cover locale-aware values and conditional content. Native application code can therefore use the same translation model as other React applications (packages/…/index.tsx• L1-55).

The provider connects these components to a native condition store and a stable translation store. A locale or condition change therefore re-renders the tree with the new state instead of requiring every component to receive locale data (packages/…/NativeGTProvider.tsx• L19-35, packages/…/NativeConditionStore.ts• L27-57).

References: packages/…/index.tsx• L1-55 packages/…/NativeGTProvider.tsx• L19-35 packages/…/NativeConditionStore.ts• L27-57

React Native localization APIs

The public API provides locale and region readers and setters, internationalization controls, locale selectors, format helpers, useGT(), useMessages(), and translation snapshot access. These APIs read provider state instead of requiring direct access to native storage (packages/…/index.tsx• L15-69).

Initial locale selection checks persisted state before device preferences. Native platforms read both through the GtReactNative module. React Native web uses browser language preferences and localStorage, so it does not require the native module (packages/…/getLocale.ts• L11-21, packages/…/getNativeLocales.ts• L12-24, packages/…/nativeStore.ts• L28-55, packages/…/NativeGtReactNative.ts• L10-20).

The React Native Babel plugin adds the locale data and internationalization polyfills required by the configured entry point. Applications can exclude selected polyfills or force selected capability polyfills when the target runtime needs a fixed set (packages/…/index.ts• L36-105, packages/…/types.ts• L1-51).

References: packages/…/index.tsx• L1-69 packages/…/getLocale.ts• L11-21 packages/…/getNativeLocales.ts• L12-24 packages/…/nativeStore.ts• L28-55 packages/…/index.ts• L36-105

TanStack Start runtime

The TanStack Start runtime joins the shared React translation model to TanStack Start's server request and browser boundaries. Its goal is to make one locale and condition set available during server rendering, server functions, and browser rendering without sharing request state between users.

TanStack Start setup

gt-tanstack-start supports TanStack Start 1.159 or later with React and React DOM. Server code calls initializeGT() from the server entry point. Browser code calls the client entry point version. Each entry point exposes the shared API and its runtime provider (packages/…/index.server.ts• L1-3, packages/…/index.client.ts• L1-3, packages/…/GTProvider.client.tsx• L1-11, packages/…/package.json• L13-22).

Server initialization creates request-aware translation state. Client initialization creates browser state and can turn locale changes into navigation when locale routing is enabled (packages/…/initializeGT.server.ts• L6-10, packages/…/initializeGT.client.ts• L9-40). The package selects server setup for server and worker environments and browser setup for browser builds. It also exposes an explicit ./server entry point for server-only consumers. These boundaries prevent browser state from entering server rendering (packages/…/package.json• L55-90, packages/…/CHANGELOG.md• L506-508).

Applications register gtMiddleware as global server request middleware. It resolves request conditions before downstream server code runs and keeps them available for that request. Server translation reads outside an active middleware scope fail because no request locale is safe to assume (packages/…/gtMiddleware.ts• L8-16, packages/…/AsyncLocalConditionStore.ts• L21-53).

In server-rendered applications, server-provided locale and condition props are the rendered state. Setters persist changes and request a reload. Provider-free single-page applications retain their cookie-backed behavior (packages/…/CHANGELOG.md• L192-198).

The package's current public export map sends worker conditions to the server build before browser conditions. This keeps worker-side rendering request-scoped while browser builds use the client runtime (packages/…/package.json• L55-82).

References: packages/…/index.server.ts• L1-3 packages/…/index.client.ts• L1-3 packages/…/initializeGT.server.ts• L6-10 packages/…/initializeGT.client.ts• L9-40 packages/…/gtMiddleware.ts• L8-16 packages/…/AsyncLocalConditionStore.ts• L21-53 packages/…/CHANGELOG.md• L192-198 packages/…/package.json• L13-22 packages/…/package.json• L55-90

TanStack Start locale routing

When localeRouting is enabled, the server checks the first path segment for a supported locale or configured alias before it checks the locale cookie and Accept-Language. It resolves aliases to configured locale keys, uses the configured default when no candidate is supported, and writes the result to the configured cookie. Region and the internationalization flag also come from their cookies (packages/…/requestConditions.ts• L23-71, packages/…/requestConditions.localeAliases.test.ts• L20-77).

The browser starts from the server-synchronized locale cookie. Non-default locales use a path prefix. The default locale stays unprefixed. Locale changes preserve the router base path and replace an existing locale prefix instead of adding a second one (packages/…/parseLocale.ts• L52-75, packages/…/localeRouting.ts• L22-69, packages/…/localeRouting.test.ts• L13-49).

The diagram shows how request conditions move from an incoming request to server output and then to browser navigation.

sequenceDiagram
  participant Browser
  participant Middleware as gtMiddleware
  participant Server
  participant Client
  Browser->>Middleware: Request with path, cookie, and headers
  Middleware->>Middleware: Resolve locale and other conditions
  Middleware->>Server: Run request-scoped rendering
  Server-->>Browser: HTML and synchronized locale cookie
  Browser->>Client: Initialize from locale cookie
  Client->>Browser: Navigate on locale change

References: packages/…/requestConditions.ts• L23-71 packages/…/parseLocale.ts• L52-75 packages/…/localeRouting.ts• L22-69 packages/…/gtMiddleware.ts• L8-16 packages/…/localeRouting.test.ts• L13-49

TanStack Start localization APIs

The shared entry point exposes the React translation components, provider and hook APIs, message registration, and translation helpers. TanStack Start adds isomorphic getLocale(), getEnableI18n(), getGT(), getMessages(), and getTranslations() functions so server and browser code can request the capability for the current runtime (packages/…/index.shared.ts• L12-49, packages/…/runtime.ts• L16-85).

On the server, these functions read the active request condition store. In the browser, they read the browser condition store. getTranslations() can scope dictionary lookup to a root identifier. parseLocale() remains available for setups without request middleware, but new request flows should use gtMiddleware with getLocale() so server calls share one resolved request state (packages/…/runtime.ts• L26-85, packages/…/parseLocale.ts• L13-49).

Cookie lookups honor the configured locale cookie name. Supported aliases resolve to their configured locale keys (packages/…/parseLocale.ts• L13-75, packages/…/parseLocale.test.ts• L120-218).

References: packages/…/index.shared.ts• L1-49 packages/…/runtime.ts• L16-85 packages/…/parseLocale.ts• L13-49 packages/…/parseLocale.test.ts• L120-218

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep Vue's ordinary plugin flow separate from the SPA singleton flow. Locale persistence and preload timing affect module-level t() calls and server hydration.
  • Keep Vue request-scoped locale mappings aligned with catalog choice and formatting rules. A mapping can change rendered language behavior without changing the stored locale key.
  • Keep Vue's rich-content shape aligned with the React catalog contract. Changes to slots, fragments, branches, or variables can change catalog identity without changing visible source text.
  • Keep React Native condition names aligned with provider props and native storage keys. A mismatch can make locale, region, or enableI18n changes invisible to the rendered tree.
  • Keep native and web locale and storage fallbacks aligned. React Native web must not require the native module.
  • Keep server-provided React Native and TanStack Start conditions paired with cookie writes and reloads. The next middleware request must render the state the user selected.
  • Keep TanStack Start server initialization paired with gtMiddleware. Moving locale reads outside the request scope can remove the active request conditions.
  • Keep TanStack Start client initialization paired with the client provider and its browser reload behavior.
  • Keep TanStack Start export conditions paired with runtime boundaries. Server and worker builds must resolve server setup before browser setup.
  • Keep the explicit TanStack Start ./server entry point aligned with server-only imports and server condition handling.
  • Keep locale-routing path rules paired with client navigation. The default locale must remain unprefixed and target locales must preserve the router base path.
  • Keep aliases, locale keys, and cookie names aligned across path, cookie, and Accept-Language resolution.
  • Keep catalog loading and cache setup paired with the framework provider so rendering never depends on an unavailable catalog.

Important failure modes

TriggerConsequenceGuard
Vue calls initializeGTSPA() during server renderingBrowser-only state cannot initialize safelyUse a request-scoped createGT({ locale }) plugin on the server
Vue calls module-level t() before SPA initialization finishesThe lookup has no active catalog runtimeAwait initializeGTSPA() before importing modules that call t()
Vue installs a plugin other than the one returned by initializeGTSPA()Module-level and component lookups use different stateInstall the exact returned plugin
React Native cannot load its native module on a native platformNative locale and storage access cannot initializeInclude the native module in the native build; use the browser fallback on web
React Native catalog loading failsThe active locale uses an empty translation snapshotKeep source-text fallback available and handle the loader result
TanStack Start omits gtMiddlewareServer translation reads have no request scopeRegister gtMiddleware as global server middleware
TanStack Start client and server resolve different locale pathsHydration or navigation can show the wrong localeInitialize the client from the synchronized cookie and use shared path rules
TanStack Start renders the client provider without client initializationLocale changes lack browser reload behaviorCall client initializeGT() before rendering the provider
A worker build resolves the browser TanStack Start entry pointServer rendering can access browser globals or share state across requestsKeep workerd and worker export conditions ahead of browser

Key files

FileWhy to read it
packages/…/state.tsDefines the Vue plugin boundary, catalog state, locale switching, and request isolation.
packages/…/spa.tsShows browser startup, singleton ownership, module-level strings, and reload-based locale changes.
packages/…/T.tsShows how Vue slot content enters the rich translation boundary.
packages/…/strings.tsDefines the main plain-string and registered-message APIs.
packages/…/package.jsonDefines Vue compatibility and the published runtime boundary.
packages/…/GTProvider.tsxShows catalog loading, fallback rendering, and provider conditions.
packages/…/NativeGTProvider.tsxConnects native condition state to shared React translation state.
packages/…/NativeConditionStore.tsShows how locale, region, and internationalization settings persist and notify React.
packages/…/getLocale.tsDefines initial locale selection across stored and device preferences.
packages/…/index.tsShows the build-time boundary for polyfills and locale data.
packages/…/package.jsonDefines React and React Native compatibility and the published entry point and native module side-effect boundaries.
packages/…/initializeGT.server.tsDefines server initialization and request condition state.
packages/…/initializeGT.client.tsDefines browser initialization and locale-routing navigation behavior.
packages/…/GTProvider.client.tsxConnects the client provider to browser reload behavior.
packages/…/gtMiddleware.tsEstablishes the request scope used by server translation APIs.
packages/…/requestConditions.tsDefines request locale precedence, alias resolution, cookie synchronization, and other conditions.
packages/…/runtime.tsExposes isomorphic locale and translation functions for server and browser code.
packages/…/package.jsonDefines server, worker, browser, and explicit server entry boundaries.