> ## Documentation Index
> Fetch the complete documentation index at: https://weaverse.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Weaverse component configuration uses `settings`. `inspector` is deprecated; never generate it.
> Weaverse Hydrogen themes use React Router v7: import from `react-router`, never `react-router-dom` or `@remix-run/*`.
> Before using any code sample, read `@weaverse/hydrogen` in the project's `package.json`: 6.x and 5.x import from different entries and use different type names, so code for one does not build on the other.
> `@weaverse/hydrogen` 6 (Shopify Hydrogen 2026.10 and later, the version these docs show) imports from `@weaverse/hydrogen/react-router` and uses `Weaverse*` types such as `WeaverseComponentProps`, `WeaverseComponentLoaderArgs` and `WeaverseComponentSchema`; the root `@weaverse/hydrogen` entry only exports `createSchema()`, data helpers and types.
> `@weaverse/hydrogen` 5.x (Hydrogen 2026.4 and earlier) imports everything from `@weaverse/hydrogen` and uses `HydrogenComponentProps`, `ComponentLoaderArgs` and `HydrogenComponentSchema`. On a 5.x project, convert samples to these names. Upgrade to 6 only when asked (`npx @weaverse/cli@latest migrate v6`, plus the Hydrogen 2026.10 upgrade). Do not mix major versions.
> Next.js themes use `@weaverse/hydrogen` 6.2.0 or later: import client and shared code from `@weaverse/hydrogen/next` and server-only code from `@weaverse/hydrogen/next/server`. `@weaverse/next` is deprecated; never install or import it.
> For live project data (pages, theme settings, translations), use the Weaverse MCP server: https://weaverse.io/docs/developer-tools/weaverse-mcp

# useTranslation

> Translate theme text in Weaverse components with useTranslation and the TranslationProvider that withWeaverse mounts.

# useTranslation

`useTranslation` returns a `t()` function that resolves your theme's text keys for the active locale: Studio's live edits, the merchant's translations from the Translation Manager, then your theme's default copy. `TranslationProvider` supplies it; [`withWeaverse`](https://weaverse.io/docs/api-reference/with-weaverse) mounts one for you.

## Import

```tsx theme={null}
import { useTranslation } from '@weaverse/hydrogen/react-router'
```

## Type

```typescript theme={null}
function useTranslation(): TranslationValue

type TranslationValue = {
  t: (key: string, variables?: Record<string, string | number>) => string
  /** Merchant translations for the active locale, or `null`. */
  merchantOverrides: Record<string, unknown> | null
  /** Store for Studio's live design-mode text edits, or `null`. */
  translationStore: TranslationStore | null
}
```

`useTranslation` throws if no `TranslationProvider` is above it. In a theme, that means the root `Layout` isn't wrapped with `withWeaverse`.

## Usage

```tsx theme={null}
import { useTranslation } from '@weaverse/hydrogen/react-router'

export function CartTitle({ count }: { count: number }) {
  const { t } = useTranslation()
  return <h2>{t('cart.title', { count })}</h2>
}
```

Keys are dot paths into your theme's text, for example `cart.title` reads `{ "cart": { "title": "..." } }`. `t()` replaces `{{name}}` placeholders with the matching `variables` value. It doesn't handle plurals or number formatting; see [i18next Integration](https://weaverse.io/docs/features/i18next-integration.md) for that.

## Resolution Order

`t(key)` returns the first value it finds, highest priority first:

1. The external `t` passed to `withWeaverse(Layout, { t })` or `TranslationProvider`, unless it returns an empty string or the key unchanged
2. Unsaved edits the merchant is making in Studio's design mode
3. The merchant's translations for the active locale (`merchantOverrides`)
4. Your theme's default copy (`staticContent`)
5. The key itself

Studio's translations always win over the bundled default copy. Editing your theme's default JSON doesn't change a key the merchant has already translated in Studio.

## Where the Data Comes From

`withWeaverse` reads `weaverseTheme.staticContent` and `weaverseTheme.merchantOverrides` from the root route's loader data, so the root loader must return `loadThemeSettings()` as `weaverseTheme`:

```ts app/root.tsx theme={null}
export async function loader({ context }: Route.LoaderArgs) {
  return {
    weaverseTheme: await context.weaverse.loadThemeSettings(),
    // ...
  }
}
```

`staticContent` comes from `i18n.staticContent` in your theme schema. See [Translation Feature Guide](https://weaverse.io/docs/features/translation-feature-guide.md) to enable the Translation Manager.

## `TranslationProvider`

`withWeaverse` already renders `TranslationProvider`, so themes rarely use it directly. Use it to provide `t()` to a tree that isn't under the Weaverse root, such as a test or a standalone component preview.

```tsx theme={null}
import { TranslationProvider } from '@weaverse/hydrogen/react-router'
import staticContent from '~/i18n/en.json'

<TranslationProvider staticContent={staticContent}>
  <CartTitle count={2} />
</TranslationProvider>
```

| Prop | Type | Description |
| - | - | - |
| `staticContent` | `Record<string, unknown>` | **Required.** The theme's default-locale text. |
| `merchantOverrides` | `Record<string, unknown>` | Merchant translations for the active locale. |
| `t` | `(key, variables?) => string` | External translate function, used first. |
| `translationStore` | `TranslationStore \| null` | Store for live design-mode overrides. |
| `children` | `ReactNode` | Content that can call `useTranslation`. |

> [!NOTE]
>
> `useThemeText`, `ThemeTextProvider` and the `themeTextStore` prop are deprecated aliases of `useTranslation`, `TranslationProvider` and `translationStore`.

The Next.js adapter exports `useTranslation` and `TranslationProvider` from `@weaverse/hydrogen/next`, where `WeaverseNextRootProvider` mounts the provider.

## Related

* [Translation Feature Guide](https://weaverse.io/docs/features/translation-feature-guide.md)
* [withWeaverse](https://weaverse.io/docs/api-reference/with-weaverse.md)
* [useThemeSettings](https://weaverse.io/docs/api-reference/use-theme-settings.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.