# How do I translate conditional text in JSX?

48.3 s · Narrator: Frederick Surrey

Instead of translating each side of a ternary separately, wrap the whole sentence in a `<T>` component and express the condition with `<Branch>`, so the translator sees the full context and can reorder the sentence for each language.

| Time | Voice | Line | On screen |
| --- | --- | --- | --- |
| 0:00.88 | Narrator | In Shanghai, a reader of Chinese opens your page, and the lunch sentence is in English. | A page draws in the middle of the frame. On "Shanghai" the language code `zh` appears over its top right corner, and on "Chinese" its sentence, "I eat lunch at home.", rises over three lines drawn as bars. The heading "The lunch sentence is in English" rises on "the", and on "English" the sentence turns blue. |
| 0:06.72 | Narrator | Home or work comes from a ternary of English words, and nothing in the app translates the sentence. | On "Home" the page slides to the right, and on "comes" a code panel opens with `Lunch.jsx`: `<p>`, `I eat lunch at {atHome ? 'home' : 'work'}.` and `</p>`. On "ternary" the blue moves from the sentence to `atHome ? 'home' : 'work'`, and on "English" a line joins that row to the page's sentence. On "nothing" the line draws back and a white box draws around the component's three lines, and on "sentence" the box moves to the sentence on the page. |
| 0:13.84 | Narrator | General Translation lets you wrap whole sentences in T and express conditions with Branch. | The answer card cuts in on "General": the answer alone rises as it is spoken, in two lines, "General Translation lets you wrap whole sentences" then "in <T> and express conditions with <Branch>", and the General Translation mark sits small in the lower left corner. |
| 0:19.70 | Narrator | Run npx gt init, choose Japanese and Chinese, and sign in. | The heading "Run npx gt init". The code panel opens again with a terminal, and `npx gt init` is typed as it is spoken; on "init" a white box draws around it. On "choose" the panel cuts to `gt.config.json`, with `"defaultLocale": "en"`, `"locales": ["ja", "zh"]` and the output path `src/_gt/[locale].json`, and the page draws again on the right, still in English. On "Chinese" `"ja"` and `"zh"` turn blue. On "sign" a second file, `.env.local`, opens under it with `VITE_GT_PROJECT_ID` and `VITE_GT_DEV_API_KEY`, the project ID and development key that signing in writes, their values left out. |
| 0:25.76 | Narrator | Put the sentence in a T component with a Branch, so the translator sees it whole. | The heading "Put the sentence in <T>". The code panel cuts to `Lunch.jsx` again. On "T" `<T>` and `</T>` open inside the `<p>`, and just after "component" `import { T, Branch } from 'gt-react';` opens at the top. On "Branch" the ternary becomes `<Branch`, and `branch={atHome.toString()}`, `true="home"`, `false="work"` and `/>.` open under it, each on its own line. A blue bar marks each changed line. On "whole" a white box draws around the lines from `<T>` to `</T>`. The page stays in English. |
| 0:31.44 | Narrator | Run npx gt translate to write Japanese and Chinese with the place before the verb. | The heading "Run npx gt translate". The code panel cuts to a terminal, and `npx gt translate` is typed as it is spoken. On "translate" the panel cuts to the Chinese translation, labelled "zh: the translation <T> renders", where the place sits in the `<Branch>` before the verb, and "home" turns blue on the page. On "Japanese" the page switches to Japanese with the code `ja`, and on "Chinese" to Chinese with `zh`; in both, the place in blue comes before the verb. On "place" a line joins the `<Branch` row to the page's sentence, and on "verb" a white box draws around the verb's row. |
| 0:37.44 | Narrator | In Shanghai, the page now shows the Chinese sentence for home and for work. | The code panel goes, and on "Shanghai" the page slides back to the middle of the frame, in Chinese, its place in blue where the English sentence turned blue at the start. On "Chinese" a white box draws around the sentence, and on "work" the sentence changes to the Chinese sentence for work, its place still in blue before the verb. |
| 0:43.09 | No voice |  | The end card: the General Translation logo with generaltranslation.com/docs/react/guides/handling-plurals-and-branches 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.
