# gt-next: General Translation Next.js SDK: Tx URL: https://generaltranslation.com/en-US/docs/next/api/components/tx.mdx --- title: Tx description: API reference for the Tx component --- ## Overview The `` component translates jsx content at runtime. ```jsx {/* [!code highlight] */} Today, I went to {" the store"}

to buy some groceries.

// [!code highlight] ``` The `` component supports translating plain text as well as complex JSX structures. Additionally, it provides features for handling variables, plurals, and context-specific translations. `` is server side only. **Runtime Translation:** `` translations occur at runtime. This means translation will be performed live. --- ## Reference ### Props ### Descriptions | Prop | Description | |-----------------|-------------------------------------------------------------------------------------------------| | `children` | The content to be translated. This can include plain text or JSX structures. | | `context` | Additional context to refine the translation. Useful for resolving ambiguous phrases. | | `locale` | An optional locale to use for the translation. Will default to browser's most preferred locale that is supported by your app. | --- ## Behavior `` translates jsx at runtime. This means that translations are performed live, so you can translate content that is only known at runtime. The trade off is that there is a delay while waiting for an on-demand translation to load is significantly slower. 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. Our advice is to translate everything you can at build time using [``](/docs/next/api/components/t), [`getGT`](/docs/next/api/strings/use-gt), or [`useGT`](/docs/next/api/strings/use-gt), and only use on-demand translations, like ``and [`tx`](/docs/next/api/strings/tx) when necessary. Make sure to follow the [deployment guide here](/docs/next/tutorials/quickdeploy). --- ## Examples ### Basic usage The `` component will translate its children at runtime. ```jsx title="SimpleTranslation.jsx" copy import { Tx } from 'gt-next'; export default function Greeting() { return ( {/* [!code highlight] */} Hello, world! // [!code highlight] ); } ``` ### With variables You can use the `` component to mark children as variables. This allows you to mark content that should not be translated. ```jsx title="DynamicGreeting.jsx" copy import { Tx, Var } from 'gt-next'; export default function DynamicGreeting(user) { return ( {/* [!code highlight] */} Hello, {user.name} ); } ``` ### With plurals The `` component also supports pluralization using the `` component. ```jsx title="ItemCount.jsx" copy import { Tx, Plural } from 'gt-next'; export default function ItemCount({ count }) { return ( You have an item.} // [!code highlight] other={<>You have items.} // [!code highlight] // [!code highlight] /> ); } ``` ### Limitations The `` function only translates its descendants. ```jsx title="Example.jsx" copy import { Tx } 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] */} // will be translated {/* [!code highlight] */} Hello, world! {/* [!code highlight] */} // 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 at runtime. * Use the `` component to translate plain text or JSX structures, including variables and pluralization. ## Next steps * For buildtime translations, look into the [``](/docs/next/api/components/t) 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).