# Localizer

## 🌐 Localizer Class

Assists with localizing `TextElement` and `TextMeshProUGUI` objects.

> **Namespace:** `Esper.Inventool.Localization`\
> **Access:** `public`\
> **Type:** `static class`

***

### 📦 Fields

| Access           | Field                          | Type                                                       | Description                                                                  |
| ---------------- | ------------------------------ | ---------------------------------------------------------- | ---------------------------------------------------------------------------- |
| `private static` | `localizedEventReferences`     | `Dictionary<TextElement, LocalizedEventReference>`         | Keeps track of registered localization events for `TextElement` objects.     |
| `private static` | `localizedEventReferencesUGUI` | `Dictionary<TextMeshProUGUI, LocalizedEventReferenceUGUI>` | Keeps track of registered localization events for `TextMeshProUGUI` objects. |

***

### 🧰 Methods

| Access          | Method                                                                                                                             | Returns | Description                                                                                                         |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------- |
| `public static` | `Localize(TextElement textElement, string tableName, string key, Func<string, string> extraStep = null)`                           | `void`  | Sets up localization for a `TextElement`. Optionally applies an extra step to the localized string.                 |
| `public static` | `Localize(TextMeshProUGUI textMesh, string tableName, string key, Func<string, string> extraStep = null, Action finalStep = null)` | `void`  | Sets up localization for a `TextMeshProUGUI`. Optionally applies an extra step and a final step after localization. |
| `public static` | `CleanEvents()`                                                                                                                    | `void`  | Unregisters all localization events of removed `TextElement` and `TextMeshProUGUI` objects.                         |
| `public static` | `RemoveAllEvents()`                                                                                                                | `void`  | Unregisters all localization events.                                                                                |

***

### 🧩 Nested Types

#### `private class LocalizedEventReference`

| Field             | Type                            | Description                           |
| ----------------- | ------------------------------- | ------------------------------------- |
| `textElement`     | `TextElement`                   | The associated text element.          |
| `localizedString` | `LocalizedString`               | The localized string reference.       |
| `changeHandler`   | `LocalizedString.ChangeHandler` | The handler for string change events. |

#### `private class LocalizedEventReferenceUGUI`

| Field             | Type                            | Description                           |
| ----------------- | ------------------------------- | ------------------------------------- |
| `textMesh`        | `TextMeshProUGUI`               | The associated TMP text object.       |
| `localizedString` | `LocalizedString`               | The localized string reference.       |
| `changeHandler`   | `LocalizedString.ChangeHandler` | The handler for string change events. |

## Localize

Use the Localize method to localize a TextElement.

```csharp
Localizer.Localize(myTextElement, "String Table Name", "String Key");
```
