# How do I handle plurals in React?

50.6 s · Narrator: Frederick Surrey

Don't hard-code plural logic with checks like n === 1. A small helper is enough for English-only apps, but multilingual apps need locale-aware plural rules, which an i18n component such as `<Plural>` from gt-react or gt-next handles for every language.

| Time | Voice | Line | On screen |
| --- | --- | --- | --- |
| 0:00.88 | Narrator | In Cairo, a browser asks for Arabic, and your page still shows its count in English. | A page draws in the middle of the frame with the sentence "Displaying 1 item" and one row under it. On "asks" the language code `ar` appears over its top right corner. The heading "The count stays in English" rises on "your", and on "English" the sentence turns blue. |
| 0:06.44 | Narrator | Its plural comes from a check for n equals one, and Arabic needs different sentences for two, three and eleven. | On "plural" the page slides to the right, and on "comes" a code panel opens with the article's `Example.jsx`, which prints `Displaying {n} item{n === 1 ? '' : 's'}` in a `<p>`. On "check" a line joins that row to the page's sentence, and on "n" the blue moves from the sentence to `n === 1 ? '' : 's'`. The line goes on "Arabic". On "different" a white box draws around the sentence. On "two" the page reads "Displaying 2 items" with two rows, and on "eleven" "Displaying 11 items" with eleven rows, so the English keeps one form. |
| 0:14.52 | Narrator | General Translation handles plurals in React with the Plural component. | The answer card cuts in on "General": the answer alone rises as it is spoken, in two lines, "General Translation handles plurals in React" then "with the <Plural> component", and the General Translation mark sits small in the lower left corner. |
| 0:19.36 | Narrator | Run npx gt init, sign in, then give Plural the count and sentences for zero, for one and for more. | The heading "Give <Plural> the count". The code panel opens again with a terminal over `Example.jsx`, which now holds the article's `<Plural>`: `<Plural n={count}`, its `zero` and `one` props, and "{count} people are watching" as its children. On "npx" `npx gt init` is typed in the terminal, and on "init" a white box draws around it. On "sign" a `.env.local` panel opens on the right with `VITE_GT_PROJECT_ID` and `VITE_GT_DEV_API_KEY`, their values left out. On "Plural" the page draws in its place, still in English under the code `ar`: "2 people are watching" with two rows. The box moves to `<Plural n={count}` on "count", to the `zero` line on "zero", to the `one` line on "one" and to the children on "more", and the page shows each sentence in turn: "No one is watching", "1 person is watching" and "2 people are watching". |
| 0:28.48 | Narrator | Wrap it in a T component, with the count inside Num. | The heading "Wrap the sentence in <T>". The code panel cuts to `Example.jsx` again. On "it" `<T>` and `</T>` open around the `<Plural>`, and on "T" the import becomes `import { T, Plural, Num } from 'gt-react'`. On "count" the page reads "1 person is watching" with one row. On "inside" the `one` prop becomes a fragment, and on "Num" `<Num>{count}</Num>` takes the count's place in both sentences. A blue bar marks each changed line. |
| 0:32.58 | Narrator | Run npx gt translate, and it writes the sentences that Spanish, Japanese and Arabic need. | The heading "Run npx gt translate". The code panel cuts to `gt.config.json`, whose locales are `"es"`, `"ja"` and `"ar"`, over a terminal. On "npx" `npx gt translate` is typed, and on "writes" a line joins it to the page's sentence. On "Spanish" the page switches to Spanish with the code `es`, and on "Japanese" to Japanese with `ja`. The line goes just before "Arabic", and on "Arabic" the page switches to Arabic with `ar`, set right to left with its row on the right. |
| 0:39.14 | Narrator | In Cairo, Plural now picks the Arabic sentence for two, for three and for eleven. | The code panel goes, and on "Cairo" the page slides back to the middle of the frame. On "picks" its Arabic sentence turns blue, in the place where the English sentence turned blue at the start. On "two", "three" and "eleven" the sentence changes to the Arabic form for that count, and the list grows to two, three and eleven rows, set from the right. |
| 0:45.42 | 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.
