# General Translation Python SDKs: TranslationsLoader
URL: https://generaltranslation.com/it/docs/python/reference/classes/translations-loader.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Il tipo callable per i loader delle traduzioni personalizzati in General Translation Python. Riferimento API per TranslationsLoader.

`TranslationsLoader` è il tipo della callback che passi come `load_translations` per fornire le tue traduzioni. Mappa un codice locale a un dizionario di traduzioni.

*Nota: `TranslationsLoader` è un **alias di tipo**, non una classe, un protocollo o un ABC. Non va sottoclassato; puoi fornire qualsiasi callable che ne rispetti la struttura.*

## Panoramica [#overview]

`TranslationsLoader` è definito come alias di `Callable`:

```python
from collections.abc import Awaitable, Callable

TranslationsLoader = Callable[[str], dict[str, str] | Awaitable[dict[str, str]]]
```

Un loader accetta un codice locale e restituisce una mappatura `dict[str, str]` dagli hash dei messaggi alle stringhe tradotte. Può essere sincrono o restituire un awaitable: il manager attende il risultato quando è awaitable.

Importa `TranslationsLoader` da `gt_i18n`. Non viene riesportato dai pacchetti del framework.

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

* **Input.** Una singola stringa di codice locale (ad esempio `"es"`).
* **Output.** Un `dict[str, str]` di hash → stringa tradotta, oppure un awaitable che restituisce tale valore.
* **Dove viene utilizzato.** Passato come `load_translations` a [`I18nManager`](/docs/python/reference/classes/i18n-manager) o [`initialize_gt`](/docs/python/reference/functions/initialize-gt). Se fornito, sostituisce il loader CDN integrato. Le chiavi devono essere hash prodotti da [`hash_message`](/docs/python/reference/functions/hash-message).

## Esempio [#example]

```python
import json
from pathlib import Path
from gt_i18n import I18nManager, TranslationsLoader

# Un loader sincrono che legge un file JSON per ogni impostazione regionale
def load_translations(locale: str) -> dict[str, str]:
    path = Path("translations") / f"{locale}.json"
    return json.loads(path.read_text()) if path.exists() else {}

loader: TranslationsLoader = load_translations
manager = I18nManager(default_locale="en", locales=["es"], load_translations=loader)
```

```python
# È valido anche un loader asincrono
async def load_translations(locale: str) -> dict[str, str]:
    return await fetch_from_somewhere(locale)
```

## Sitemap

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