Update downloader to get speeches from tolgee

This commit is contained in:
Roman Jaroš 2025-03-02 13:25:40 +01:00
parent 5f21775771
commit e37886072f
6 changed files with 139 additions and 31 deletions

View file

@ -64,6 +64,12 @@ function makeChunks(input: AddonData, chunkSize: number = 1000) {
return result;
}
const splitFirst = (text: string, delimiter: string) => {
const index = text.indexOf(delimiter);
if (index === -1) return text;
return text.slice(index + delimiter.length);
};
(async () => {
const args = process.argv.slice(2);
const addonDir = path.join(process.cwd(), `../Addon/Data/${args[0]}`);
@ -129,11 +135,19 @@ function makeChunks(input: AddonData, chunkSize: number = 1000) {
: tolgeeKey.translations.csf.text,
],
}),
...(tolgeeKey.keyNamespace === 'speech' && {
speeches: [
tolgeeKey.translations.cs.text,
tolgeeKey.translations.cs.text === tolgeeKey.translations.csf.text
? null
: tolgeeKey.translations.csf.text,
tolgeeKey.translations.en.text,
],
}),
name: tolgeeKey.keyDescription,
id: tolgeeKey.keyName.replace('q', '').replace('i', ''),
isQuest: tolgeeKey.keyName.startsWith('q'),
isQuestItem: tolgeeKey.keyName.startsWith('i'),
isSpeech: tolgeeKey.keyName.startsWith('s'),
};
}
} else {
@ -175,10 +189,11 @@ function makeChunks(input: AddonData, chunkSize: number = 1000) {
fs.appendFileSync(fileName, luaQuestRecord, 'utf8');
}
if (czechQuest.isSpeech) {
if (czechQuest.speeches) {
let luaQuestRecord = '';
luaQuestRecord += `CzechQuestsAddon.data.item["${czechQuest.descriptions?.[2]}"] = {\n`;
luaQuestRecord += '\ttext = "' + normalizeTranslation(czechQuest.descriptions?.[0]) + '", \n';
const key = splitFirst(normalizeTranslation(czechQuest.speeches?.[2]) ?? '', ':').trim();
luaQuestRecord += `CzechQuestsAddon.data.speech["${key}"] = {\n`;
luaQuestRecord += '\ttext = "' + normalizeTranslation(czechQuest.speeches?.[0]).trim() + '", \n';
luaQuestRecord += `}\n`;
fs.appendFileSync(fileName, luaQuestRecord, 'utf8');
}
@ -195,17 +210,13 @@ type Quest = {
id: string;
name: string;
names?: (string | null)[];
description?: string;
descriptions?: (string | null)[];
progress?: string;
progresses?: (string | null)[];
completion?: string;
completions?: (string | null)[];
objective?: string;
objectives?: (string | null)[];
speeches?: (string | null)[];
isQuest: boolean;
isQuestItem: boolean;
isSpeech: boolean;
};
type TolgeeKeysData = {