LogoPixi’VN
indexFunctions

~~Function: onReplaceTextBeforeTranslation()~~

> onReplaceTextBeforeTranslation(getTextToReplace): void

Defined in: src/functions/replace.ts:71

Parameters

getTextToReplace

(key) => string | undefined

The function to get the text to replace

Returns

void

Deprecated

Use TextReplaces instead.

This function is called before the 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 function. If there are a text is "Hello, my name is [john]", the following function will return "Hello, my name is {{john}}"

Example

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}}}`
})