# gt-node: General Translation Node.js SDK: getLocale
URL: https://generaltranslation.com/it/docs/node/reference/functions/get-locale.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Legge l'impostazione regionale attiva per la richiesta corrente in General Translation gt-node. Riferimento API per getLocale.

Restituisce l&#39;impostazione regionale attiva come codice BCP 47. Richiamala all&#39;interno di uno scope [`withGT`](/docs/node/reference/functions/with-gt) per leggere l&#39;impostazione regionale associata alla richiesta.

## Panoramica [#overview]

Chiama `getLocale` senza argomenti per ottenere il codice locale BCP 47 attivo.

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

const locale = getLocale(); // 'en-US'
```

Firma:

```ts
getLocale(): string
```

*Nota: `getLocale` deve essere chiamato all&#39;interno di una callback di [`withGT`](/docs/node/reference/functions/with-gt), in modo da sapere quale impostazione regionale usare.*

## Come funziona [#how-it-works]

* **Nell&#39;ambito della richiesta.** Legge l&#39;impostazione regionale associata alla chiamata [`withGT`](/docs/node/reference/functions/with-gt) circostante.
* **Sincrono.** Restituisce subito e non richiede `await`.

## Parametri [#parameters]

`getLocale` non accetta parametri.

## Restituisce [#returns]

**Tipo** `string`

Il codice locale BCP 47 attuale (ad esempio, `'en-US'`).

## Esempi [#examples]

```ts title="handler.js"
// Utilizzo di base
import { withGT, getLocale } from 'gt-node';

app.use((req, res, next) => {
  const locale = req.headers['accept-language']?.split(',')[0] || 'en-US';
  withGT(locale, () => {
    console.log(getLocale()); // 'en-US'
    next();
  });
});
```

## Sitemap

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