# ~~Function: onReplaceTextBeforeTranslation()~~ (/jsdoc/pixi-vn-ink/index/functions/onReplaceTextBeforeTranslation)



\> **onReplaceTextBeforeTranslation**(`getTextToReplace`): `void`

Defined in: [src/functions/replace.ts:71](https://github.com/DRincs-Productions/pixi-vn-ink/blob/cf876d4db655e65b32a20a362a828ecba73f4786/src/functions/replace.ts#L71)

Parameters [#parameters]

getTextToReplace [#gettexttoreplace]

(`key`) => `string` | `undefined`

The function to get the text to replace

Returns [#returns]

`void`

Deprecated [#deprecated]

Use [TextReplaces](/jsdoc/pixi-vn-ink/index/namespaces/TextReplaces) instead.

This function is called before the [onInkTranslate](/jsdoc/pixi-vn-ink/index/functions/onInkTranslate) function is called.
It will replace the text between square brackets.
It can be used for example to replace the normal method for replacing the text \[key] with a new method to replace the text \{\{key}}.
It can be used for example to optimize the text replacement with i18next, using the [onInkTranslate](/jsdoc/pixi-vn-ink/index/functions/onInkTranslate) function.
If there are a text is "Hello, my name is \[john]", the following function will return "Hello, my name is \{\{john}}"

Example [#example]

```ts
import { onReplaceTextBeforeTranslation, onInkTranslate } from 'pixi-vn-ink'
import { useTranslation } from "react-i18next";
import { john } from "../values/characters"

const { t } = useTranslation(["narration"]);

onInkTranslate((text) => {
    return t(text, {
        john: john.name
    })
})

onReplaceTextBeforeTranslation((key) => {
    return `{{${key}}}`
})
```
