Refactor Encounters, use new translations format for save space
This commit is contained in:
parent
7d9f58650a
commit
908f45eb9b
59 changed files with 103852 additions and 58396 deletions
|
@ -1,95 +1,26 @@
|
|||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
import axios from 'axios';
|
||||
import dotenv from 'dotenv';
|
||||
import { callTolgee } from './utils/callTolgee';
|
||||
import {
|
||||
buildTree,
|
||||
getEncounterGroupKey,
|
||||
getEncounterKey,
|
||||
writeEncounter,
|
||||
writeEncounterStructure,
|
||||
} from './utils/entities/encounter';
|
||||
import { TolgeeKey, TolgeeTranslationsResponse } from './types';
|
||||
import { writeQuest } from './utils/entities/quest';
|
||||
import { writeBook } from './utils/entities/book';
|
||||
import { writeSpeech } from './utils/entities/speech';
|
||||
|
||||
dotenv.config({ path: '.env' }).parsed;
|
||||
|
||||
const normalizeTranslation = (translation: string | null | undefined) => {
|
||||
if (translation == null) {
|
||||
return '';
|
||||
}
|
||||
return translation.replace(/\n/g, '\\n').replace(/"/g, "'");
|
||||
};
|
||||
|
||||
function getSplitByIndexes(input: string, indexes: number[]): string[] {
|
||||
const parts = input.split('_');
|
||||
return indexes.map((index) => parts[index]).filter((item) => item !== undefined);
|
||||
}
|
||||
|
||||
const prepareLuaWithFemaleVersion = (quest: Quest, type: keyof Quest, key: string) => {
|
||||
let text = '';
|
||||
const value = quest[type] as string;
|
||||
const normalizedMaleValue = normalizeTranslation(value?.[0]);
|
||||
const normalizedFemaleValue = normalizeTranslation(value?.[1]);
|
||||
if (normalizedMaleValue != '') {
|
||||
text += '\t' + key + 'Male = "' + normalizedMaleValue + '", \n';
|
||||
}
|
||||
if (normalizedFemaleValue != '') {
|
||||
text += '\t' + key + 'Female = "' + normalizedFemaleValue + '", \n';
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
const callTolgee = async <R>(
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE' = 'GET',
|
||||
path: string,
|
||||
params?: any,
|
||||
data?: any,
|
||||
) => {
|
||||
const args = process.argv.slice(2);
|
||||
const projectId = args[1];
|
||||
try {
|
||||
return await axios<R>(`https://translate.romanjaros.local/v2/projects/${projectId}${path}`, {
|
||||
method,
|
||||
data,
|
||||
params,
|
||||
headers: {
|
||||
'X-API-KEY': process.env.TOLGEE_PAT as string,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
function makeChunks(input: AddonData, chunkSize: number = 1000) {
|
||||
const keys = Object.keys(input);
|
||||
const result = [];
|
||||
|
||||
for (let i = 0; i < keys.length; i += chunkSize) {
|
||||
const chunk = keys.slice(i, i + chunkSize).reduce((acc: AddonData, key) => {
|
||||
acc[key] = input[key];
|
||||
return acc;
|
||||
}, {});
|
||||
result.push(chunk);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const splitFirst = (text: string, delimiter: string) => {
|
||||
const index = text.indexOf(delimiter);
|
||||
if (index === -1) return text;
|
||||
return text.slice(index + delimiter.length);
|
||||
};
|
||||
|
||||
const generateRoleTactic = (role: (string | null)[]) => {
|
||||
let luaQuestRecord = '';
|
||||
for (const ability of role) {
|
||||
if (ability == null) continue;
|
||||
const information = ability.split('\n');
|
||||
luaQuestRecord += `\t\t{"${information[0].trim()}","${information[1].trim()}","${information[2].trim()}","${information[3].trim()}"},\n`;
|
||||
}
|
||||
return luaQuestRecord;
|
||||
};
|
||||
|
||||
(async () => {
|
||||
const args = process.argv.slice(2);
|
||||
const addonDir = path.join(process.cwd(), `../Addon/Data/${args[0]}`);
|
||||
|
||||
const addonData: Record<string, Quest> = {};
|
||||
const addonData: TolgeeKey[][] = [];
|
||||
let pageNumber = 0;
|
||||
|
||||
try {
|
||||
|
@ -98,242 +29,63 @@ const generateRoleTactic = (role: (string | null)[]) => {
|
|||
const response = await callTolgee<TolgeeTranslationsResponse>('GET', `/translations`, {
|
||||
filterTranslatedInLang: 'cs',
|
||||
languages: 'cs,csf,en',
|
||||
size: 2000,
|
||||
size: 1000,
|
||||
page: pageNumber,
|
||||
});
|
||||
const translations = response.data?._embedded?.keys ?? [];
|
||||
if (response.data?.page.totalPages > response.data?.page.number) {
|
||||
pageNumber++;
|
||||
|
||||
// for each page from tolgee
|
||||
addonData[pageNumber] = [];
|
||||
for (const tolgeeKey of translations) {
|
||||
let key = tolgeeKey.keyName;
|
||||
|
||||
if (tolgeeKey.keyNamespace === 'tactic') {
|
||||
key = key.split('_')[0];
|
||||
}
|
||||
|
||||
const instanceName = getSplitByIndexes(tolgeeKey.keyName, [1, 2]).join('_');
|
||||
|
||||
addonData[key] = {
|
||||
...addonData[tolgeeKey.keyName],
|
||||
...(tolgeeKey.keyNamespace === 'name' && {
|
||||
names: [
|
||||
tolgeeKey.translations.cs.text,
|
||||
tolgeeKey.translations.cs.text === tolgeeKey.translations.csf.text
|
||||
? null
|
||||
: tolgeeKey.translations.csf.text,
|
||||
],
|
||||
}),
|
||||
...(tolgeeKey.keyNamespace === 'objective' && {
|
||||
objectives: [
|
||||
tolgeeKey.translations.cs.text,
|
||||
tolgeeKey.translations.cs.text === tolgeeKey.translations.csf.text
|
||||
? null
|
||||
: tolgeeKey.translations.csf.text,
|
||||
],
|
||||
}),
|
||||
...(tolgeeKey.keyNamespace === 'description' && {
|
||||
descriptions: [
|
||||
tolgeeKey.translations.cs.text,
|
||||
tolgeeKey.translations.cs.text === tolgeeKey.translations.csf.text
|
||||
? null
|
||||
: tolgeeKey.translations.csf.text,
|
||||
tolgeeKey.translations.en.text,
|
||||
],
|
||||
}),
|
||||
...(tolgeeKey.keyNamespace === 'progress' && {
|
||||
progresses: [
|
||||
tolgeeKey.translations.cs.text,
|
||||
tolgeeKey.translations.cs.text === tolgeeKey.translations.csf.text
|
||||
? null
|
||||
: tolgeeKey.translations.csf.text,
|
||||
],
|
||||
}),
|
||||
...(tolgeeKey.keyNamespace === 'completion' && {
|
||||
completions: [
|
||||
tolgeeKey.translations.cs.text,
|
||||
tolgeeKey.translations.cs.text === tolgeeKey.translations.csf.text
|
||||
? null
|
||||
: 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,
|
||||
],
|
||||
}),
|
||||
...(tolgeeKey.keyNamespace === 'tactic' && {
|
||||
tactics: {
|
||||
[instanceName]: {
|
||||
...(addonData[key]?.tactics?.[instanceName] ?? {}),
|
||||
...(tolgeeKey.keyName.endsWith('_summary') && {
|
||||
summary: tolgeeKey.translations.cs.text,
|
||||
}),
|
||||
...(tolgeeKey.keyName.includes('_tank_') && {
|
||||
tank: [...(addonData[key].tactics?.[instanceName]?.tank ?? []), tolgeeKey.translations.cs.text],
|
||||
}),
|
||||
...(tolgeeKey.keyName.includes('_healer_') && {
|
||||
healer: [...(addonData[key].tactics?.[instanceName]?.healer ?? []), tolgeeKey.translations.cs.text],
|
||||
}),
|
||||
...(tolgeeKey.keyName.includes('_dps_') && {
|
||||
dps: [...(addonData[key].tactics?.[instanceName]?.dps ?? []), tolgeeKey.translations.cs.text],
|
||||
}),
|
||||
},
|
||||
},
|
||||
}),
|
||||
name: tolgeeKey.keyDescription,
|
||||
id: tolgeeKey.keyName.replace('q', '').replace('i', ''),
|
||||
isQuest: tolgeeKey.keyName.startsWith('q'),
|
||||
isQuestItem: tolgeeKey.keyName.startsWith('i'),
|
||||
};
|
||||
addonData[pageNumber].push(tolgeeKey);
|
||||
}
|
||||
pageNumber++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// split into chunks
|
||||
const chunks = makeChunks(addonData);
|
||||
const encounterKeys: Record<string, string[]> = {};
|
||||
let fileIndex = 0;
|
||||
|
||||
// build addon file
|
||||
chunks.forEach((chunk, index) => {
|
||||
const fileName = path.join(addonDir, `${index++}.lua`);
|
||||
addonData.forEach((chunk, index) => {
|
||||
fileIndex = index;
|
||||
const fileName = path.join(addonDir, `${fileIndex++}.lua`);
|
||||
try {
|
||||
fs.unlinkSync(fileName);
|
||||
} catch (e) {}
|
||||
fs.appendFileSync(fileName, 'local _, addon = ...\n', 'utf8');
|
||||
for (const [, czechQuest] of Object.entries(chunk)) {
|
||||
// prepare variables
|
||||
if (czechQuest.isQuest) {
|
||||
let luaQuestRecord = '';
|
||||
luaQuestRecord += `addon.data.quest[${czechQuest.id}] = {\n`;
|
||||
luaQuestRecord += prepareLuaWithFemaleVersion(czechQuest, 'names', 'title');
|
||||
luaQuestRecord += prepareLuaWithFemaleVersion(czechQuest, 'objectives', 'objective');
|
||||
luaQuestRecord += prepareLuaWithFemaleVersion(czechQuest, 'descriptions', 'description');
|
||||
luaQuestRecord += prepareLuaWithFemaleVersion(czechQuest, 'progresses', 'progress');
|
||||
luaQuestRecord += prepareLuaWithFemaleVersion(czechQuest, 'completions', 'completion');
|
||||
luaQuestRecord += `}\n`;
|
||||
fs.appendFileSync(fileName, luaQuestRecord, 'utf8');
|
||||
}
|
||||
|
||||
if (czechQuest.isQuestItem) {
|
||||
const page = czechQuest.id.split('_page')?.[1] ?? null;
|
||||
const variableId = `"${czechQuest.name}${page ? `__${page}` : ''}"`;
|
||||
let luaQuestRecord = '';
|
||||
luaQuestRecord += `addon.data.item[${variableId}] = {\n`;
|
||||
luaQuestRecord += '\ttitle = "' + normalizeTranslation(czechQuest.name) + '", \n';
|
||||
luaQuestRecord += '\ttext = "' + normalizeTranslation(czechQuest.descriptions?.[0]) + '", \n';
|
||||
luaQuestRecord += `}\n`;
|
||||
fs.appendFileSync(fileName, luaQuestRecord, 'utf8');
|
||||
}
|
||||
|
||||
if (czechQuest.speeches) {
|
||||
let luaQuestRecord = '';
|
||||
const key = splitFirst(normalizeTranslation(czechQuest.speeches?.[2]) ?? '', ': ').trim();
|
||||
const npcNameKey = normalizeTranslation(czechQuest.name).trim();
|
||||
luaQuestRecord += `addon.data.speech["${npcNameKey}_${key}"] = {\n`;
|
||||
luaQuestRecord += '\ttext = "' + normalizeTranslation(czechQuest.speeches?.[0]).trim() + '", \n';
|
||||
luaQuestRecord += `}\n`;
|
||||
fs.appendFileSync(fileName, luaQuestRecord, 'utf8');
|
||||
}
|
||||
|
||||
if (czechQuest.tactics) {
|
||||
let luaQuestRecord = '';
|
||||
const npcNameKey = normalizeTranslation(czechQuest.name).trim();
|
||||
luaQuestRecord += `addon.data.tactic["${npcNameKey}"] = {\n`;
|
||||
for (const [instance, roles] of Object.entries(czechQuest.tactics)) {
|
||||
luaQuestRecord += `\t${instance} = {\n`;
|
||||
luaQuestRecord += `\t\tsummary = "${roles.summary}",\n`;
|
||||
luaQuestRecord += `\t\ttank = {\n`;
|
||||
if (roles.tank) luaQuestRecord += generateRoleTactic(roles.tank);
|
||||
luaQuestRecord += `\t\t},\n`;
|
||||
luaQuestRecord += `\t\theal = {\n`;
|
||||
if (roles.healer) luaQuestRecord += generateRoleTactic(roles.healer);
|
||||
luaQuestRecord += `\t\t},\n`;
|
||||
luaQuestRecord += `\t\tdps = {\n`;
|
||||
if (roles.dps) luaQuestRecord += generateRoleTactic(roles.dps);
|
||||
luaQuestRecord += `\t\t},\n`;
|
||||
luaQuestRecord += `\t},\n`;
|
||||
}
|
||||
luaQuestRecord += `}\n`;
|
||||
fs.appendFileSync(fileName, luaQuestRecord, 'utf8');
|
||||
for (const [, key] of Object.entries(chunk)) {
|
||||
switch (key.keyNamespace) {
|
||||
case 'quest':
|
||||
fs.appendFileSync(fileName, writeQuest(key), 'utf8');
|
||||
break;
|
||||
case 'book':
|
||||
fs.appendFileSync(fileName, writeBook(key), 'utf8');
|
||||
break;
|
||||
case 'speech':
|
||||
fs.appendFileSync(fileName, writeSpeech(key), 'utf8');
|
||||
break;
|
||||
case 'encounter':
|
||||
const groupId = getEncounterGroupKey(key);
|
||||
encounterKeys[groupId] = encounterKeys[groupId] ?? [];
|
||||
encounterKeys[groupId].push(getEncounterKey(key));
|
||||
fs.appendFileSync(fileName, writeEncounter(key), 'utf8');
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const fileName = path.join(addonDir, `${fileIndex++}.lua`);
|
||||
try {
|
||||
fs.unlinkSync(fileName);
|
||||
} catch (e) {}
|
||||
fs.appendFileSync(fileName, 'local _, addon = ...\n', 'utf8');
|
||||
Object.entries(encounterKeys).forEach(([key, encounterKeys]) => {
|
||||
const structure = buildTree(encounterKeys);
|
||||
fs.appendFileSync(fileName, writeEncounterStructure(key, structure), 'utf8');
|
||||
});
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
})();
|
||||
|
||||
type AddonData = Record<string, Quest>;
|
||||
|
||||
type Tactic = {
|
||||
summary?: string | null;
|
||||
tank?: (string | null)[];
|
||||
healer?: (string | null)[];
|
||||
dps?: (string | null)[];
|
||||
};
|
||||
|
||||
type InstanceTactic = {
|
||||
[key: string]: Tactic;
|
||||
};
|
||||
|
||||
type Quest = {
|
||||
id: string;
|
||||
name: string;
|
||||
names?: (string | null)[];
|
||||
descriptions?: (string | null)[];
|
||||
progresses?: (string | null)[];
|
||||
completions?: (string | null)[];
|
||||
objectives?: (string | null)[];
|
||||
speeches?: (string | null)[];
|
||||
tactics?: InstanceTactic;
|
||||
isQuest: boolean;
|
||||
isQuestItem: boolean;
|
||||
};
|
||||
|
||||
type TolgeeKeysData = {
|
||||
keyId: number;
|
||||
keyName: string;
|
||||
keyNamespace: string;
|
||||
keyDescription: string;
|
||||
keyTags: TolgeeTag[];
|
||||
translations: {
|
||||
en: {
|
||||
id: number;
|
||||
text: string;
|
||||
state: 'REVIEWED' | 'TRANSLATED';
|
||||
};
|
||||
cs: {
|
||||
id: number;
|
||||
text: string | null;
|
||||
state: 'REVIEWED' | 'TRANSLATED';
|
||||
};
|
||||
csf: {
|
||||
id: number;
|
||||
text: string | null;
|
||||
state: 'REVIEWED' | 'TRANSLATED';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
type TolgeeTag = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
type TolgeeTranslationsResponse = {
|
||||
_embedded: {
|
||||
keys: TolgeeKeysData[];
|
||||
};
|
||||
page: {
|
||||
size: number;
|
||||
totalElements: number;
|
||||
totalPages: number;
|
||||
number: number;
|
||||
};
|
||||
};
|
||||
|
|
45
.support/types.ts
Normal file
45
.support/types.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
export type TolgeeKey = {
|
||||
keyId: number;
|
||||
keyName: string;
|
||||
keyNamespace: string;
|
||||
keyDescription: string;
|
||||
keyTags: TolgeeTag[];
|
||||
translations: {
|
||||
en: {
|
||||
id: number;
|
||||
text: string;
|
||||
state: 'REVIEWED' | 'TRANSLATED';
|
||||
};
|
||||
cs: {
|
||||
id: number;
|
||||
text: string | null;
|
||||
state: 'REVIEWED' | 'TRANSLATED';
|
||||
};
|
||||
csf: {
|
||||
id: number;
|
||||
text: string | null;
|
||||
state: 'REVIEWED' | 'TRANSLATED';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export type TolgeeTag = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type TolgeeTranslationsResponse = {
|
||||
_embedded: {
|
||||
keys: TolgeeKey[];
|
||||
};
|
||||
page: {
|
||||
size: number;
|
||||
totalElements: number;
|
||||
totalPages: number;
|
||||
number: number;
|
||||
};
|
||||
};
|
||||
|
||||
export type TreeNode = {
|
||||
key: string;
|
||||
children: TreeNode[];
|
||||
};
|
4
.support/utils/array.ts
Normal file
4
.support/utils/array.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export function splitByIndexes(input: string, indexes: number[]): string[] {
|
||||
const parts = input.split('_');
|
||||
return indexes.map((index) => parts[index]).filter((item) => item !== undefined);
|
||||
}
|
23
.support/utils/callTolgee.ts
Normal file
23
.support/utils/callTolgee.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import axios from 'axios';
|
||||
|
||||
export const callTolgee = async <R>(
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE' = 'GET',
|
||||
path: string,
|
||||
params?: any,
|
||||
data?: any,
|
||||
) => {
|
||||
const args = process.argv.slice(2);
|
||||
const projectId = args[1];
|
||||
try {
|
||||
return await axios<R>(`https://translate.romanjaros.local/v2/projects/${projectId}${path}`, {
|
||||
method,
|
||||
data,
|
||||
params,
|
||||
headers: {
|
||||
'X-API-KEY': process.env.TOLGEE_PAT as string,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
};
|
10
.support/utils/entities/book.ts
Normal file
10
.support/utils/entities/book.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { TolgeeKey } from '../../types';
|
||||
import { writeAlsoFemaleTranslation } from '../translation';
|
||||
|
||||
export const writeBook = (tolgeeKey: TolgeeKey): string => {
|
||||
let luaRecord = '';
|
||||
luaRecord += `addon.data.book["${tolgeeKey.keyName}"] = {\n`;
|
||||
luaRecord += writeAlsoFemaleTranslation(tolgeeKey.translations);
|
||||
luaRecord += `}\n`;
|
||||
return luaRecord;
|
||||
};
|
61
.support/utils/entities/encounter.ts
Normal file
61
.support/utils/entities/encounter.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
import { TolgeeKey, TreeNode } from '../../types';
|
||||
import { writeAlsoFemaleTranslation } from '../translation';
|
||||
|
||||
export function buildTree(inputs: string[], layer = ''): TreeNode[] {
|
||||
const root: TreeNode[] = [];
|
||||
inputs
|
||||
.filter((input) => new RegExp(`_(${layer})([0-9]{2})$`).test(input))
|
||||
.forEach((input) => {
|
||||
const layerIndex = input.split('_').at(-1);
|
||||
root.push({
|
||||
key: input,
|
||||
children: buildTree(inputs, layerIndex),
|
||||
});
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
export const getEncounterKey = (tolgeeKey: TolgeeKey): string => {
|
||||
const [, difficulty, instance, type, key] = tolgeeKey.keyName.split('_');
|
||||
return [tolgeeKey.keyDescription, difficulty, instance, type, key].join('_');
|
||||
};
|
||||
|
||||
export const getEncounterGroupKey = (tolgeeKey: TolgeeKey): string => {
|
||||
const [, difficulty, instance] = tolgeeKey.keyName.split('_');
|
||||
return [tolgeeKey.keyDescription, difficulty, instance].join('_');
|
||||
};
|
||||
|
||||
export const writeEncounter = (tolgeeKey: TolgeeKey): string => {
|
||||
let luaRecord = '';
|
||||
const keyName = getEncounterKey(tolgeeKey);
|
||||
|
||||
luaRecord += `addon.data.encounter["${keyName}"] = {\n`;
|
||||
luaRecord += writeAlsoFemaleTranslation(tolgeeKey.translations);
|
||||
luaRecord += `}\n`;
|
||||
return luaRecord;
|
||||
};
|
||||
|
||||
const writeStructure = (structure: TreeNode[], layer = 0): string => {
|
||||
let luaRecord = '';
|
||||
const tab = '\t'.repeat(layer);
|
||||
const layerIndex = layer + 1;
|
||||
structure.forEach((node) => {
|
||||
const hasEmptyChildren = node.children.length === 0;
|
||||
luaRecord += `${tab}{\n`;
|
||||
luaRecord += `\t${tab}key = "${node.key}",\n`;
|
||||
luaRecord += `\t${tab}children = {${hasEmptyChildren ? '' : '\n'}`;
|
||||
luaRecord += `${writeStructure(node.children, layerIndex)}`;
|
||||
luaRecord += `${hasEmptyChildren ? '' : `\t${tab}`}},\n`;
|
||||
luaRecord += `${tab}},\n`;
|
||||
});
|
||||
return luaRecord;
|
||||
};
|
||||
|
||||
export const writeEncounterStructure = (key: string, structure: TreeNode[]): string => {
|
||||
let luaRecord = '';
|
||||
luaRecord += `addon.data.encounter["${key}"] = {\n`;
|
||||
luaRecord += writeStructure(structure);
|
||||
luaRecord += `}\n`;
|
||||
return luaRecord;
|
||||
};
|
10
.support/utils/entities/quest.ts
Normal file
10
.support/utils/entities/quest.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { TolgeeKey } from '../../types';
|
||||
import { writeAlsoFemaleTranslation } from '../translation';
|
||||
|
||||
export const writeQuest = (tolgeeKey: TolgeeKey): string => {
|
||||
let luaRecord = '';
|
||||
luaRecord += `addon.data.quest["${tolgeeKey.keyName}"] = {\n`;
|
||||
luaRecord += writeAlsoFemaleTranslation(tolgeeKey.translations);
|
||||
luaRecord += `}\n`;
|
||||
return luaRecord;
|
||||
};
|
10
.support/utils/entities/speech.ts
Normal file
10
.support/utils/entities/speech.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { TolgeeKey } from '../../types';
|
||||
import { normalize, writeMaleTranslation } from '../translation';
|
||||
|
||||
export const writeSpeech = (tolgeeKey: TolgeeKey): string => {
|
||||
let luaRecord = '';
|
||||
luaRecord += `addon.data.speech["${normalize(tolgeeKey.keyDescription)}_${tolgeeKey.keyName}"] = {\n`;
|
||||
luaRecord += writeMaleTranslation(tolgeeKey.translations);
|
||||
luaRecord += `}\n`;
|
||||
return luaRecord;
|
||||
};
|
30
.support/utils/translation.ts
Normal file
30
.support/utils/translation.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { TolgeeKey } from '../types';
|
||||
|
||||
export const normalize = (translation: string | null | undefined) => {
|
||||
if (translation == null) {
|
||||
return '';
|
||||
}
|
||||
return translation.replace(/\n/g, '\\n').replace(/"/g, "'");
|
||||
};
|
||||
|
||||
export const writeMaleTranslation = (value: TolgeeKey['translations']) => {
|
||||
let text = '';
|
||||
const normalizedValue = normalize(value?.['cs']?.text);
|
||||
if (normalizedValue != '') {
|
||||
text += '\tm = "' + normalizedValue + '", \n';
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
export const writeAlsoFemaleTranslation = (value: TolgeeKey['translations']) => {
|
||||
let text = '';
|
||||
const normalizedMaleValue = normalize(value?.['cs']?.text);
|
||||
const normalizedFemaleValue = normalize(value?.['csf']?.text);
|
||||
if (normalizedMaleValue != '') {
|
||||
text += '\tm = "' + normalizedMaleValue + '", \n';
|
||||
}
|
||||
if (normalizedFemaleValue != '' && normalizedMaleValue != normalizedFemaleValue) {
|
||||
text += '\tf = "' + normalizedFemaleValue + '", \n';
|
||||
}
|
||||
return text;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue