All files / scripts/lib/translation translatorFacade.js

100% Statements 9/9
100% Branches 8/8
100% Functions 1/1
100% Lines 7/7

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  3x                         36x 35x 35x 3x 35x     3x  
#!/usr/bin/env node
const orchestrator = require('./translationOrchestrator');
 
/**
 * Translates all short UI strings on a repository node to German.
 * Delegates to translateTitlesBatch so the caller does not need to know which
 * fields are translatable or how batching works.
 *
 * @param {object} node - Repository node; mutated in place with _de fields
 * @param {Function} translateWithCache - Per-repo cached translation function
 * @param {Function} shouldTranslateUI - Guard that filters strings too long for DeepL
 * @returns {Promise<object>} The same node
 */
async function translateNode(node, translateWithCache, shouldTranslateUI) {
  if (!node) return node;
  try {
    await orchestrator.translateTitlesBatch(node, translateWithCache, shouldTranslateUI);
  } catch (e) { if (process.env.DEBUG_FETCH === '1' || process.env.DEBUG_FETCH === 'true') console.log('translateNode error', e && e.message); }
  return node;
}
 
module.exports = { translateNode };