( db: Db, collectionPrefix: string, translationDocs: TranslationDocument[] )
| 207 | } |
| 208 | |
| 209 | async function _refreshLocaleCollection( |
| 210 | db: Db, |
| 211 | collectionPrefix: string, |
| 212 | translationDocs: TranslationDocument[] |
| 213 | ): Promise<void> { |
| 214 | const localeCollectionName = `${collectionPrefix}locales`; |
| 215 | const localeCollection = db.collection(localeCollectionName); |
| 216 | |
| 217 | try { |
| 218 | await localeCollection.drop(); |
| 219 | } catch (err) { |
| 220 | if (!(err instanceof MongoServerError && err.codeName === 'NamespaceNotFound')) throw err; |
| 221 | } |
| 222 | |
| 223 | const localeDocs = computeLocaleDocuments(translationDocs); |
| 224 | if (localeDocs.length > 0) { |
| 225 | try { |
| 226 | await localeCollection.createIndex({ lang: 1 }, { unique: true }); |
| 227 | await localeCollection.insertMany(localeDocs, { ordered: false }); |
| 228 | console.log( |
| 229 | ` Inserted ${localeDocs.length} locale documents into '${localeCollectionName}'.` |
| 230 | ); |
| 231 | } catch (err) { |
| 232 | console.error(` Error inserting locale documents into '${localeCollectionName}':`, err); |
| 233 | throw err; |
| 234 | } |
| 235 | } else { |
| 236 | console.log(` No locales to insert into '${localeCollectionName}'.`); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Discovers all non-English locale directories under jsonDbDir, loads their |
no test coverage detected