Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions kb/en-US/i18n-without-translation-files.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,18 @@ ICU message syntax makes this worse. The format libraries like `i18next`, `react
What if you didn't extract strings at all?

```tsx
import { T } from 'gt-react';
import { T, Num, Branch } from 'gt-react';

function CheckoutSummary({ itemCount, discount }) {
return (
<T>
<div>
<h2>Order Summary</h2>
<p>You have {itemCount} items in your cart.</p>
{discount && <p>{discount}% discount applied!</p>}
<p>You have <Num>{itemCount}</Num> items in your cart.</p>
<Branch
branch={discount > 0}
true={<p><Num>{discount}</Num>% discount applied!</p>}
/>
<p>Total (before tax):</p>
<small>Tax calculated at checkout.</small>
</div>
Expand All @@ -69,6 +72,8 @@ function CheckoutSummary({ itemCount, discount }) {

The [`<T>`](/docs/react/reference/components/t) component in [`gt-react`](/docs/react/react-quickstart) marks a block of JSX for translation. The English stays in your component. When a user visits in Spanish, the content inside [`<T>`](/docs/react/reference/components/t) is replaced with its Spanish equivalent. Structure and formatting carry over.

Values that change at runtime go inside variable components such as [`<Num>`](/docs/react/reference/components/num), and conditional content goes inside [`<Branch>`](/docs/react/reference/components/branch). The CLI stops with an error when a [`<T>`](/docs/react/reference/components/t) has children that can change at runtime.

There's no `t('checkout.summary.title')`, no `en.json`, no per-locale JSON files to keep in sync.

## Translations as build output
Expand Down
Loading