# Function: add() (/jsdoc/pixi-vn-json/index/namespaces/TextReplaces/functions/add)



\> **add**(`fn`, `handlerOptions`): `void`

Defined in: [src/handlers/TextReplaces.ts:88](https://github.com/DRincs-Productions/pixi-vn-json/blob/336c45bc1f677c3b088aac058f0a457afc7cf32e/src/handlers/TextReplaces.ts#L88)

Registers a new replacement handler.

Handlers are executed in the order they are added. The first handler added runs first.

When the first handler of a given type (`"before-translation"` or `"after-translation"`)
is registered, the corresponding translator hook (`translator.beforeToTranslate` or
`translator.afterToTranslate`) is automatically set so that `TextReplaces` takes exclusive
ownership of that hook. Do **not** mix `TextReplaces` with the deprecated
onReplaceTextBeforeTranslation / onReplaceTextAfterTranslation functions
for the same phase, as they will overwrite each other's hook.

Parameters [#parameters]

fn [#fn]

[`ReplaceHandler`](/jsdoc/pixi-vn-json/index/type-aliases/ReplaceHandler)

The handler function. Receives the key found inside `[...]` and should return
the replacement string, or `undefined` to leave that token unchanged.

handlerOptions [#handleroptions]

[`ReplaceHandlerOptions`](/jsdoc/pixi-vn-json/index/type-aliases/ReplaceHandlerOptions)

Configuration for this handler, including its name, optional
description, validation regex, and execution phase.

Returns [#returns]

`void`

Example [#example]

```ts
import { TextReplaces } from 'pixi-vn-ink'

TextReplaces.add(
    (key) => key === "player" ? "Mario" : undefined,
    {
        name: "player-name",
        validation: /^player$/,
    }
)
```
