MCPcopy Create free account
hub / github.com/5e-bits/5e-database / _handleTranslationFileAdded

Function _handleTranslationFileAdded

scripts/update/processor.ts:388–420  ·  view source on GitHub ↗
(db: Db, filepath: string)

Source from the content-addressed store, hash-verified

386}
387
388async function _handleTranslationFileAdded(db: Db, filepath: string): Promise<void> {
389 const ctx = await resolveTranslationContext(filepath);
390 if (!ctx) return;
391 const { lang, indexName, enMap } = ctx;
392
393 const transData = await readFileContent(filepath);
394
395 console.log(`\nProcessing Added translation ${filepath}...`);
396
397 const collectionPrefix = getCollectionPrefix(filepath);
398 const translationCollection = db.collection(`${collectionPrefix}translations`);
399
400 const ops: AnyBulkWriteOperation<Document>[] = [];
401 for (const entry of transData) {
402 const doc = buildTranslationDoc(entry as Record<string, unknown>, enMap, indexName, lang);
403 if (!doc) continue;
404 ops.push({
405 [MONGO_OP_UPDATE_ONE]: {
406 filter: {
407 source_collection: doc.source_collection,
408 source_index: doc.source_index,
409 lang: doc.lang,
410 },
411 update: { $set: doc },
412 upsert: true,
413 },
414 });
415 }
416
417 if (ops.length > 0) await translationCollection.bulkWrite(ops, { ordered: false });
418 console.log(` Processed ${ops.length} translation entries.`);
419 await _refreshLocaleStatsForLang(db, filepath, lang);
420}
421
422async function _handleTranslationFileModified(db: Db, filepath: string): Promise<void> {
423 // enPath is read from disk (post-commit), so if the English source was also modified in the

Callers 1

processFileUpdateFunction · 0.85

Calls 5

getCollectionPrefixFunction · 0.90
buildTranslationDocFunction · 0.90
readFileContentFunction · 0.85

Tested by

no test coverage detected