# gt-react: General Translation React SDK: Variable Components URL: https://generaltranslation.com/en-US/docs/react/guides/variables.mdx --- title: Variable Components description: How to use variable components for dynamic content within translations --- {/* AUTO-GENERATED: Do not edit directly. Edit the template in content/docs-templates/ instead. */} Variable components allow you to safely include dynamic content within [``](/docs/react/api/components/t) components. They handle formatting and localization locally without sending data to the translation API, making them perfect for sensitive information like usernames, account numbers, and financial data. ## Available components - [``](/docs/react/api/components/var): Raw dynamic content without formatting - [``](/docs/react/api/components/num): Numbers with locale-specific formatting - [``](/docs/react/api/components/currency): Currency values with symbols and formatting - [``](/docs/react/api/components/datetime): Dates and times with locale conventions ## Quickstart Variable components work inside [``](/docs/react/api/components/t) to handle dynamic content: ```jsx import { T, Var, Num, Currency, DateTime } from 'gt-react'; function UserProfile({ user }) { return (

Welcome back, {user.name}!

You have {user.itemCount} items.

Balance: {user.balance}

Last login: {user.lastLogin}

); } ``` ## How variable components work Variable components solve the dynamic content problem by: 1. **Wrapping dynamic values** so they can be used inside [``](/docs/react/api/components/t) 2. **Handling formatting locally** using the browser's built-in i18n APIs 3. **Keeping data private** - content is never sent to the translation API 4. **Providing localization** based on the user's current locale ```jsx // ❌ This breaks - dynamic content in

Hello {username}

// ✅ This works - dynamic content wrapped

Hello {username}

``` ## Component guide ### Var - Raw dynamic content Use [``](/docs/react/api/components/var) for any dynamic content that doesn't need special formatting: ```jsx // User information

Hello, {user.name}!

Your account ID is {user.accountId}

// Conditional rendering Dashboard: {isAdmin ? : } ``` ### Num - Formatted numbers Use [``](/docs/react/api/components/num) for numbers that should follow locale formatting rules: ```jsx // Basic number formatting You have {itemCount} items in your cart. // Standalone usage (equivalent to number.toLocaleString()) {totalItems} // Custom formatting options Distance: {distance} km ``` ### Currency - Money values Use [``](/docs/react/api/components/currency) for monetary amounts: ```jsx // Basic currency formatting (defaults to "USD") Your total is {total}. // Different currencies Price: {price} // Custom formatting {roundedAmount} ``` ### DateTime - Dates and times Use [``](/docs/react/api/components/datetime) for dates and times: ```jsx // Basic date formatting Order placed on {orderDate} // Time formatting Last updated: {timestamp} // Custom date format {eventDate} ``` ## Privacy and security ### Data stays local Variable components handle all formatting locally using the browser's [Intl APIs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl). **No dynamic content is sent to the translation API**, making them perfect for: - User names and personal information - Account numbers and IDs - Financial data and balances - Private timestamps and dates ```jsx // Safe - sensitive data stays local Account balance: {balance} Last login: {lastLoginTime} ``` ### Important exception Be careful with nested [``](/docs/react/api/components/t) components inside variable components: ```jsx // ⚠️ The inner content WILL be sent for translation Hello, world! {/* This gets translated */} {privateData} {/* This stays local */} ``` ## Standalone usage Variable components can be used outside of [``](/docs/react/api/components/t) for pure formatting: ```jsx // These work like their respective .toLocale*() methods {count} // count.toLocaleString() {price} // price formatting {date} // date.toLocaleDateString() ``` ## Common issues ### Ignoring localization options For [``](/docs/react/api/components/currency), make sure to pass the `currency` prop to specify the currency type. This ensures that the correct currency symbol and formatting are used when displaying the value: ```jsx // ❌ Defaults to USD - may not be what users expect The item costs {price} // ✅ Explicitly specify the currency The item costs {price} ``` Other components also have optional props that allow you to customize the formatting: ```jsx // Basic formatting {count} items in stock // Custom formatting {percentage} completion rate // Date formatting Last updated: {lastUpdate} ``` ## Next steps - [Branching Components Guide](/docs/react/guides/branches) - Add conditional logic to your translations - [String Translation Guide](/docs/react/guides/strings) - Translate plain text without JSX - API References: - [`` Component](/docs/react/api/components/var) - [`` Component](/docs/react/api/components/num) - [`` Component](/docs/react/api/components/currency)