# General Translation React SDKs (gt-react, gt-next, gt-react-native): Translating strings
URL: https://generaltranslation.com/en-US/docs/react/guides/translating-strings.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: How to translate standalone strings such as labels and placeholders with the General Translation useGT hook.

Some text is not JSX — placeholders, `aria-label`s, alt text, and strings you build in code. Use the [`useGT`](/docs/react/reference/hooks/use-gt) hook to translate these. In async App Router components, use [`getGT`](/docs/react/nextjs/reference/functions/get-gt) instead.

## Translate with `useGT` [#use-gt]

Call [`useGT`](/docs/react/reference/hooks/use-gt) to get a translation function, then pass it your source string. [`useGT`](/docs/react/reference/hooks/use-gt) returns the function directly.

<Tabs items={['React', 'Next.js', 'TanStack Start', 'React Native']}>
  <Tab value="React">
    ```tsx
    import { useGT } from 'gt-react';

    function Search() {
      const gt = useGT();
      return <input placeholder={gt('Search products')} aria-label={gt('Search')} />;
    }
    ```
  </Tab>

  <Tab value="Next.js">
    ```tsx title="Synchronous components"
    import { useGT } from 'gt-next';

    function Search() {
      const gt = useGT();
      return <input placeholder={gt('Search products')} aria-label={gt('Search')} />;
    }
    ```

    ```tsx title="Async App Router components"
    import { getGT } from 'gt-next/server';

    async function Search() {
      const gt = await getGT();
      return <input placeholder={gt('Search products')} aria-label={gt('Search')} />;
    }
    ```
  </Tab>

  <Tab value="TanStack Start">
    ```tsx
    import { useGT } from 'gt-tanstack-start';

    function Search() {
      const gt = useGT();
      return <input placeholder={gt('Search products')} aria-label={gt('Search')} />;
    }
    ```
  </Tab>

  <Tab value="React Native">
    ```tsx
    import { useGT } from 'gt-react-native';

    function Search() {
      const gt = useGT();
      return <TextInput placeholder={gt('Search products')} accessibilityLabel={gt('Search')} />;
    }
    ```
  </Tab>
</Tabs>

*Note: Write `const gt = useGT()` — the hook returns the function itself, not an object. Pass a string literal, not a template literal or concatenation, so the CLI can extract it.*

## Insert variables [#variables]

Use ICU message syntax with a named placeholder, and pass the value in the options object. This is identical across frameworks.

```tsx
const gt = useGT();
gt('Welcome back, {name}!', { name: user.name });
```

## Add context [#context]

Pass [`$context`](/docs/react/reference/types/inline-translation-options#context) to disambiguate a string, and [`$id`](/docs/react/reference/types/inline-translation-options#id) to give it a stable identifier.

```tsx
gt('Bank', { $context: 'a bank of a river' });
```

## Reuse strings defined outside components [#shared]

To define translatable strings at module scope — for constants, enums, or config — register them with [`msg`](/docs/react/reference/functions/msg) and resolve them with [`useMessages`](/docs/react/reference/hooks/use-messages). In async App Router components, use [`getMessages`](/docs/react/nextjs/reference/functions/get-messages) instead. Register the string once with [`msg`](/docs/react/reference/functions/msg), then resolve it where you render.

<Tabs items={['React', 'Next.js', 'TanStack Start', 'React Native']}>
  <Tab value="React">
    ```tsx
    import { msg, useMessages } from 'gt-react';

    const STATUS = { active: msg('Active'), paused: msg('Paused') };

    function Badge({ status }: { status: 'active' | 'paused' }) {
      const m = useMessages();
      return <span>{m(STATUS[status])}</span>;
    }
    ```
  </Tab>

  <Tab value="Next.js">
    ```tsx title="Synchronous components"
    import { msg, useMessages } from 'gt-next';

    const STATUS = { active: msg('Active'), paused: msg('Paused') };

    function Badge({ status }: { status: 'active' | 'paused' }) {
      const m = useMessages();
      return <span>{m(STATUS[status])}</span>;
    }
    ```

    ```tsx title="Async App Router components"
    import { msg } from 'gt-next';
    import { getMessages } from 'gt-next/server';

    const STATUS = { active: msg('Active'), paused: msg('Paused') };

    async function Badge({ status }: { status: 'active' | 'paused' }) {
      const m = await getMessages();
      return <span>{m(STATUS[status])}</span>;
    }
    ```
  </Tab>

  <Tab value="TanStack Start">
    ```tsx
    import { msg, useMessages } from 'gt-tanstack-start';

    const STATUS = { active: msg('Active'), paused: msg('Paused') };

    function Badge({ status }: { status: 'active' | 'paused' }) {
      const m = useMessages();
      return <span>{m(STATUS[status])}</span>;
    }
    ```
  </Tab>

  <Tab value="React Native">
    ```tsx
    import { msg, useMessages } from 'gt-react-native';

    const STATUS = { active: msg('Active'), paused: msg('Paused') };

    function Badge({ status }: { status: 'active' | 'paused' }) {
      const m = useMessages();
      return <Text>{m(STATUS[status])}</Text>;
    }
    ```
  </Tab>
</Tabs>

## Next steps

- /docs/react/guides/translating-jsx
- /docs/react/guides/formatting-variables
- /docs/react/guides/handling-plurals-and-branches
- /docs/react/guides/translating-with-dictionaries

## Sitemap

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