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



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

Defined in: [src/translator/TextReplaces.ts:79](https://github.com/DRincs-Productions/pixi-vn-json/blob/f2528001a05fe854a897e0c1d03c7e311fe08af2/src/translator/TextReplaces.ts#L79)

Registers a new replacement handler.

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

The TranslatorManager translation pipeline automatically calls
[TextReplaces.replace](/pixi-vn-json/index/namespaces/TextReplaces/functions/replace) for both phases (`"before-translation"` and
`"after-translation"`), so no additional setup is required after calling `add`.

## Parameters [#parameters]

### fn [#fn]

[`ReplaceHandler`](/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`](/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 title="content/text-replaces.ts"
import { TextReplaces } from 'pixi-vn-ink'

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