Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions docs-templates/guides/dictionaries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ function MixedApproach() {

## Next steps

<Callout>
**See it in action:** Check out the [dictionary pattern example app](https://github.com/gt-examples/dictionary-pattern) for a working demo — [live preview](https://dictionary-pattern.generaltranslation.dev).
</Callout>

- [Languages Guide](__DOCS_PATH__/guides/languages) - Configure supported languages and locale settings
- [Dynamic Content Guide](/docs/key-concepts/dynamic-content) - Handle runtime translation needs
- API References:
Expand Down
4 changes: 4 additions & 0 deletions docs-templates/guides/t.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,9 @@ The CLI will error on dynamic content in [`<T>`](__DOCS_PATH__/api/components/t)

## Next steps

<Callout>
**See it in action:** Check out the [`<T>` component basics example app](https://github.com/gt-examples/t-component-basics) for a working demo — [live preview](https://t-component-basics.generaltranslation.dev).
</Callout>

- [Variable Components Guide](__DOCS_PATH__/guides/variables) - Handle dynamic content within JSX translations
- [Branching Components Guide](__DOCS_PATH__/guides/branches) - Add conditional logic to your translations
1 change: 1 addition & 0 deletions docs/en-US/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"./platform",
"./next",
"./react",
"./tanstack-start",
"./react-native",
"./react-core-linter",
"./node",
Expand Down
4 changes: 4 additions & 0 deletions docs/en-US/next/guides/dictionaries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ function MixedApproach() {

## Next steps

<Callout>
**See it in action:** Check out the [dictionary pattern example app](https://github.com/gt-examples/dictionary-pattern) for a working demo — [live preview](https://dictionary-pattern.generaltranslation.dev).
</Callout>

- [Languages Guide](/docs/next/guides/languages) - Configure supported languages and locale settings
- [Dynamic Content Guide](/docs/next/guides/dynamic-content) - Handle runtime translation needs
- API References:
Expand Down
4 changes: 4 additions & 0 deletions docs/en-US/next/guides/dynamic-content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ Dynamic translation consumes API quota on every request. Use caching and error h

## Next steps

<Callout>
**See it in action:** Check out the [dynamic content example app](https://github.com/gt-examples/dynamic-content-tx) for a working demo of `tx()` and `<Tx>` — [live preview](https://dynamic-content-tx.generaltranslation.dev).
</Callout>

- [Local Translation Guide](/docs/next/guides/local-tx) - Handle translations without API calls
- [Middleware Guide](/docs/next/guides/middleware) - Language detection and routing
- API References:
Expand Down
4 changes: 4 additions & 0 deletions docs/en-US/next/guides/middleware.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export const config = {

## Next steps

<Callout>
**See it in action:** The [static site generation example app](https://github.com/gt-examples/static-site-generation) includes a full middleware setup with locale routing — [live preview](https://static-site-generation.generaltranslation.dev).
</Callout>

- [SSG Guide](/docs/next/guides/ssg) - Static generation with locale routing
- [RTL Support](/docs/next/guides/rtl) - Right-to-left languages
- API References:
6 changes: 5 additions & 1 deletion docs/en-US/next/guides/ssg.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ To fix this issue, make sure that all of your route segment files (so typically

## Further reading

<Callout>
**See it in action:** Check out the [static site generation example app](https://github.com/gt-examples/static-site-generation) for a working demo — [live preview](https://static-site-generation.generaltranslation.dev).
</Callout>

- Check out the [middleware guide](/docs/next/guides/middleware) required for locale routing
- Check out the [release notes](/blog/gt-next_v6_10_0) for migrating from legacy SSG pattern
- See an example app [here](https://github.com/generaltranslation/gt/tree/main/examples/next-ssg)
- See an example app in the monorepo [here](https://github.com/generaltranslation/gt/tree/main/examples/next-ssg)
4 changes: 4 additions & 0 deletions docs/en-US/next/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ For production, you need to pre-translate content since runtime translation is d

## Next steps

<Callout>
**See it in action:** Browse [working example apps](/docs/next/tutorials/examples) to see `gt-next` patterns in real projects, or jump straight to the [app catalog](https://app-catalog.generaltranslation.dev).
</Callout>

- [`<T>` Component Guide](/docs/next/guides/t) - Deep dive into the [`<T>`](/docs/next/api/components/t) component and JSX translation
- [String Translation Guide](/docs/next/guides/strings) - Using [`useGT`](/docs/next/api/strings/use-gt) and [`getGT`](/docs/next/api/strings/get-gt)
- [Variable Components](/docs/next/guides/variables) - Handle dynamic content with [`<Var>`](/docs/next/api/components/var), [`<Num>`](/docs/next/api/components/num), etc.
4 changes: 4 additions & 0 deletions docs/en-US/next/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ See the [useTranslations API Reference](/docs/next/api/dictionary/use-translatio

## Next steps

<Callout>
**See it in action:** Browse [working example apps](/docs/next/tutorials/examples) showcasing each pattern, or explore the full [app catalog](https://app-catalog.generaltranslation.dev).
</Callout>

- Learn about how to set up your Next.js project with the SDK: [Quickstart](/docs/next/tutorials/quickstart)
- Learn about how to translate JSX content with the [`<T>`](/docs/next/api/components/t) component: [JSX Translation Guide](/docs/next/guides/t)
- Learn about how to translate strings with the [`useGT`](/docs/next/api/strings/use-gt) hook: [String Translation Guide](/docs/next/guides/strings)
Expand Down
255 changes: 255 additions & 0 deletions docs/en-US/tanstack-start/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
---
title: TanStack Start Quickstart
description: Internationalize your TanStack Start app with gt-tanstack-start
---

**Prerequisites:** TanStack Start project with React 16.8+

<Callout type="warn">
**Experimental:** `gt-tanstack-start` is under active development and not yet recommended for production use.
</Callout>

## Installation

Install `gt-tanstack-start`, `gt-react`, and the `gt` CLI:

<Tabs items={['npm', 'yarn', 'bun', 'pnpm']}>
<Tab value="npm">
```bash
npm i gt-tanstack-start gt-react
npm i -D gt
```
</Tab>
<Tab value="yarn">
```bash
yarn add gt-tanstack-start gt-react
yarn add --dev gt
```
</Tab>
<Tab value="bun">
```bash
bun add gt-tanstack-start gt-react
bun add --dev gt
```
</Tab>
<Tab value="pnpm">
```bash
pnpm add gt-tanstack-start gt-react
pnpm add --save-dev gt
```
</Tab>
</Tabs>

<Callout type="info">
`gt-react` is required as a direct dependency so the `gt` CLI can detect `<T>` components in your source code.
</Callout>

## Configuration

### `gt.config.json`

Create a `gt.config.json` in your project root:

```json title="gt.config.json"
{
"defaultLocale": "en",
"locales": ["es", "ja"],
"files": {
"gt": {
"output": "src/_gt/[locale].json"
}
}
}
```

<Callout>
Translation files **must** be inside `src/` for Vite's dynamic imports to work. Using `public/` will not work.
</Callout>

### Translation loader

Create a `loadTranslations.ts` file in your project root:

```ts title="loadTranslations.ts"
export default async function loadTranslations(locale: string) {
const translations = await import(`./src/_gt/${locale}.json`);
return translations.default;
}
```

### Root route setup

Update `src/routes/__root.tsx` to initialize GT and provide translations:

```tsx title="src/routes/__root.tsx"
import {
HeadContent,
Scripts,
createRootRoute,
} from '@tanstack/react-router'
import {
initializeGT,
GTProvider,
getTranslations,
getLocale,
LocaleSelector,
} from 'gt-tanstack-start'
import gtConfig from '../../gt.config.json'
import loadTranslations from '../../loadTranslations'

// Initialize GT at the module level
initializeGT({
...gtConfig,
loadTranslations,
})

export const Route = createRootRoute({
head: () => ({
meta: [
{ charSet: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
],
}),
loader: async () => {
return {
translations: await getTranslations(),
locale: getLocale(),
}
},
shellComponent: RootDocument,
})

function RootDocument({ children }: { children: React.ReactNode }) {
const { translations, locale } = Route.useLoaderData()
return (
<html lang={locale}>
<head>
<HeadContent />
</head>
<body>
<GTProvider translations={translations}>
<LocaleSelector />
{children}
</GTProvider>
<Scripts />
</body>
</html>
)
}
```

## Usage

Wrap content in `<T>` to translate it. Import `<T>` from `gt-react`:

```tsx title="src/routes/index.tsx"
import { createFileRoute } from '@tanstack/react-router'
import { T } from 'gt-react'

export const Route = createFileRoute('/')({ component: Home })

function Home() {
return (
<T>
<h1>Welcome to our app!</h1>
<p>This content is automatically translated.</p>
</T>
)
}
```

<Callout type="info">
Import `<T>` from `gt-react` (not `gt-tanstack-start`). The `gt` CLI scans for `gt-react` imports to find translatable content.
</Callout>

## Generate translations

### Using General Translation (recommended)

Run the `gt translate` command to generate translations:

```bash
npx gt translate
```

This sends your content to the General Translation API and downloads translated JSON files to `src/_gt/`.

You'll need environment variables for the API:

```bash title=".env"
GT_API_KEY="your-api-key"
GT_PROJECT_ID="your-project-id"
```

Get your free API keys at [dash.generaltranslation.com](https://dash.generaltranslation.com/signup) or run:

```bash
npx gt auth
```

### Manual translations

If you prefer to manage translations yourself:

1. Generate source language files:

```bash
npx gt generate
```

2. Translate the generated JSON files manually

3. Place them at `src/_gt/{locale}.json`

## Testing

Start the dev server:

<Tabs items={['npm', 'yarn', 'bun', 'pnpm']}>
<Tab value="npm">
```bash
npm run dev
```
</Tab>
<Tab value="yarn">
```bash
yarn dev
```
</Tab>
<Tab value="bun">
```bash
bun run dev
```
</Tab>
<Tab value="pnpm">
```bash
pnpm dev
```
</Tab>
</Tabs>

Visit [localhost:3000](http://localhost:3000) and use the locale selector to switch languages. Translations are loaded from local JSON files, so language switching is instant.

## Deployment

Add the translation step to your build script:

```json title="package.json"
{
"scripts": {
"build": "npx gt translate && vite build"
}
}
```

## Example app

See the complete working example: [tanstack-start-basic](https://github.com/generaltranslation/gt/tree/main/examples/tanstack-start-basic)

---

## Next steps

- Read the [overview](/docs/tanstack-start/introduction) for a deeper look at the API
- Learn about [variable components](/docs/react/guides/variables) like `<Var>`, `<Num>`, and `<Currency>`
- Explore the [`<T>` component](/docs/react/api/components/t) API reference
Loading
Loading