# General Translation React SDKs (gt-react, gt-next, gt-react-native): getTranslationsSnapshot
URL: https://generaltranslation.com/en-US/docs/react/reference/functions/get-translations-snapshot.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Load a locale's translations for `<GTProvider>`. API reference for getTranslationsSnapshot.

The `getTranslationsSnapshot` function loads the translations for a locale in the shape that [`<GTProvider>`](/docs/react/reference/components/gt-provider) expects for its `translations` prop. Call it after initialization to produce the snapshot the provider consumes synchronously.

*Available in `gt-react`, `gt-next`, `gt-tanstack-start`, and `gt-react-native`.*

In `gt-next`, use this function with the Pages Router. The App Router's React Server Component export throws; its server translation setup is managed by `gt-next`.

## Overview [#overview]

After [initializing](/docs/react/reference/config#initialization) `gt-react`, await `getTranslationsSnapshot` for the active locale and pass the result to the provider.

```tsx
const translations = await getTranslationsSnapshot(locale);
```

*Note: call `getTranslationsSnapshot` after [`initializeGT`](/docs/react/reference/config#initialize) or [`initializeGTSPA`](/docs/react/reference/config#initialize-spa), which create the translation cache it uses.*

## How it works [#how-it-works]

`getTranslationsSnapshot` asks the configured [`loadTranslations`](/docs/react/reference/functions/load-translations) function to load the locale through the translation cache, then returns a serializable snapshot. Passing this snapshot to [`<GTProvider>`](/docs/react/reference/components/gt-provider) lets translated content render synchronously, without a loading flash.

## Parameters [#parameters]

| Parameter | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| [`locale`](#locale) | The locale to load translations for. | `string` | No | — |

### `locale` [#locale]

**Type** `string` · **Required**

The locale whose translations to load, as a BCP 47 code.

## Returns [#returns]

**Type** `Promise<Record<Locale, Record<Hash, Translation>>>`

A promise resolving to the translations snapshot for the locale, in the shape [`<GTProvider>`](/docs/react/reference/components/gt-provider) expects for its `translations` prop.

## Errors [#errors]

In development, if [`loadTranslations`](/docs/react/reference/functions/load-translations) rejects, `getTranslationsSnapshot` logs a warning and resolves to `{}`. The failed locale is omitted, so passing the snapshot to a provider does not seed an empty entry.

In production, the translation cache logs the loader error and returns an empty catalog, so the snapshot contains `{ [locale]: {} }`. The failed load is not cached in the originating cache and a later load can retry, but passing that snapshot to another provider can seed an empty catalog there.

If your loader catches an error and returns `{}`, the cache treats that empty object as a successful load and keeps it until `cacheExpiryTime` expires.

## Examples [#examples]

*Examples import from `gt-react`; import from your framework's package instead.*

```tsx title="src/routes/root.tsx"
import {
  GTProvider,
  initializeGT,
  getTranslationsSnapshot,
  parseLocale,
} from 'gt-react';
import gtConfig from '../../gt.config.json';

const loadTranslations = (locale: string) =>
  import(`../_gt/${locale}.json`).then((m) => m.default);

initializeGT({ ...gtConfig, loadTranslations });

export async function loadRoot(request: Request) {
  const locale = parseLocale(request);
  return {
    locale,
    translations: await getTranslationsSnapshot(locale), // [!code highlight]
  };
}

export function Root({ locale, translations, children }) {
  return (
    <GTProvider locale={locale} translations={translations}>
      {children}
    </GTProvider>
  );
}
```

## Notes [#notes]

- Call `getTranslationsSnapshot` after initialization.
- Pass the result to the `translations` prop of [`<GTProvider>`](/docs/react/reference/components/gt-provider).

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
