# General Translation React SDKs (gt-react, gt-next, gt-react-native): decodeVars
URL: https://generaltranslation.com/it/docs/react/reference/functions/decode-vars.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Espande le variabili codificate da declareVar riportandole ai loro valori. Riferimento API per decodeVars.

La funzione `decodeVars` estrae i valori originali dalle stringhe che contengono marcatori [`declareVar`](/docs/react/reference/functions/declare-var). Poiché [`declareVar`](/docs/react/reference/functions/declare-var) aggiunge marcatori compatibili con ICU al testo sorgente, questi marcatori possono interferire con la logica di elaborazione delle stringhe: `decodeVars` li rimuove.

*Disponibile in `gt-react`, `gt-next`, `gt-tanstack-start` e `gt-react-native`.*

## Panoramica [#overview]

Passa una stringa contenente i marcatori [`declareVar`](/docs/react/reference/functions/declare-var) e `decodeVars` la restituisce con i valori originali reinseriti al loro posto.

```tsx
function getGreeting({ name }) {
  const greeting = 'Hello, ' + declareVar(name);
  // "Hello, {_gt_, select, other {Brian}}"

  return decodeVars(greeting);
  // "Hello, Brian" — come se declareVar non fosse mai stata usata
}
```

*Nota: `decodeVars` ha effetto solo sulle stringhe sorgente che contengono i marcatori [`declareVar`](/docs/react/reference/functions/declare-var). Non ha effetto sulle stringhe tradotte e non è un parser generico per ICU MessageFormat.*

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

`decodeVars` agisce sui pattern ICU MessageFormat creati da [`declareVar`](/docs/react/reference/functions/declare-var), interpolando ogni variabile `_gt_` nel suo valore originale e preservando esattamente tutto il resto del contenuto. Usalo quando una logica esistente di manipolazione delle stringhe deve essere eseguita su una stringa che contiene marcatori di variabili.

## Parametri [#parameters]

| Parametro                  | Descrizione                                                                                                                 | Tipo     | Facoltativo | Predefinito |
| -------------------------- | --------------------------------------------------------------------------------------------------------------------------- | -------- | ----------- | ----------- |
| [`icuString`](#icu-string) | Una stringa contenente marcatori ICU generati dalle chiamate a [`declareVar`](/docs/react/reference/functions/declare-var). | `string` | No          | —           |

### `icuString` [#icu-string]

**Tipo** `string` · **Obbligatorio**

Una stringa che contiene marcatori ICU prodotti da [`declareVar`](/docs/react/reference/functions/declare-var).

## Restituisce [#returns]

**Tipo** `string`

La stringa da cui sono stati rimossi i marcatori ICU, contenente i valori originali delle variabili.

## Esempi [#examples]

*Gli esempi importano da `gt-react`; importa invece dal package del tuo framework.*

```tsx title="BasicUsage.tsx"
import { declareVar, decodeVars } from 'gt-react';

const encodedVar = declareVar(name);
// "{_gt_, select, other {Alice}}"
const decodedVar = decodeVars(encodedVar);
// "Alice"
```

```tsx title="MultipleVariables.tsx"
import { declareVar, decodeVars } from 'gt-react';

const name1 = 'Alice';
const name2 = 'Bob';
const encodedVar =
  'Hello, ' + declareVar(name1) + '! My name is ' + declareVar(name2);
// "Hello, {_gt_, select, other {Alice}}! My name is {_gt_, select, other {Bob}}"

const decodedVar = decodeVars(encodedVar);
// "Hello, Alice! My name is Bob"
```

## Note [#notes]

* Usa `decodeVars` solo su stringhe che contengono i marcatori [`declareVar`](/docs/react/reference/functions/declare-var).
* È pensato per i pattern ICU creati da [`declareVar`](/docs/react/reference/functions/declare-var) e non va usato su stringhe ICU arbitrarie.
* Non influisce sull&#39;elaborazione delle traduzioni: rimuove solo i marcatori per la manipolazione delle stringhe.

## Sitemap

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