# How do I translate strings outside JSX?

51.4 s · Narrator: Frederick Surrey

Use the useGT hook for strings such as placeholders and aria labels, getGT in async App Router components, and msg with useMessages for strings defined at module scope, outside a component.

| Time | Voice | Line | On screen |
| --- | --- | --- | --- |
| 0:00.88 | Narrator | In Vienna, your product list shows its search placeholder and badges in English. | A product list draws in the middle of the frame. On "Vienna" the language code `de` appears over its top right corner, and on "list" a search field reading "Search products" rises, then three rows with the badges "Active", "Paused" and "Active". The heading "Placeholder and badges in English" rises on "its". On "placeholder" "Search products" turns blue, and on "badges" the blue moves to the three badges. |
| 0:06.14 | Narrator | The placeholder is an attribute, and the badges come from a constant. | On "placeholder" the list slides to the right, and on "is" a code panel opens with `Search.tsx`, whose `<input>` has `placeholder="Search products"` and `aria-label="Search"`. On "attribute" the blue moves to `placeholder="Search products"`, and a line joins it to the search field. The line goes, and on "badges" the panel cuts to `Badge.tsx`: a constant `STATUS` with `active: 'Active'` and `paused: 'Paused'`, and a `Badge` that returns `<span>{STATUS[status]}</span>`. On "constant" the blue moves to `'Active'` and `'Paused'`, and a line joins them to the first badge. |
| 0:11.04 | Narrator | General Translation translates placeholders with useGT and constants with msg and useMessages. | The answer card cuts in on "General": the answer alone rises as it is spoken, in two lines, "General Translation translates placeholders with" then "useGT and constants with msg and useMessages", and the General Translation mark sits small in the lower left corner. |
| 0:18.78 | Narrator | Call useGT, and pass the placeholder to the function it returns. | The heading "Translate the placeholder with useGT", and the code panel opens again with `Search.tsx`. On "useGT" `import { useGT } from 'gt-next';` opens at the top, on "pass" `const gt = useGT();` opens, and on "placeholder" the placeholder becomes `{gt('Search products')}` and the label `{gt('Search')}`. A blue bar marks each changed line. On "function" a file panel opens on the right with the project's files, `gt.config.json` and `loadTranslations.js` among them, and on "returns" a white box draws around `const gt = useGT();`. |
| 0:23.62 | Narrator | In async components, await getGT, because they cannot use hooks. | The heading "Await getGT in async components", and the code panel cuts to `Search.tsx` as the last step left it. On "async" `async ` is typed in front of `function Search()`, on "await" `const gt = useGT();` becomes `const gt = await getGT();`, and on "getGT" the import becomes `import { getGT } from 'gt-next/server';`, each marked by a blue bar. On "cannot" a white box draws around `const gt = await getGT();`. |
| 0:29.32 | Narrator | For constants, msg registers each string, and useMessages resolves it where you render it. | The heading "Register constants with msg", and the code panel cuts to `Badge.tsx`. On "msg" `import { msg, useMessages } from 'gt-next';` opens at the top; on "registers" `'Active'` becomes `msg('Active')`, and on "each" `'Paused'` becomes `msg('Paused')`. On "useMessages" `const m = useMessages();` opens in the function, and on "render" the return becomes `<span>{m(STATUS[status])}</span>`. A blue bar marks each changed line. |
| 0:36.10 | Narrator | Run npx gt translate to write the Spanish, Japanese and German strings. | The heading "Run npx gt translate", and the code panel cuts to `gt.config.json`, with `"locales": ["es", "ja", "de"]`, over a terminal. On "npx" `npx gt translate` is typed, marked by a blue bar. On "translate" the product list draws again on the right, in English, in place of the file panel. On "Spanish", "Japanese" and "German" the list and its code switch to that language. |
| 0:42.02 | Narrator | In Vienna, the placeholder and the badges now read in German. | The code panel lifts away, and on "Vienna" the list, in German with the code `de`, slides back to the middle of the frame. On "placeholder" the German placeholder turns blue, and on "badges" the blue moves to the German badges, in the places where the English ones turned blue at the start. On "German" a white box draws around the search field and the three rows. |
| 0:46.14 | No voice |  | The end card: the General Translation logo with generaltranslation.com/docs/react/guides/translating-strings under it, held to the last frame while the music ends on a held chord. |

Times are where each line starts in the final, read from the film's own audio.
