# gt-node: General Translation Node.js SDK: Rilevare l'impostazione regionale della richiesta
URL: https://generaltranslation.com/it/docs/node/guides/detecting-locale.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Come determinare e associare un'impostazione regionale a ogni richiesta con General Translation in gt-node.

Ogni chiamata di traduzione in `gt-node` viene eseguita usando l&#39;impostazione regionale della richiesta corrente. Determini questa impostazione regionale a partire dalla richiesta e la associ con [`withGT`](/docs/node/reference/functions/with-gt), così tutte le funzioni di traduzione successive la utilizzano.

## Associa un&#39;impostazione regionale con `withGT` [#with-gt]

Avvolgi la gestione della richiesta in `withGT(locale, fn)`. L&#39;impostazione regionale viene memorizzata per tutta la durata della richiesta, così [`getGT`](/docs/node/reference/functions/get-gt), [`getMessages`](/docs/node/reference/functions/get-messages), [`tx`](/docs/node/reference/functions/tx) e [`getLocale`](/docs/node/reference/functions/get-locale) vengono risolti in base a essa.

```ts
import { withGT } from 'gt-node';

app.use((req, res, next) => withGT(resolveLocale(req), () => next()));
```

*Nota: chiamare una funzione di traduzione o di impostazione regionale al di fuori di un contesto [`withGT`](/docs/node/reference/functions/with-gt) genera un errore in ambiente di sviluppo; in produzione ripiega sull&#39;impostazione regionale predefinita.*

## Rileva da `Accept-Language` [#accept-language]

Usa [`getRequestLocale`](/docs/node/reference/functions/get-request-locale) per scegliere l&#39;impostazione regionale supportata più adatta in base all&#39;header `Accept-Language` della richiesta, con fallback sull&#39;impostazione regionale predefinita.

```ts
import { withGT, getRequestLocale } from 'gt-node';

app.use((req, res, next) => withGT(getRequestLocale(req), () => next()));
```

## Rileva dai tuoi segnali [#custom]

Per rispettare una scelta esplicita dell&#39;utente, determina tu stesso l&#39;impostazione regionale, ad esempio da un cookie o da un segmento del percorso, e in caso contrario usa [`getRequestLocale`](/docs/node/reference/functions/get-request-locale). Passa il risultato a [`withGT`](/docs/node/reference/functions/with-gt).

```ts
function resolveLocale(req) {
  return req.cookies?.locale || getRequestLocale(req);
}

app.use((req, res, next) => withGT(resolveLocale(req), () => next()));
```

[`withGT`](/docs/node/reference/functions/with-gt) confronta il valore che passi con i `locales` configurati, quindi se un&#39;impostazione regionale non è supportata usa quella predefinita. Leggi l&#39;impostazione regionale attiva in qualsiasi punto della richiesta con [`getLocale`](/docs/node/reference/functions/get-locale).

## Next steps

- /docs/node/guides/translating-strings
- /docs/node/guides/configuring
- /docs/node/guides/storing-translations

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
