Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 45x 42x 42x 42x 42x 42x 42x 40x 40x 9x 9x 9x 40x 40x 14x 14x 14x 13x 13x 9x 7x 7x 7x 3x 3x 7x 2x 2x 7x 2x 2x 2x 2x 6x | /**
* Batches all translatable short strings from a repository node into a single
* Promise.all call, then maps results back onto the node using a parallel index array.
* mapToResultIndex mirrors titleTasks: entry i is the dot-path describing where
* result i should be written, so the two arrays must always stay in sync.
*
* @param {object} node - Repository node; mutated in place with _de fields
* @param {Function} translateWithCache - translateWithCache(repo, text) → Promise
* @param {Function} shouldTranslateUI - Guard that filters out strings too long for DeepL
* @returns {Promise<void>}
*/
async function translateTitlesBatch(node, translateWithCache, shouldTranslateUI) {
if (!node || !translateWithCache || !shouldTranslateUI) return;
try {
const titleTasks = [];
// Parallel index: titleTasks[i] maps to the node path in mapToResultIndex[i]
const mapToResultIndex = [];
const summaryForTranslation = (node.summary && typeof node.summary === 'string') ? node.summary : '';
const docsTitleForTranslation = (node.docsTitle && typeof node.docsTitle === 'string') ? node.docsTitle : '';
if (shouldTranslateUI(summaryForTranslation)) { titleTasks.push(translateWithCache(node.name, summaryForTranslation)); mapToResultIndex.push(['summary']); }
if (shouldTranslateUI(docsTitleForTranslation)) { titleTasks.push(translateWithCache(node.name, docsTitleForTranslation)); mapToResultIndex.push(['docsTitle']); }
if (node.repoDocs) {
if (node.repoDocs.apiDocumentation && shouldTranslateUI(node.repoDocs.apiDocumentation.title)) { titleTasks.push(translateWithCache(node.name, node.repoDocs.apiDocumentation.title)); mapToResultIndex.push(['repoDocs','apiDocumentation','title']); }
if (node.repoDocs.architectureOverview && shouldTranslateUI(node.repoDocs.architectureOverview.title)) { titleTasks.push(translateWithCache(node.name, node.repoDocs.architectureOverview.title)); mapToResultIndex.push(['repoDocs','architectureOverview','title']); }
if (node.repoDocs.testing && node.repoDocs.testing.testingDocs && shouldTranslateUI(node.repoDocs.testing.testingDocs.title)) { titleTasks.push(translateWithCache(node.name, node.repoDocs.testing.testingDocs.title)); mapToResultIndex.push(['repoDocs','testing','testingDocs','title']); }
}
const results = await Promise.all(titleTasks);
for (let ri = 0; ri < results.length; ri++) {
const res = results[ri] || { text: null };
const pathArr = mapToResultIndex[ri];
if (!pathArr || !Array.isArray(pathArr) || !res || !res.text) continue;
try {
if (pathArr.length === 1 && pathArr[0] === 'summary') node.summary_de = res.text;
else if (pathArr.length === 1 && pathArr[0] === 'docsTitle') node.docsTitle_de = res.text;
else Eif (pathArr[0] === 'repoDocs') {
Iif (!node.repoDocs) node.repoDocs = {};
if (pathArr[1] === 'apiDocumentation') {
node.repoDocs.apiDocumentation = node.repoDocs.apiDocumentation || {};
node.repoDocs.apiDocumentation.title_de = res.text;
}
if (pathArr[1] === 'architectureOverview') {
node.repoDocs.architectureOverview = node.repoDocs.architectureOverview || {};
node.repoDocs.architectureOverview.title_de = res.text;
}
if (pathArr[1] === 'testing' && pathArr[2] === 'testingDocs') {
node.repoDocs.testing = node.repoDocs.testing || {};
node.repoDocs.testing.testingDocs = node.repoDocs.testing.testingDocs || {};
node.repoDocs.testing.testingDocs.title_de = res.text;
}
}
} catch (e) { /* ignore mapping failures */ }
}
} catch (e) { if (process.env.DEBUG_FETCH === '1' || process.env.DEBUG_FETCH === 'true') console.log('translateTitlesBatch error', e && e.message); }
}
module.exports = { translateTitlesBatch };
|