# gt-next: General Translation Next.js SDK: Branching Components
URL: https://generaltranslation.com/en-US/docs/next/guides/branches.mdx
---
title: Branching Components
description: How to use branching components for conditional content within translations
---
{/* AUTO-GENERATED: Do not edit directly. Edit the template in content/docs-templates/ instead. */}
Branching components enable conditional content rendering within [``](/docs/next/api/components/t) components. They handle dynamic logic like if/else statements and pluralization rules while ensuring all content variations can be properly translated.
## Available components
- [``](/docs/next/api/components/branch): Conditional content based on values or states
- [``](/docs/next/api/components/plural): Automatic pluralization using locale-specific rules
## Quickstart
Branching components work inside [``](/docs/next/api/components/t) to handle conditional logic:
```jsx
import { T, Branch, Plural, Num, Var } from 'gt-next';
function NotificationPanel({ user, messageCount }) {
return (
{user.name} is currently online
}
away={{user.name} is away
}
>
{user.name} status unknown
You have {messageCount} message}
other={You have {messageCount} messages
}
/>
);
}
```
## How branching components work
Branching components solve conditional rendering within translations by:
1. **Replacing ternary operators** and conditional logic inside [``](/docs/next/api/components/t)
2. **Providing fallback content** when conditions don't match expected values
3. **Enabling translation** of all possible content variations
4. **Following locale rules** for pluralization automatically
```jsx
// ❌ This breaks - conditional logic in
{isActive ? 'User is active' : 'User is inactive'}
// ✅ This works - conditional logic with branching
User is active}
false={User is inactive
}
/>
```
## Component guide
### Branch - Conditional content
Use [``](/docs/next/api/components/branch) for any conditional rendering based on values or states:
```jsx
// User status display
Administrator Dashboard}
user={User Dashboard
}
guest={Guest Access
}
>
Access level unknown
// Boolean conditions
Welcome back!}
false={Please log in
}
/>
// Subscription tiers
Upgrade to unlock premium features}
premium={Enjoy your premium experience
}
enterprise={Contact support for enterprise solutions
}
>
Subscription status unavailable
```
### Plural - Smart pluralization
Use [``](/docs/next/api/components/plural) for content that changes based on quantity:
```jsx
// Basic pluralization
{itemCount} item in cart}
other={{itemCount} items in cart
}
/>
// Zero handling
No new notifications}
one={{notifications} notification
}
other={{notifications} notifications
}
/>
// Complex pluralization (follows Unicode CLDR rules)
Due today}
one={Due in {days} day
}
few={Due in {days} days
}
many={Due in {days} days
}
other={Due in {days} days
}
/>
```
### Combining with variable components
Branching and variable components work together seamlessly:
```jsx
Order {order.id} is pending.
Total: {order.total}
}
shipped={
Order {order.id} shipped on {order.shippedDate}
}
delivered={
Order {order.id} was delivered successfully
}
>
Order status unknown
```
## When to use branching components
### Replace ternary operators
Convert conditional logic for use within [``](/docs/next/api/components/t):
```jsx
// ❌ Can't use ternary in
{isActive ? Active user
: Inactive user
}
// ✅ Use Branch instead
Active user}
false={Inactive user
}
/>
```
### Handle multiple conditions
Replace switch statements or multiple if/else conditions:
```jsx
// ❌ Complex conditional logic
{status === 'loading' ? Loading...
:
status === 'error' ? Error occurred
:
status === 'success' ? Success!
:
Unknown status
}
// ✅ Clean branching logic
Loading...}
error={Error occurred
}
success={Success!
}
>
Unknown status
```
### Pluralization rules
Replace manual plural handling:
```jsx
// ❌ Manual pluralization
{count === 1 ? 1 item
: {count} items
}
// ✅ Automatic pluralization
{count} item}
other={{count} items
}
/>
```
## Standalone usage
Branching components can be used outside [``](/docs/next/api/components/t) for pure logic without translation:
```jsx
// Pure conditional rendering
}
light={}
>
// Pure pluralization
}
other={}
/>
```
## Common issues
### Missing branch keys
Always provide fallback content for unmatched values:
```jsx
// ❌ No fallback for unexpected values
}
user={}
// What if userRole is "moderator"?
/>
// ✅ Always include fallback
}
user={}
>
{/* Fallback for any other value */}
```
### Incomplete plural forms
Provide necessary plural forms for your default locale:
```jsx
// ❌ Missing "other" form
1 item}
// What about 0, 2, 3, etc.?
/>
// ✅ Include required forms
No items}
one={1 item
}
other={{count} items
}
/>
```
### Complex nested logic
Although this works, we recommend keeping branching logic simple and avoid deep nesting:
```jsx
// ❌ Complex nested branching
{/* Hard to read and maintain */}
// ✅ Flatten logic or use multiple components
}
active-offline={}
inactive-online={}
>
```
Learn more about pluralization rules in the [Unicode CLDR documentation](https://cldr.unicode.org/index/cldr-spec/plural-rules).
## Next steps
- [String Translation Guide](/docs/next/guides/strings) - Translate plain text without JSX
- [Dynamic Content Guide](/docs/key-concepts/dynamic-content) - Handle runtime translation
- API References:
- [`` Component](/docs/next/api/components/branch)