# gt-next: General Translation Next.js SDK: T URL: https://generaltranslation.com/en-GB/docs/next/api/components/t.mdx --- title: T description: API reference for the T component --- ## Overview The `` component is the main translation method in `gt-next`. ```jsx Today, I went to {" the store"}

to buy some groceries.

``` The `` component supports translating plain text as well as complex JSX structures. Additionally, it provides features for handling variables, plurals, and context-specific translations. **Build-time Translation:** `` translations occur at build time. This means translation happens before deployment to reduce latency. Make sure to follow the [deployment guide here](/docs/next/tutorials/quickdeploy). *** ## Reference ### Props ### Descriptions | Prop | Description | | ---------- | --------------------------------------------------------------------------------------------------------------- | | `children` | The content to be translated. This can include plain text or JSX structures. | | `id` | An optional unique identifier for the translation string. If not provided, one is auto-generated at build time. | | `context` | Additional context to help refine the translation. Useful for resolving ambiguous phrases. | ### Returns `React.JSX.Element|undefined` that contains the rendered translation or fallback content based on the supplied configuration. *** ## Behaviour ### Production During the CD process, any children inside a `` will be translated before your application is deployed. This ensures fast load times for all locales, but it can only translate content known at build time. Once generated, translations are either (1) stored in the CDN or (2) stored in your app's build output, according to your configuration. From there, the translated content is served to your users. If a translation is not found, it will fall back to the original content. Make sure to follow the [deployment guide here](/docs/next/tutorials/quickdeploy). ### Development During development, the `` function will translate content on-demand. This is useful for prototyping how your app will look in different languages. Remember to add a Dev API key to your environment to enable this behaviour. While loading, `` will return undefined unless the languages are similar (en-US vs en-GB), though this behaviour can be customised with render settings. If an error occurs, `` will return the original content. You will see a delay during on-demand translation in development. This delay will not occur in production builds unless content is explicitly being translated on-demand, i.e. by using [``](/docs/next/api/components/tx) or [`tx`](/docs/next/api/strings/tx). *** ## Examples ### Basic usage The `` will translate its children. ```jsx title="SimpleTranslation.jsx" copy import { T } from 'gt-next'; export default function Greeting() { return ( Hello, world! ); } ``` ### With variables You can use the `` component to mark children as variables. This allows you to mark content that should not be translated. Usually, `` components wrap dynamic content. ```jsx title="DynamicGreeting.jsx" copy import { T, Var } from 'gt-next'; export default function DynamicGreeting(user) { return ( Hello, {user.name}! ); } ``` ### With plurals The `` component also supports pluralisation using the `` component. ```jsx title="ItemCount.jsx" copy import { T, Plural } from 'gt-next'; export default function ItemCount({ count }) { return ( You have an item.} other={<>You have items.} /> ); } ``` ### Limitations The `` component does not translate dynamic content. ```jsx title="DynamicContent.jsx" copy import { T } from 'gt-next'; export default function DynamicContent({greeting}) { return ( {greeting} {/* will create an error */} ); } ``` The `` function translates its descendants. ```jsx title="Example.jsx" copy import { T } from 'gt-next'; const ValidTranslation = ({ children }) => (
{children}
); const InvalidTranslation = ({ children }) => (
No translation
); export default function Example() { return ( { /* [!code highlight] */}
This is valid!
{/* will be translated */} { /* [!code highlight] */} Hello, world! {/* will be translated */} {/* will not be translated */}
); } ``` **Note:** A good rule of thumb is that any content that is *literally* between the two ``s in the file will be translated. You can always add another `` to translate content that isn't being translated, though nesting `` components is not recommended. *** ## Notes * The `` component is designed for translating content in your application. It is the primary method for localisation in `gt-next`. * Use the `` component to translate plain text or JSX structures, including variables and pluralisation. * If you use the `` component on the client side, make sure it is wrapped in a [``](/docs/next/api/components/gtprovider) to access the translation context. ## Next steps * For on-demand translations, look into the [``](/docs/next/api/components/tx) component. * For more advanced features, see the [`` reference](/docs/next/guides/t). * For translating strings, look into [`tx`](/docs/next/api/strings/tx), [`getGT`](/docs/next/api/strings/get-gt), and [`useGT`](/docs/next/api/strings/use-gt).