> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mastermindcms.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TranslationManager

> Translation helpers exported by msm-components

`TranslationManager` wraps i18next and adds helpers for loading translations from MastermindCMS.

## Initialization

Before you use `translate()`, set the locales JSON path once:

```js theme={null}
setLocalesPath("/path/to/locales/{{lng}}.json");
```

In an application, point the path to public locale files:

```js theme={null}
import { setLocalesPath } from "msm-components/dist/services.js";

setLocalesPath("/admin/assets/locales/{{lng}}.json");
```

The `{{lng}}` placeholder is replaced with the current language. Initialize it once when the application starts.

## Exports

From `msm-components` you can use:

* `setLocalesPath(loadPath)`
* `translate(...args)`
* `translations` (a proxy for lazy translation access)
* `tr(key, repository?)` (loads/returns a single translation)
* `loadTranslation(key, repository?)`
* `loadManyTranslations(...keys)`
* `loadByLangCodeForEntity(entityId, lang, repository?)`
* `loadByLangCode(key, lang)`
* `loadTranslationById(id)`
* `clearTranslationsCache()`
* `getLanguages()`
* `getAlphabetForActiveLanguage()`

## Examples

```js theme={null}
import { setLocalesPath, translate } from "msm-components/dist/services.js";

setLocalesPath("/assets/locales/{{lng}}.json");
const title = await translate("DashboardTitle");
const greeting = await translate("Greeting", { name: "Alex" });
```

Load several values at once:

```js theme={null}
import { loadManyTranslations } from "msm-components/dist/services.js";

const texts = await loadManyTranslations(
  "UserConfirmationDialogTitle",
  "UserConfirmationButtonOk",
  "AbortButton"
);
```

`tr` and `translations` lazily load values from the translation repository:

```js theme={null}
import { tr, translations } from "msm-components/dist/services.js";

const label = await tr("SaveButton");
const cancelLabel = await translations.CancelButton;
```

## Notes

* If `setLocalesPath()` was not called, translation functions throw an error to make the misconfiguration obvious.
* The helper uses the unified service call mechanism under the hood (service/repository calls), so it relies on the built-in client instance provided by `msm-components`.
* Use `clearTranslationsCache()` when the active locale data has changed.
