# How do I translate a React app?

50.7 s · Narrator: Frederick Surrey

Install gt-react and the gt CLI, list your languages in gt.config.json with the output inside src, add a loadTranslations file, initialize gt-react with initializeGTSPA in a small entry file before your app renders, wrap your text in the T component, and run npx gt translate to write a translation file for each language.

| Time | Voice | Line | On screen |
| --- | --- | --- | --- |
| 0:00.88 | Narrator | In Paris, your React app renders English for a browser that asks for French. | An app page draws in the middle of the frame. On "your" the heading "Your React app renders English" rises, and the page's heading "Welcome to my app" and the line "This content will be translated automatically." rise with it. On "English" the page's heading turns blue, and on "asks" the language code `fr` appears over the page's top right corner: the language the reader's browser asks for. |
| 0:06.08 | Narrator | Its only text is English, and the app loads no other language. | On "Its" the page slides to the right. On "text" a code panel opens with `src/components/Welcome.tsx`, whose `<main>` holds `<h1>Welcome to my app</h1>` and the paragraph, and under it the one line of `index.html` that loads the app, `<script type="module" src="/src/main.tsx"></script>`. On "English" the blue moves from the page to `Welcome to my app` in the code, and on "and" a line joins that row to the page's heading. On "loads" a white box draws around the line of `index.html`. |
| 0:10.70 | Narrator | General Translation lets you initialize gt-react before the app renders and wrap its text in T. | The answer card cuts in on "General": the answer alone rises as it is spoken, in two lines, "General Translation lets you initialize gt-react" then "before the app renders and wrap its text in <T>", and the General Translation mark sits small in the lower left corner. |
| 0:17.90 | Narrator | List your languages in gt.config.json, and add a loadTranslations file. | The heading "List your languages in gt.config.json", and the code panel opens again with `gt.config.json`: `"defaultLocale": "en"`, `"locales": ["es", "fr", "ja"]` and the output path `src/_gt/[locale].json`. On "languages" `"es"`, `"fr"` and `"ja"` turn blue. On "in" a file panel opens on the right with `index.html`, `src/`, `components/Welcome.tsx` and `main.tsx`, and on "gt.config.json" the config joins them. On "add" the code panel cuts to `src/loadTranslations.ts`, and on "file" it joins the files under `src/`. |
| 0:23.60 | Narrator | An entry file calls initializeGTSPA first, then loads the rest of the app. | The heading "Call initializeGTSPA first", and the code panel cuts to the new `src/index.ts`, its lines rising: three imports, `await initializeGTSPA({ ...gtConfig, loadTranslations });` and `await import('./main');`, with the line of `index.html` under it. On "entry" `index.ts` joins the files, and on "initializeGTSPA" its name turns blue. On "first" the line of `index.html` changes from `/src/main.tsx` to `/src/index.ts`, marked by a blue bar, and on "rest" a white box draws around `await import('./main');`. |
| 0:30.00 | Narrator | Wrap the page's text in T, so the CLI finds it. | The heading "Wrap the page's text in <T>", and the code panel cuts to `src/components/Welcome.tsx`. On "T" `<T>` and `</T>` open around the heading and the paragraph, which move in; on "so" `import { T } from 'gt-react';` opens at the top. A blue bar marks each changed line, and on "CLI" a white box draws around the lines from `<T>` to `</T>`. |
| 0:34.14 | Narrator | Sign in, set your project ID, and run npx gt translate. | The code panel cuts to a terminal over `.env.local`. On "Sign" `npx gt login` is typed, and on "project" `.env.local` gains `GT_PROJECT_ID="your-project-id"`. The heading "Run npx gt translate" rises on "run", and on "npx" `npx gt translate` is typed on a new line. On "translate" a line joins it to the file panel, and `src/_gt/` appears with `es.json`, `fr.json` and `ja.json` under it. |
| 0:39.34 | Narrator | Spanish, Japanese or French loads before the app renders, and in Paris it opens in French. | The app page cuts back in the middle of the frame, in Spanish, with the code `es`. On "Japanese" it cuts to the page in Japanese, with `ja`. On "French" it cuts to an empty page with `fr`, and on "renders" its heading and paragraph rise in French. On "opens" the French heading turns blue, in the place where the English heading turned blue at the start. |
| 0:45.47 | No voice |  | The end card: the General Translation logo with generaltranslation.com/docs/react/react-spa-quickstart 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.
