# gt-react: General Translation React SDK: The T Component URL: https://generaltranslation.com/en-US/docs/react/guides/t.mdx --- title: The T Component description: How to internationalize JSX components using the T component --- {/* AUTO-GENERATED: Do not edit directly. Edit the template in content/docs-templates/ instead. */} The [`` component](/docs/react/api/components/t) is the primary tool for internationalizing JSX content in your React application. It wraps your JSX elements and automatically translates them based on the user's locale. **Tip:** With [auto JSX injection](/docs/cli/features/auto-jsx-injection) enabled, the compiler can automatically wrap your JSX in translation components at build time. You may not need to add `` manually in most cases. Manual `` is still useful when you need fine-grained control, such as setting a specific `id` or `context`. ## Quickstart Transform any static JSX content by wrapping it with [``](/docs/react/api/components/t): ```jsx import { T } from 'gt-react'; // Before function Greeting() { return

Hello, world!

; } // After function Greeting() { return

Hello, world!

; } ``` For dynamic content within [``](/docs/react/api/components/t), use [Variable Components](/docs/react/guides/variables) and [Branching Components](/docs/react/guides/branches). ## Basic usage The [`` component](/docs/react/api/components/t) accepts any JSX content as children: ```jsx // Simple text Welcome to our app // HTML elements

Page Title

// Complex nested JSX
Important: Please read carefully.
``` ## Configuration options ### Adding context Provide translation context for ambiguous terms: ```jsx Click the toast to dismiss ``` ## When to use T Use [``](/docs/react/api/components/t) for **static content only**: ```jsx // ✅ Static content works

Welcome to our site

// ❌ Dynamic content breaks

Hello {username}

Today is {new Date()}

// ✅ Use Variable components for dynamic content

Hello {username}

``` Variable and Branching components are designed to work inside [``](/docs/react/api/components/t) for dynamic content. See [Variable Components](/docs/react/guides/variables) and [Branching Components](/docs/react/guides/branches) guides for details. ## Examples ### Simple elements ```jsx // Basic text Hello, world! // Button with text // Heading with styling

Welcome

``` ### Complex components ```jsx // Navigation menu // Alert message
Your session expires in 5 minutes
``` ### With variables You can use variable components for localized formatting. ```jsx // Combining static text with dynamic values

Welcome back, {user.name}!

You have {user.friends.length} friends online

Your birthday is {user.birthday}

Your balance is {user.balance}

``` Learn more about the [`` component](/docs/react/api/components/var) in the [Variable Components Guide](/docs/react/guides/variables). ## Production setup ### Build process Add translation to your build pipeline: ```json title="package.json" { "scripts": { "build": "npx gt translate && <...YOUR_BUILD_COMMAND...>" } } ``` ### Development vs production behavior - **Development**: With a dev API key, translations happen on-demand when components render. You'll see real-time translation as you develop. - **Production**: All translations are pre-built during the build stage and will be visible once your application is live. Set your development API key in your environment to enable live translation during development. You can create one in the Dashboard under [API Keys](https://dash.generaltranslation.com/en-US/project/api-keys). ### Privacy considerations Content in [``](/docs/react/api/components/t) components is sent to the GT API for translation. For sensitive data, use [Variable Components](/docs/react/guides/variables) to keep private information local: ```jsx // Safe - sensitive data stays local Welcome back, {username} ``` ## How much to wrap in a single `` Wrap **logical content blocks** — content that a translator would naturally read and translate together. ```jsx // ✅ Good — related content wrapped together gives translators full context

Welcome to Our Platform

Get started in minutes with our simple setup process.

// ✅ Good — each card is an independent unit {features.map((feature) => (

{feature.title}

{feature.description}

))} // ❌ Too narrow — fragments the translation, loses context

Welcome to Our Platform

Get started in minutes with our simple setup process.

// ❌ Too wide — wrapping your entire page makes it harder to maintain {/* ...hundreds of lines of JSX... */} ``` **Rule of thumb:** if text is visually or semantically related, wrap it in one ``. Only split when content is genuinely independent (e.g., a header vs. a footer). Wrapping more content in a single `` gives translators better context, which produces more natural translations — some languages restructure sentences or need to reference nearby content. ## Common issues ### Component boundaries [``](/docs/react/api/components/t) only translates direct children, not content inside other components: ```jsx // ❌ Wrong - content inside components won't be translated function MyComponent() { return

This won't be translated

; }

This will be translated

{/* Content inside won't be translated */}
// ✅ Correct - wrap each component individually function MyComponent() { return

This will be translated

; }

This will be translated

``` ### Nesting T components ```jsx // ❌ Don't nest components Hello world {/* Don't do this */} ``` ### Dynamic content errors The CLI will error on dynamic content in [``](/docs/react/api/components/t). Wrap dynamic values with Variable components: ```jsx // ❌ Wrong - dynamic content breaks

Hello {username}

// ✅ Correct - use Variable components

Hello {username}

``` See the [Variable Components Guide](/docs/react/guides/variables) for handling dynamic values and the [Branching Components Guide](/docs/react/guides/branches) for conditional content. ## Next steps **See it in action:** Check out the [`` component basics example app](https://github.com/gt-examples/t-component-basics) for a working demo — [live preview](https://t-component-basics.generaltranslation.dev). - [Variable Components Guide](/docs/react/guides/variables) - Handle dynamic content within JSX translations - [Branching Components Guide](/docs/react/guides/branches) - Add conditional logic to your translations