# General Translation Overview: Uso degli agenti di coding URL: https://generaltranslation.com/it/docs/overview/for-coding-agents.mdx --- title: Uso degli agenti di coding description: Come usare agenti di coding IA e LLMs con General Translation, indirizzandoli alla documentazione in formato leggibile dalle macchine, al server MCP e alla nostra guida pronta all'uso per agenti. --- General Translation è progettato per funzionare con agenti di coding IA e LLMs. Le librerie sono open-source, la configurazione è prevedibile e la documentazione è pubblicata in formati leggibili dalle macchine. Un agente come Cursor, Claude Code o Copilot può aggiungere ed eseguire General Translation per te con un contesto accurato e aggiornato. *Per una localizzazione completamente automatizzata che apra pull request in autonomia, usa invece il nostro agente dedicato [Locadex](/docs/platform/locadex/quickstart) anziché affidarti a un agente personalizzato.* ## Guida rapida per agente [#agent-guide] Fornisci al tuo agente tutto ciò di cui ha bisogno con un solo copia e incolla. Copia la guida qui sotto in un file `AGENTS.md` (o `CLAUDE.md`, una regola di Cursor o il file di istruzioni del tuo strumento) nella radice del progetto e il tuo agente aggiungerà ed eseguirà General Translation correttamente. Usa il pulsante Copia nell'angolo in alto a destra del blocco. ````markdown title="AGENTS.md" # General Translation — agent guide Instructions for AI coding agents adding [General Translation](https://generaltranslation.com) to a project. General Translation is a full-stack localization product: open-source i18n libraries plus a CLI that translate an app and its content into any language. Follow these rules when internationalizing code or wiring up translations. ## What to use Pick the package that matches the stack: - **Next.js (App Router or Pages Router)** → `gt-next` - **React (SPA, e.g. Vite)** → `gt-react` - **Node.js server** → `gt-node` - **Any JavaScript runtime, or lower-level control** → `generaltranslation` (the Core library) - **Translating content files (JSON, MDX, YAML, and more) or running translation in CI** → the `gt` CLI All of these are free and open-source. The libraries work with or without a General Translation account; an API key unlocks on-demand translation in development and the hosted translation API. ## Setup Prefer the wizard. From the project root, run: ```bash npx gt init ``` It installs the right library and the `gt` CLI, wires up the framework (for Next.js, adds `withGTConfig` and `GTProvider`), creates `gt.config.json`, and generates API credentials. For manual setup, install the packages yourself: ```bash npm install gt-next # or gt-react / gt-node / generaltranslation npm install -D gt ``` Then create `gt.config.json` in the project root — this is the single source of truth for locales: ```json { "defaultLocale": "en", "locales": ["es", "fr", "ja"], "files": { "gt": { "output": "public/_gt/[locale].json" } } } ``` - `defaultLocale` — the language the source is written in. - `locales` — the languages to translate into. - `files.gt.output` — where the CLI writes translation files (`[locale]` is replaced per language). Add this directory to `.gitignore`; the files are generated. Set API credentials as environment variables (in `.env.local` for Next.js, `.env` otherwise): ```bash GT_API_KEY="gtx-dev-..." # gtx-dev- in development, gtx-api- in production/CI GT_PROJECT_ID="..." ``` Never commit `GT_API_KEY`, expose it to the browser, or prefix it with `NEXT_PUBLIC_`. ## Core usage Wrap user-facing JSX in ``. Write source copy directly — no translation keys needed: ```tsx import { T } from 'gt-next'; // or 'gt-react' // Everything inside is translated as a unit

Welcome to my app

