LogoPixi’VN
Narration

Internalization

As explained in more detail here, Pixi’VN gives the possibility to translate the game text using a library, such as i18next. Also in ink + Pixi’VN integration you can use a library to translate the text of the ink.

Pixi’VN gives the developer the ability to intercept the translation event with the onInkTranslate function.

The onInkTranslate function has as a parameter a callback function takes as parameter the text to translate and returns the translated text.

import { onInkTranslate } from "@drincs/pixi-vn-ink";

export function initializeInk(options: { t: (key: string) => string }) {
    const { t } = options;
    onInkTranslate(t);
}

Auto-generation of translation files

Templates

In all templates, you can use the following button in the settings to automatically generate the json file that will be used for translations. dowload-translate

To facilitate the creation of the translation files, you can use the generateJsonInkTranslation function to automatically generate the JSON structure from the ink text.

import { generateJsonInkTranslation } from "@drincs/pixi-vn-ink";
import i18n from "i18next";
import { convertInkToJson } from "./utils/ink-utility";

function getLocalesResource(lng: string): Promise<any> {
    return import(`./locales/strings_${lng}.json`);
}

async function generateResourceToTranslate(lng: string): Promise<any> {
    let res = await getLocalesResource(lng);
    res = { ...res };
    if (!res) {
        res = {};
    }
    if (!res.narration) {
        res.narration = {};
    }
    if (res.default) {
        delete res.default;
    }
    (await convertInkToJson()).forEach((element) => {
        element && generateJsonInkTranslation(element, res.narration);
    });
    return res;
}

export async function downloadResourceToTranslate() {
    const lng = i18n.options.fallbackLng?.toString() || "en";
    const data = await generateResourceToTranslate(lng);
    const jsonString = JSON.stringify(data);
    // download the save data as a JSON file
    const blob = new Blob([jsonString], { type: "application/json" });
    // download the file
    const url = URL.createObjectURL(blob);
    const a = document.createElement("a");
    a.href = url;
    a.download = `strings_${lng}.json`;
    a.click();
}