# gt-next: General Translation Next.js SDK: T URL: https://generaltranslation.com/en-US/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. **Buildtime Translation:** `` translations occur at buildtime. 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` | A unique identifier for the translation string. This ensures consistent translation across your app. | | `context` | Additional context to refine the translation. Useful for resolving ambiguous phrases. | ### Returns `React.JSX.Element|undefined` which contains the rendered translation or fallback content based on the provided configuration. --- ## Behavior ### Production During the CD process, any children inside of 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 fallback to the originial 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 what your app will look like in different languages. Remember to add a Dev API key to your environment to enable this behavior. While loading, `` will return undefined unless languages are similar (en-US vs en-GB), though this behavior can be customized 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 during for 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 pluralization 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 content that is dynamic. ```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 `` in the file will be translated. You can always add another `` to translate the content that is not 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 localization in `gt-next`. * Use the `` component to translate plain text or JSX structures, including variables and pluralization. * 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. * Look into 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).