; ``` Use `useGT()` for standalone strings (placeholders, `aria-label`, `alt`, button labels). `useGT()` returns the translation function directly: ```tsx import { useGT } from 'gt-next'; const gt = useGT(); // ✅ correct // const { gt } = useGT(); // ❌ wrong — useGT returns the function, not an object ; ``` In async App Router components, use `getGT` instead. `gt-next/server` does not work with the Pages Router: ```tsx import { getGT } from 'gt-next/server'; const gt = await getGT(); ``` Wrap dynamic or private values (names, emails, IDs) in `` so they are not translated and never sent to the API. Use ``, ``, and `` for values that should be reformatted but not translated: ```tsx import { T, Var } from 'gt-next'; // Generates one translation, keeps the name unchanged Hello, {name}! ; ``` For Node.js servers, initialize once and resolve translations per request: ```js import { initializeGT, withGT, getGT } from 'gt-node'; initializeGT({ defaultLocale: 'en', locales: ['en', 'es', 'fr'] }); // wrap handlers in withGT(locale, ...); then `const gt = await getGT()` inside them ``` Keep all locale configuration in `gt.config.json` — do not scatter locale lists across the codebase. ## Commands | Command | When to run | | --- | --- | | `npx gt init` | Once, to set up a project (installs deps, configures the framework, creates `gt.config.json`, generates credentials). | | `npx gt configure` | To create or update `gt.config.json` (locales and files) without the full wizard. | | `npx gt auth` | To generate or refresh API credentials. | | `npx gt translate` | To translate the project via the General Translation API. Run in CI **before** building for production. | | `npx gt generate` | To create translation file templates to translate manually (no API key needed). | Add translation to the production build so translations stay current, for example: `"build": "npx gt translate && next build"`. ## Rules — do and don't Do: - Wrap every new piece of user-facing copy in `` (or `useGT()`/`getGT()` for standalone strings) as you write it. - Run `npx gt translate` before committing or building for production so new copy is translated. - Keep the locale list in `gt.config.json` only. - Wrap dynamic and private values in ``, and add `context` when a string is ambiguous. Don't: - Hardcode already-translated strings in the source, or add per-language `if`/`switch` branches — translate the source copy instead. - Hand-edit generated translation files (the CLI overwrites them). - Commit `GT_API_KEY` or expose it to the client. - Duplicate the locale configuration outside `gt.config.json`. ## Links - [`llms.txt`](/llms.txt) — indice della documentazione, breve e leggibile da macchina. - [`llms-full.txt`](/llms-full.txt) — contenuto completo della documentazione per strumenti in grado di caricare un contesto più ampio. - [`sitemap.xml`](/sitemap.xml) — mappa di tutte le pagine pubblicate. - Quickstarts: [React](/docs/react/react-quickstart), [Node](/docs/node/quickstart), [Core library](/docs/platform/core/quickstart), and the [CLI](/docs/cli/quickstart). - [Key concepts](/docs/overview/key-concepts) — locales, context, and static vs. dynamic content. ```` ## Indirizza gli agenti alla documentazione [#point-agents] Fornisci al tuo agente l'accesso diretto alla documentazione, così le sue risposte resteranno accurate. General Translation pubblica diversi punti di accesso leggibili dalle macchine nella radice del sito e sotto `/docs` sull'host della documentazione: * [`llms.txt`](/llms.txt) — un breve indice della documentazione in stile [llmstxt.org](https://llmstxt.org/). * [`llms-full.txt`](/llms-full.txt) — l'intero contenuto della documentazione in un unico file, escluso il riferimento OpenAPI generato. * [`sitemap.xml`](/sitemap.xml) — una mappa leggibile dalle macchine di tutte le pagine pubblicate. L'host della documentazione espone anche questi file in `/docs/llms.txt` e `/docs/llms-full.txt`. Ogni pagina della documentazione è disponibile anche come **Markdown non elaborato**: aggiungi `.md` o `.mdx` a qualsiasi URL di pagina (ad esempio `/docs/cli/quickstart.mdx`) per ottenere il sorgente pulito invece di analizzare l'HTML renderizzato. Per aggiungere la documentazione come contesto, incolla un URL della documentazione o il link a `llms.txt` nel contesto del tuo agente, oppure aggiungi la documentazione come sorgente negli strumenti che supportano l'indicizzazione della documentazione. ## Server MCP [#mcp] General Translation offre un server [Model Context Protocol](https://modelcontextprotocol.io) (MCP) che consente agli agenti di interrogare direttamente la documentazione. È disponibile in due forme: * **Locale (stdio)** — il pacchetto npm pubblicato [`@generaltranslation/mcp`](https://www.npmjs.com/package/@generaltranslation/mcp), da eseguire sulla tua macchina con `npx`. Ideale per gli strumenti che mantengono una connessione persistente, come Cursor e Claude Code. * **Remoto (HTTP/SSE)** — un endpoint ospitato su `https://mcp.gtx.dev`. Usa l'endpoint SSE solo se il tuo strumento non supporta HTTP in streaming. Configura la connessione usando il trasporto supportato dal tuo strumento. La struttura della configurazione è identica per tutti gli strumenti: aggiungila al file di configurazione MCP del tuo strumento (ad esempio, `.mcp.json`): ```json title=".mcp.json" { "mcpServers": { "generaltranslation": { "command": "npx", "args": ["-y", "@generaltranslation/mcp@latest"] } } } ``` ```json title=".mcp.json" { "mcpServers": { "generaltranslation": { "type": "streamable-http", "url": "https://mcp.gtx.dev" } } } ``` ```json title=".mcp.json" { "mcpServers": { "generaltranslation": { "type": "sse", "url": "https://mcp.gtx.dev/sse" } } } ``` Una volta connesso, chiedi al tuo agente di usare il server MCP `generaltranslation`. *Esempio: "Usa il server MCP generaltranslation per spiegare come usare un componente [``](/docs/react/reference/components/t)."* ## Suggerimenti specifici per gli editor [#editor-tips] La maggior parte della configurazione è uguale per tutti gli agenti; questi sono i pochi punti in cui le indicazioni cambiano. * **Cursor** — registra il server MCP, poi chiedigli di "usare lo strumento `generaltranslation`". Aggiungi la documentazione come sorgente oppure fai riferimento a `/llms.txt` nel prompt. * **Claude Code** — legge automaticamente un file `AGENTS.md` nella radice, quindi basta inserire la [guida dell'agente](#agent-guide) nel file `AGENTS.md` del tuo progetto per prepararlo. Registra il server MCP e chiedigli di "usare il server MCP `generaltranslation`". * **Copilot** — inserisci le indicazioni valide per tutto il repo nel file delle istruzioni (ad esempio `.github/copilot-instructions.md`) e fai riferimento lì a `/llms.txt` della documentazione. ## Best practice [#best-practices] Gli agenti sono affidabili per il lavoro meccanico di i18n, ma per la qualità della traduzione e la configurazione serve comunque l'intervento umano. Usa questa suddivisione: * **Affida all'agente:** racchiudere il testo visibile agli utenti in [``](/docs/react/reference/components/t), aggiungere [`useGT()`](/docs/react/reference/hooks/use-gt) per le stringhe standalone, impostare `gt.config.json` ed eseguire [`npx gt init`](/docs/cli/reference/commands/init). * **Verifica manualmente:** il [contesto di traduzione](/docs/overview/key-concepts#context) (Glossario e Direttive) scritto dall'agente, la configurazione delle impostazioni regionali (`defaultLocale` e `locales`) e che i valori dinamici o privati siano racchiusi in [``](/docs/react/reference/components/var). * **Non lasciare mai all'agente:** la modifica manuale dei file di traduzione generati o l'inserimento nel codice di stringhe già tradotte invece di tradurre il testo sorgente con la CLI.