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 mounts one for you.
Import
Type
useTranslation throws if no TranslationProvider is above it. In a theme, that means the root Layout isn’t wrapped with withWeaverse.
Usage
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 for that.
Resolution Order
t(key) returns the first value it finds, highest priority first:
- The external
tpassed towithWeaverse(Layout, { t })orTranslationProvider, unless it returns an empty string or the key unchanged - Unsaved edits the merchant is making in Studio’s design mode
- The merchant’s translations for the active locale (
merchantOverrides) - Your theme’s default copy (
staticContent) - The key itself
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:
app/root.tsx
staticContent comes from i18n.staticContent in your theme schema. See Translation Feature Guide 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.
useThemeText, ThemeTextProvider and the themeTextStore prop are deprecated aliases of useTranslation, TranslationProvider and translationStore.useTranslation and TranslationProvider from @weaverse/hydrogen/next, where WeaverseNextRootProvider mounts the provider.