(db: Db, filepath: string)
| 386 | } |
| 387 | |
| 388 | async 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 | |
| 422 | async 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 |
no test coverage detected