@intlayer/cli 5.7.7 → 5.8.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/cjs/fill.cjs +82 -54
  2. package/dist/cjs/fill.cjs.map +1 -1
  3. package/dist/esm/fill.mjs +86 -56
  4. package/dist/esm/fill.mjs.map +1 -1
  5. package/dist/types/fill.d.ts +1 -0
  6. package/dist/types/fill.d.ts.map +1 -1
  7. package/package.json +15 -15
  8. package/dist/cjs/cli.test.cjs +0 -435
  9. package/dist/cjs/cli.test.cjs.map +0 -1
  10. package/dist/cjs/utils/calculateChunks.test.cjs +0 -104
  11. package/dist/cjs/utils/calculateChunks.test.cjs.map +0 -1
  12. package/dist/cjs/utils/checkFileModifiedRange.test.cjs +0 -175
  13. package/dist/cjs/utils/checkFileModifiedRange.test.cjs.map +0 -1
  14. package/dist/cjs/utils/fixChunkStartEndChars.test.cjs +0 -81
  15. package/dist/cjs/utils/fixChunkStartEndChars.test.cjs.map +0 -1
  16. package/dist/cjs/utils/formatTimeDiff.test.cjs +0 -32
  17. package/dist/cjs/utils/formatTimeDiff.test.cjs.map +0 -1
  18. package/dist/cjs/utils/getChunk.test.cjs +0 -46
  19. package/dist/cjs/utils/getChunk.test.cjs.map +0 -1
  20. package/dist/cjs/utils/getOutputFilePath.test.cjs +0 -73
  21. package/dist/cjs/utils/getOutputFilePath.test.cjs.map +0 -1
  22. package/dist/cjs/utils/listSpecialChars.test.cjs +0 -58
  23. package/dist/cjs/utils/listSpecialChars.test.cjs.map +0 -1
  24. package/dist/cjs/utils/reorderParagraphs.test.cjs +0 -71
  25. package/dist/cjs/utils/reorderParagraphs.test.cjs.map +0 -1
  26. package/dist/cjs/utils/splitTextByLine.test.cjs +0 -14
  27. package/dist/cjs/utils/splitTextByLine.test.cjs.map +0 -1
  28. package/dist/esm/cli.test.mjs +0 -412
  29. package/dist/esm/cli.test.mjs.map +0 -1
  30. package/dist/esm/utils/calculateChunks.test.mjs +0 -103
  31. package/dist/esm/utils/calculateChunks.test.mjs.map +0 -1
  32. package/dist/esm/utils/checkFileModifiedRange.test.mjs +0 -181
  33. package/dist/esm/utils/checkFileModifiedRange.test.mjs.map +0 -1
  34. package/dist/esm/utils/fixChunkStartEndChars.test.mjs +0 -80
  35. package/dist/esm/utils/fixChunkStartEndChars.test.mjs.map +0 -1
  36. package/dist/esm/utils/formatTimeDiff.test.mjs +0 -31
  37. package/dist/esm/utils/formatTimeDiff.test.mjs.map +0 -1
  38. package/dist/esm/utils/getChunk.test.mjs +0 -45
  39. package/dist/esm/utils/getChunk.test.mjs.map +0 -1
  40. package/dist/esm/utils/getOutputFilePath.test.mjs +0 -72
  41. package/dist/esm/utils/getOutputFilePath.test.mjs.map +0 -1
  42. package/dist/esm/utils/listSpecialChars.test.mjs +0 -57
  43. package/dist/esm/utils/listSpecialChars.test.mjs.map +0 -1
  44. package/dist/esm/utils/reorderParagraphs.test.mjs +0 -70
  45. package/dist/esm/utils/reorderParagraphs.test.mjs.map +0 -1
  46. package/dist/esm/utils/splitTextByLine.test.mjs +0 -13
  47. package/dist/esm/utils/splitTextByLine.test.mjs.map +0 -1
  48. package/dist/types/cli.test.d.ts +0 -2
  49. package/dist/types/cli.test.d.ts.map +0 -1
  50. package/dist/types/utils/calculateChunks.test.d.ts +0 -2
  51. package/dist/types/utils/calculateChunks.test.d.ts.map +0 -1
  52. package/dist/types/utils/checkFileModifiedRange.test.d.ts +0 -2
  53. package/dist/types/utils/checkFileModifiedRange.test.d.ts.map +0 -1
  54. package/dist/types/utils/fixChunkStartEndChars.test.d.ts +0 -2
  55. package/dist/types/utils/fixChunkStartEndChars.test.d.ts.map +0 -1
  56. package/dist/types/utils/formatTimeDiff.test.d.ts +0 -2
  57. package/dist/types/utils/formatTimeDiff.test.d.ts.map +0 -1
  58. package/dist/types/utils/getChunk.test.d.ts +0 -2
  59. package/dist/types/utils/getChunk.test.d.ts.map +0 -1
  60. package/dist/types/utils/getOutputFilePath.test.d.ts +0 -2
  61. package/dist/types/utils/getOutputFilePath.test.d.ts.map +0 -1
  62. package/dist/types/utils/listSpecialChars.test.d.ts +0 -2
  63. package/dist/types/utils/listSpecialChars.test.d.ts.map +0 -1
  64. package/dist/types/utils/reorderParagraphs.test.d.ts +0 -2
  65. package/dist/types/utils/reorderParagraphs.test.d.ts.map +0 -1
  66. package/dist/types/utils/splitTextByLine.test.d.ts +0 -2
  67. package/dist/types/utils/splitTextByLine.test.d.ts.map +0 -1
package/dist/cjs/fill.cjs CHANGED
@@ -37,8 +37,10 @@ var import_config = require("@intlayer/config");
37
37
  var import_core = require("@intlayer/core");
38
38
  var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
39
39
  var import_unmerged_dictionaries_entry = __toESM(require("@intlayer/unmerged-dictionaries-entry"));
40
+ var import_p_limit = __toESM(require("p-limit"));
40
41
  var import_path = require("path");
41
42
  var import_checkAIAccess = require('./utils/checkAIAccess.cjs');
43
+ const NB_CONCURRENT_TRANSLATIONS = 5;
42
44
  const ensureArray = (value) => [value].flat();
43
45
  const getTargetDictionary = async (options) => {
44
46
  const configuration = (0, import_config.getConfiguration)(options.configOptions);
@@ -259,12 +261,22 @@ const fill = async (options) => {
259
261
  );
260
262
  continue;
261
263
  }
262
- appLogger(
263
- `Processing content declaration: ${targetUnmergedDictionary.filePath}`,
264
- {
265
- isVerbose: true
266
- }
264
+ if (!targetUnmergedDictionary.filePath) {
265
+ appLogger(
266
+ `Dictionary with key "${dictionaryKey}" has no file path. Skipping.`,
267
+ {
268
+ level: "warn"
269
+ }
270
+ );
271
+ continue;
272
+ }
273
+ const relativePath = (0, import_path.relative)(
274
+ configuration.content.baseDir,
275
+ targetUnmergedDictionary.filePath
267
276
  );
277
+ appLogger(`Processing content declaration: ${relativePath}`, {
278
+ isVerbose: true
279
+ });
268
280
  const sourceLocaleContent = (0, import_core.getLocalisedContent)(
269
281
  mainDictionaryToProcess,
270
282
  sourceLocale,
@@ -280,66 +292,81 @@ const fill = async (options) => {
280
292
  continue;
281
293
  }
282
294
  const result = [];
283
- for await (const targetLocale of outputLocalesList) {
284
- appLogger(
285
- `Preparing translation for ${dictionaryKey} from ${sourceLocale} to ${targetLocale}`,
286
- {
287
- isVerbose: true
288
- }
289
- );
290
- const presetOutputContent = (0, import_core.getLocalisedContent)(
291
- mainDictionaryToProcess,
292
- targetLocale,
293
- { dictionaryKey, keyPath: [] }
294
- );
295
- try {
296
- const translationResult = await (0, import_api.getAiAPI)(
297
- void 0,
298
- configuration
299
- ).translateJSON(
300
- {
301
- entryFileContent: sourceLocaleContent.content,
302
- // Should be JSON, ensure getLocalisedContent provides this.
303
- presetOutputContent: presetOutputContent.content,
304
- // Should be JSON
305
- dictionaryDescription: mainDictionaryToProcess.description,
306
- entryLocale: sourceLocale,
307
- outputLocale: targetLocale,
308
- mode,
309
- aiOptions: options.aiOptions
310
- },
295
+ const limit = (0, import_p_limit.default)(
296
+ options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS
297
+ );
298
+ const translationPromises = outputLocalesList.map(
299
+ (targetLocale) => limit(async () => {
300
+ appLogger(
301
+ `Preparing translation for '${dictionaryKey}' dictionary from ${(0, import_core.getLocaleName)(
302
+ sourceLocale,
303
+ import_config.Locales.ENGLISH
304
+ )} (${sourceLocale}) to ${(0, import_core.getLocaleName)(targetLocale, import_config.Locales.ENGLISH)} (${targetLocale})`,
311
305
  {
312
- ...oAuth2AccessToken && {
313
- headers: {
314
- Authorization: `Bearer ${oAuth2AccessToken}`
306
+ isVerbose: true
307
+ }
308
+ );
309
+ const presetOutputContent = (0, import_core.getLocalisedContent)(
310
+ mainDictionaryToProcess,
311
+ targetLocale,
312
+ { dictionaryKey, keyPath: [] }
313
+ );
314
+ try {
315
+ const translationResult = await (0, import_api.getAiAPI)(
316
+ void 0,
317
+ configuration
318
+ ).translateJSON(
319
+ {
320
+ entryFileContent: sourceLocaleContent.content,
321
+ // Should be JSON, ensure getLocalisedContent provides this.
322
+ presetOutputContent: presetOutputContent.content,
323
+ // Should be JSON
324
+ dictionaryDescription: mainDictionaryToProcess.description,
325
+ entryLocale: sourceLocale,
326
+ outputLocale: targetLocale,
327
+ mode,
328
+ aiOptions: options.aiOptions
329
+ },
330
+ {
331
+ ...oAuth2AccessToken && {
332
+ headers: {
333
+ Authorization: `Bearer ${oAuth2AccessToken}`
334
+ }
315
335
  }
316
336
  }
337
+ );
338
+ if (!translationResult.data?.fileContent) {
339
+ appLogger(
340
+ `No content result found for ${dictionaryKey} to ${targetLocale}`,
341
+ {
342
+ level: "error"
343
+ }
344
+ );
345
+ return null;
317
346
  }
318
- );
319
- if (!translationResult.data?.fileContent) {
347
+ const processedPerLocaleDictionary = (0, import_chokidar.processPerLocaleDictionary)({
348
+ ...mainDictionaryToProcess,
349
+ content: translationResult.data?.fileContent,
350
+ locale: targetLocale
351
+ });
352
+ return processedPerLocaleDictionary;
353
+ } catch (error) {
320
354
  appLogger(
321
- `No content result found for ${dictionaryKey} to ${targetLocale}`,
355
+ `Error filling ${dictionaryKey} to ${targetLocale}:` + error,
322
356
  {
323
357
  level: "error"
324
358
  }
325
359
  );
326
- continue;
360
+ return null;
327
361
  }
328
- const processedPerLocaleDictionary = (0, import_chokidar.processPerLocaleDictionary)({
329
- ...mainDictionaryToProcess,
330
- content: translationResult.data?.fileContent,
331
- locale: targetLocale
332
- });
333
- result.push(processedPerLocaleDictionary);
334
- } catch (error) {
335
- appLogger(
336
- `Error filling ${dictionaryKey} to ${targetLocale}:` + error,
337
- {
338
- level: "error"
339
- }
340
- );
362
+ })
363
+ );
364
+ const translationResults = await Promise.all(translationPromises);
365
+ translationResults.forEach((translationResult) => {
366
+ if (translationResult) {
367
+ result.push(translationResult);
341
368
  }
342
- }
369
+ });
343
370
  const dictionaryToMerge = mode === "review" ? [...result, mainDictionaryToProcess] : [mainDictionaryToProcess, ...result];
344
371
  const mergedResults = (0, import_chokidar.mergeDictionaries)(dictionaryToMerge);
345
372
  let formattedDict = targetUnmergedDictionary;
@@ -360,6 +387,7 @@ const fill = async (options) => {
360
387
  configuration,
361
388
  formattedDict.filePath
362
389
  );
390
+ if (!formattedDict.autoFill) return;
363
391
  await autoFill(
364
392
  mergedResults,
365
393
  targetUnmergedDictionary,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fill.ts"],"sourcesContent":["import { AIOptions, getAiAPI, getOAuthAPI } from '@intlayer/api'; // Importing only getAiAPI for now\nimport {\n getFilteredLocalesContent,\n listGitFiles,\n ListGitFilesOptions,\n mergeDictionaries,\n processPerLocaleDictionary,\n reduceDictionaryContent,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n type IntlayerConfig,\n Locales,\n} from '@intlayer/config';\nimport {\n type AutoFill,\n type ContentNode,\n type Dictionary,\n getLocalisedContent,\n} from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport unmergedDictionariesRecord from '@intlayer/unmerged-dictionaries-entry';\nimport { dirname, extname, join } from 'path';\nimport { checkAIAccess } from './utils/checkAIAccess';\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locales;\n outputLocales?: Locales | Locales[];\n file?: string | string[];\n mode?: 'complete' | 'review';\n keys?: string | string[];\n excludedKeys?: string | string[];\n filter?: (entry: Dictionary) => boolean; // DictionaryEntry needs to be defined\n pathFilter?: string | string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n};\n\nconst ensureArray = <T>(value: T | T[]): T[] => [value].flat() as T[];\n\nconst getTargetDictionary = async (options: FillOptions) => {\n const configuration = getConfiguration(options.configOptions);\n\n const { baseDir } = configuration.content;\n\n let result = Object.values(unmergedDictionariesRecord).flat();\n\n // 1. if filePath not defined, list all content declaration files based on unmerged dictionaries list\n if (typeof options.file !== 'undefined') {\n const fileArray = ensureArray(options.file);\n const absoluteFilePaths = fileArray.map((file) => join(baseDir, file));\n\n result = result.filter(\n (dict) =>\n dict.filePath &&\n (absoluteFilePaths.includes(dict.filePath) ||\n absoluteFilePaths.includes(join(baseDir, dict.filePath)))\n );\n }\n\n if (typeof options.keys !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.keys)?.includes(dict.key)\n );\n }\n\n if (typeof options.excludedKeys !== 'undefined') {\n result = result.filter(\n (dict) => !ensureArray(options.excludedKeys)?.includes(dict.key)\n );\n }\n\n if (typeof options.pathFilter !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.pathFilter)?.includes(dict.filePath ?? '')\n );\n }\n\n if (typeof options.filter !== 'undefined') {\n result = result.filter(options.filter);\n }\n\n const gitOptions = options.gitOptions;\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n result = result.filter((dict) => {\n if (!dict.filePath) return false;\n\n return gitChangedFiles.some((gitFile) => dict.filePath === gitFile);\n });\n }\n }\n\n return result.filter((dict) => !dict.autoFilled);\n};\n\nconst transformUriToAbsolutePath = (\n uri: string,\n filePath: string,\n baseDir: string\n) => {\n if (uri.startsWith('/')) {\n return join(baseDir, uri);\n }\n\n if (uri.startsWith('./')) {\n return join(dirname(filePath), uri);\n }\n\n return filePath;\n};\n\nexport type AutoFillData = {\n localeList: Locales[];\n filePath: string;\n};\n\nconst formatAutoFillData = (\n autoFillOptions: AutoFill,\n localeList: Locales[],\n filePath: string,\n dictionaryKey: string,\n configuration: IntlayerConfig\n): AutoFillData[] => {\n const outputContentDeclarationFile: AutoFillData[] = [];\n\n if (!Boolean(autoFillOptions)) return outputContentDeclarationFile;\n\n if (autoFillOptions === true) {\n // wanted jsonFilePath: /..../src/components/home/index.content.json\n // replace file extension in json\n let jsonFilePath = filePath.replace(extname(filePath), '.json');\n\n // if both filePath jsonFilePath are same path, change it as : /..../src/components/home/index.fill.content.json\n if (filePath === jsonFilePath) {\n jsonFilePath = jsonFilePath.replace(extname(jsonFilePath), '.fill.json');\n }\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: jsonFilePath,\n });\n }\n\n if (typeof autoFillOptions === 'string') {\n if (autoFillOptions.includes('{{locale}}')) {\n const output = localeList.map((locale) => ({\n localeList: [locale],\n filePath: transformUriToAbsolutePath(\n autoFillOptions\n .replace('{{locale}}', locale)\n .replace('{{key}}', dictionaryKey),\n filePath,\n configuration.content.baseDir\n ),\n }));\n\n outputContentDeclarationFile.push(...output);\n } else {\n outputContentDeclarationFile.push({\n localeList,\n filePath: transformUriToAbsolutePath(\n autoFillOptions,\n filePath,\n configuration.content.baseDir\n ),\n });\n }\n\n return outputContentDeclarationFile;\n }\n\n if (typeof autoFillOptions === 'object') {\n const localeList = Object.keys(autoFillOptions).filter(\n (locale) => typeof autoFillOptions[locale] === 'string'\n ) as Locales[];\n\n const output: AutoFillData[] = localeList.map((locale) => ({\n localeList: [locale],\n filePath: transformUriToAbsolutePath(\n autoFillOptions[locale].replace('{{key}}', dictionaryKey),\n filePath,\n configuration.content.baseDir\n ),\n }));\n\n // Group by filePath and merge localeList\n const groupedByFilePath = output.reduce((acc, curr) => {\n const existing = acc.find((item) => item.filePath === curr.filePath);\n if (existing) {\n existing.localeList.push(...curr.localeList);\n } else {\n acc.push(curr);\n }\n return acc;\n }, [] as AutoFillData[]);\n\n outputContentDeclarationFile.push(...groupedByFilePath);\n }\n\n return outputContentDeclarationFile;\n};\n\nconst autoFill = async (\n fullDictionary: Dictionary,\n contentDeclarationFile: Dictionary,\n autoFillOptions: AutoFill,\n outputLocales: Locales[],\n parentLocales: Locales[],\n configuration: IntlayerConfig\n) => {\n const appLogger = getAppLogger(configuration);\n let localeList: Locales[] = (\n outputLocales ?? configuration.internationalization.locales\n ).filter((locale) => !parentLocales?.includes(locale));\n\n const filePath = contentDeclarationFile.filePath;\n\n if (!filePath) {\n appLogger('No file path found for dictionary', {\n level: 'error',\n });\n return;\n }\n\n const autoFillData: AutoFillData[] = formatAutoFillData(\n autoFillOptions,\n localeList,\n filePath,\n fullDictionary.key,\n configuration\n );\n\n appLogger(`Auto fill data: ${JSON.stringify(autoFillData, null, 2)}`, {\n level: 'info',\n isVerbose: true,\n });\n\n for await (const output of autoFillData) {\n const reducedDictionary = reduceDictionaryContent(\n fullDictionary,\n contentDeclarationFile\n );\n\n const isPerLocaleDeclarationFile = output.localeList.length === 1;\n\n if (isPerLocaleDeclarationFile) {\n const sourceLocale = output.localeList[0];\n\n const sourceLocaleContent = getLocalisedContent(\n reducedDictionary as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey: reducedDictionary.key, keyPath: [] }\n );\n\n await writeContentDeclaration({\n ...fullDictionary,\n locale: sourceLocale,\n autoFilled: true,\n autoFill: undefined,\n content: sourceLocaleContent.content,\n filePath: output.filePath,\n });\n } else {\n const content = getFilteredLocalesContent(\n reducedDictionary.content as unknown as ContentNode,\n output.localeList,\n { dictionaryKey: reducedDictionary.key, keyPath: [] }\n );\n\n // write file\n await writeContentDeclaration({\n ...fullDictionary,\n autoFilled: true,\n autoFill: undefined,\n content,\n filePath: output.filePath,\n });\n }\n }\n};\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options.mode ?? 'review';\n const baseLocale = options.sourceLocale ?? defaultLocale;\n\n checkAIAccess(configuration, options.aiOptions);\n\n let oAuth2AccessToken: string | undefined;\n if (configuration.editor.clientId) {\n const intlayerAuthAPI = getOAuthAPI(configuration);\n const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();\n\n oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n }\n\n appLogger('Starting fill function', {\n level: 'info',\n });\n\n const targetUnmergedDictionaries = await getTargetDictionary(options);\n\n // Determine output locales\n const outputLocalesList: Locales[] = (\n options.outputLocales ? ensureArray(options.outputLocales) : locales\n ).filter((locale) =>\n // If mode is review, translate all locales\n // If mode is complete, translate only the locales that are not the source locale\n mode === 'review' ? true : locale !== baseLocale\n );\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n appLogger(\n [\n 'Affected dictionary keys for processing:',\n Array.from(affectedDictionaryKeys).join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n\n for (const targetUnmergedDictionary of targetUnmergedDictionaries) {\n const dictionaryKey = targetUnmergedDictionary.key;\n const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];\n const sourceLocale: Locales =\n (targetUnmergedDictionary.locale as Locales) ?? baseLocale;\n\n if (!mainDictionaryToProcess) {\n appLogger(\n `Dictionary with key \"${dictionaryKey}\" not found in dictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n appLogger(\n `Processing content declaration: ${targetUnmergedDictionary.filePath}`,\n {\n isVerbose: true,\n }\n );\n\n const sourceLocaleContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n if (Object.keys(sourceLocaleContent).length === 0) {\n appLogger(\n `No content found for dictionary ${dictionaryKey} in source locale ${sourceLocale}. Skipping translation for this dictionary.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const result: Dictionary[] = [];\n\n // 5. for each locale to translate (exclude base locale) generate json translations\n for await (const targetLocale of outputLocalesList) {\n appLogger(\n `Preparing translation for ${dictionaryKey} from ${sourceLocale} to ${targetLocale}`,\n {\n isVerbose: true,\n }\n );\n\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n targetLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n try {\n const translationResult = await getAiAPI(\n undefined,\n configuration\n ).translateJSON(\n {\n entryFileContent: sourceLocaleContent.content, // Should be JSON, ensure getLocalisedContent provides this.\n presetOutputContent: presetOutputContent.content, // Should be JSON\n dictionaryDescription: mainDictionaryToProcess.description,\n entryLocale: sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions: options.aiOptions,\n },\n {\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n }\n );\n\n if (!translationResult.data?.fileContent) {\n appLogger(\n `No content result found for ${dictionaryKey} to ${targetLocale}`,\n {\n level: 'error',\n }\n );\n continue;\n }\n\n const processedPerLocaleDictionary = processPerLocaleDictionary({\n ...mainDictionaryToProcess,\n content: translationResult.data?.fileContent,\n locale: targetLocale,\n });\n\n result.push(processedPerLocaleDictionary);\n } catch (error) {\n appLogger(\n `Error filling ${dictionaryKey} to ${targetLocale}:` + error,\n {\n level: 'error',\n }\n );\n }\n }\n\n const dictionaryToMerge =\n mode === 'review'\n ? [...result, mainDictionaryToProcess] // Mode review: generated content will override the base one\n : [mainDictionaryToProcess, ...result]; // Mode complete: base content will override the generated one\n\n const mergedResults = mergeDictionaries(dictionaryToMerge);\n\n let formattedDict = targetUnmergedDictionary;\n\n if (formattedDict.locale) {\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n formattedDict.locale,\n { dictionaryKey, keyPath: [] }\n );\n formattedDict = {\n ...formattedDict,\n content: presetOutputContent.content,\n };\n }\n\n const reducedResult = reduceDictionaryContent(mergedResults, formattedDict);\n\n await writeContentDeclaration(\n { ...formattedDict, content: reducedResult.content },\n configuration,\n formattedDict.filePath\n );\n\n await autoFill(\n mergedResults,\n targetUnmergedDictionary,\n formattedDict.autoFill,\n outputLocalesList,\n [sourceLocale],\n configuration\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAiD;AACjD,sBAQO;AACP,oBAMO;AACP,kBAKO;AACP,gCAA+B;AAC/B,yCAAuC;AACvC,kBAAuC;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AACA,sBAAgB;AAAA,QACd,GAAG;AAAA,QACH,SAAS,oBAAoB;AAAA,MAC/B;AAAA,IACF;AAEA,UAAM,oBAAgB,yCAAwB,eAAe,aAAa;AAE1E,cAAM;AAAA,MACJ,EAAE,GAAG,eAAe,SAAS,cAAc,QAAQ;AAAA,MACnD;AAAA,MACA,cAAc;AAAA,IAChB;AAEA,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA,CAAC,YAAY;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":["unmergedDictionariesRecord","localeList","dictionariesRecord"]}
1
+ {"version":3,"sources":["../../src/fill.ts"],"sourcesContent":["import { AIOptions, getAiAPI, getOAuthAPI } from '@intlayer/api'; // Importing only getAiAPI for now\nimport {\n getFilteredLocalesContent,\n listGitFiles,\n ListGitFilesOptions,\n mergeDictionaries,\n processPerLocaleDictionary,\n reduceDictionaryContent,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n type IntlayerConfig,\n Locales,\n} from '@intlayer/config';\nimport {\n type AutoFill,\n type ContentNode,\n type Dictionary,\n getLocaleName,\n getLocalisedContent,\n} from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport unmergedDictionariesRecord from '@intlayer/unmerged-dictionaries-entry';\nimport pLimit from 'p-limit';\nimport { dirname, extname, join, relative } from 'path';\nimport { checkAIAccess } from './utils/checkAIAccess';\n\nconst NB_CONCURRENT_TRANSLATIONS = 5;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locales;\n outputLocales?: Locales | Locales[];\n file?: string | string[];\n mode?: 'complete' | 'review';\n keys?: string | string[];\n excludedKeys?: string | string[];\n filter?: (entry: Dictionary) => boolean; // DictionaryEntry needs to be defined\n pathFilter?: string | string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n};\n\nconst ensureArray = <T>(value: T | T[]): T[] => [value].flat() as T[];\n\nconst getTargetDictionary = async (options: FillOptions) => {\n const configuration = getConfiguration(options.configOptions);\n\n const { baseDir } = configuration.content;\n\n let result = Object.values(unmergedDictionariesRecord).flat();\n\n // 1. if filePath not defined, list all content declaration files based on unmerged dictionaries list\n if (typeof options.file !== 'undefined') {\n const fileArray = ensureArray(options.file);\n const absoluteFilePaths = fileArray.map((file) => join(baseDir, file));\n\n result = result.filter(\n (dict) =>\n dict.filePath &&\n (absoluteFilePaths.includes(dict.filePath) ||\n absoluteFilePaths.includes(join(baseDir, dict.filePath)))\n );\n }\n\n if (typeof options.keys !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.keys)?.includes(dict.key)\n );\n }\n\n if (typeof options.excludedKeys !== 'undefined') {\n result = result.filter(\n (dict) => !ensureArray(options.excludedKeys)?.includes(dict.key)\n );\n }\n\n if (typeof options.pathFilter !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.pathFilter)?.includes(dict.filePath ?? '')\n );\n }\n\n if (typeof options.filter !== 'undefined') {\n result = result.filter(options.filter);\n }\n\n const gitOptions = options.gitOptions;\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n result = result.filter((dict) => {\n if (!dict.filePath) return false;\n\n return gitChangedFiles.some((gitFile) => dict.filePath === gitFile);\n });\n }\n }\n\n return result.filter((dict) => !dict.autoFilled);\n};\n\nconst transformUriToAbsolutePath = (\n uri: string,\n filePath: string,\n baseDir: string\n) => {\n if (uri.startsWith('/')) {\n return join(baseDir, uri);\n }\n\n if (uri.startsWith('./')) {\n return join(dirname(filePath), uri);\n }\n\n return filePath;\n};\n\nexport type AutoFillData = {\n localeList: Locales[];\n filePath: string;\n};\n\nconst formatAutoFillData = (\n autoFillOptions: AutoFill,\n localeList: Locales[],\n filePath: string,\n dictionaryKey: string,\n configuration: IntlayerConfig\n): AutoFillData[] => {\n const outputContentDeclarationFile: AutoFillData[] = [];\n\n if (!Boolean(autoFillOptions)) return outputContentDeclarationFile;\n\n if (autoFillOptions === true) {\n // wanted jsonFilePath: /..../src/components/home/index.content.json\n // replace file extension in json\n let jsonFilePath = filePath.replace(extname(filePath), '.json');\n\n // if both filePath jsonFilePath are same path, change it as : /..../src/components/home/index.fill.content.json\n if (filePath === jsonFilePath) {\n jsonFilePath = jsonFilePath.replace(extname(jsonFilePath), '.fill.json');\n }\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: jsonFilePath,\n });\n }\n\n if (typeof autoFillOptions === 'string') {\n if (autoFillOptions.includes('{{locale}}')) {\n const output = localeList.map((locale) => ({\n localeList: [locale],\n filePath: transformUriToAbsolutePath(\n autoFillOptions\n .replace('{{locale}}', locale)\n .replace('{{key}}', dictionaryKey),\n filePath,\n configuration.content.baseDir\n ),\n }));\n\n outputContentDeclarationFile.push(...output);\n } else {\n outputContentDeclarationFile.push({\n localeList,\n filePath: transformUriToAbsolutePath(\n autoFillOptions,\n filePath,\n configuration.content.baseDir\n ),\n });\n }\n\n return outputContentDeclarationFile;\n }\n\n if (typeof autoFillOptions === 'object') {\n const localeList = Object.keys(autoFillOptions).filter(\n (locale) => typeof autoFillOptions[locale] === 'string'\n ) as Locales[];\n\n const output: AutoFillData[] = localeList.map((locale) => ({\n localeList: [locale],\n filePath: transformUriToAbsolutePath(\n autoFillOptions[locale].replace('{{key}}', dictionaryKey),\n filePath,\n configuration.content.baseDir\n ),\n }));\n\n // Group by filePath and merge localeList\n const groupedByFilePath = output.reduce((acc, curr) => {\n const existing = acc.find((item) => item.filePath === curr.filePath);\n if (existing) {\n existing.localeList.push(...curr.localeList);\n } else {\n acc.push(curr);\n }\n return acc;\n }, [] as AutoFillData[]);\n\n outputContentDeclarationFile.push(...groupedByFilePath);\n }\n\n return outputContentDeclarationFile;\n};\n\nconst autoFill = async (\n fullDictionary: Dictionary,\n contentDeclarationFile: Dictionary,\n autoFillOptions: AutoFill,\n outputLocales: Locales[],\n parentLocales: Locales[],\n configuration: IntlayerConfig\n) => {\n const appLogger = getAppLogger(configuration);\n let localeList: Locales[] = (\n outputLocales ?? configuration.internationalization.locales\n ).filter((locale) => !parentLocales?.includes(locale));\n\n const filePath = contentDeclarationFile.filePath;\n\n if (!filePath) {\n appLogger('No file path found for dictionary', {\n level: 'error',\n });\n return;\n }\n\n const autoFillData: AutoFillData[] = formatAutoFillData(\n autoFillOptions,\n localeList,\n filePath,\n fullDictionary.key,\n configuration\n );\n\n appLogger(`Auto fill data: ${JSON.stringify(autoFillData, null, 2)}`, {\n level: 'info',\n isVerbose: true,\n });\n\n for await (const output of autoFillData) {\n const reducedDictionary = reduceDictionaryContent(\n fullDictionary,\n contentDeclarationFile\n );\n\n const isPerLocaleDeclarationFile = output.localeList.length === 1;\n\n if (isPerLocaleDeclarationFile) {\n const sourceLocale = output.localeList[0];\n\n const sourceLocaleContent = getLocalisedContent(\n reducedDictionary as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey: reducedDictionary.key, keyPath: [] }\n );\n\n await writeContentDeclaration({\n ...fullDictionary,\n locale: sourceLocale,\n autoFilled: true,\n autoFill: undefined,\n content: sourceLocaleContent.content,\n filePath: output.filePath,\n });\n } else {\n const content = getFilteredLocalesContent(\n reducedDictionary.content as unknown as ContentNode,\n output.localeList,\n { dictionaryKey: reducedDictionary.key, keyPath: [] }\n );\n\n // write file\n await writeContentDeclaration({\n ...fullDictionary,\n autoFilled: true,\n autoFill: undefined,\n content,\n filePath: output.filePath,\n });\n }\n }\n};\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options.mode ?? 'review';\n const baseLocale = options.sourceLocale ?? defaultLocale;\n\n checkAIAccess(configuration, options.aiOptions);\n\n let oAuth2AccessToken: string | undefined;\n if (configuration.editor.clientId) {\n const intlayerAuthAPI = getOAuthAPI(configuration);\n const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();\n\n oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n }\n\n appLogger('Starting fill function', {\n level: 'info',\n });\n\n const targetUnmergedDictionaries = await getTargetDictionary(options);\n\n // Determine output locales\n const outputLocalesList: Locales[] = (\n options.outputLocales ? ensureArray(options.outputLocales) : locales\n ).filter((locale) =>\n // If mode is review, translate all locales\n // If mode is complete, translate only the locales that are not the source locale\n mode === 'review' ? true : locale !== baseLocale\n );\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n appLogger(\n [\n 'Affected dictionary keys for processing:',\n Array.from(affectedDictionaryKeys).join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n\n for (const targetUnmergedDictionary of targetUnmergedDictionaries) {\n const dictionaryKey = targetUnmergedDictionary.key;\n const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];\n const sourceLocale: Locales =\n (targetUnmergedDictionary.locale as Locales) ?? baseLocale;\n\n if (!mainDictionaryToProcess) {\n appLogger(\n `Dictionary with key \"${dictionaryKey}\" not found in dictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n if (!targetUnmergedDictionary.filePath) {\n appLogger(\n `Dictionary with key \"${dictionaryKey}\" has no file path. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const relativePath = relative(\n configuration.content.baseDir,\n targetUnmergedDictionary.filePath\n );\n\n appLogger(`Processing content declaration: ${relativePath}`, {\n isVerbose: true,\n });\n\n const sourceLocaleContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n if (Object.keys(sourceLocaleContent).length === 0) {\n appLogger(\n `No content found for dictionary ${dictionaryKey} in source locale ${sourceLocale}. Skipping translation for this dictionary.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const result: Dictionary[] = [];\n\n // 5. for each locale to translate (exclude base locale) generate json translations\n // Limit concurrent translations to 5 at a time\n const limit = pLimit(\n options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS\n );\n\n const translationPromises = outputLocalesList.map((targetLocale) =>\n limit(async () => {\n appLogger(\n `Preparing translation for '${dictionaryKey}' dictionary from ${getLocaleName(\n sourceLocale,\n Locales.ENGLISH\n )} (${sourceLocale}) to ${getLocaleName(targetLocale, Locales.ENGLISH)} (${targetLocale})`,\n {\n isVerbose: true,\n }\n );\n\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n targetLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n try {\n const translationResult = await getAiAPI(\n undefined,\n configuration\n ).translateJSON(\n {\n entryFileContent: sourceLocaleContent.content, // Should be JSON, ensure getLocalisedContent provides this.\n presetOutputContent: presetOutputContent.content, // Should be JSON\n dictionaryDescription: mainDictionaryToProcess.description,\n entryLocale: sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions: options.aiOptions,\n },\n {\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n }\n );\n\n if (!translationResult.data?.fileContent) {\n appLogger(\n `No content result found for ${dictionaryKey} to ${targetLocale}`,\n {\n level: 'error',\n }\n );\n return null;\n }\n\n const processedPerLocaleDictionary = processPerLocaleDictionary({\n ...mainDictionaryToProcess,\n content: translationResult.data?.fileContent,\n locale: targetLocale,\n });\n\n return processedPerLocaleDictionary;\n } catch (error) {\n appLogger(\n `Error filling ${dictionaryKey} to ${targetLocale}:` + error,\n {\n level: 'error',\n }\n );\n return null;\n }\n })\n );\n\n // Wait for all translations to complete\n const translationResults = await Promise.all(translationPromises);\n\n // Filter out null results and add to result array\n translationResults.forEach((translationResult) => {\n if (translationResult) {\n result.push(translationResult);\n }\n });\n\n const dictionaryToMerge =\n mode === 'review'\n ? [...result, mainDictionaryToProcess] // Mode review: generated content will override the base one\n : [mainDictionaryToProcess, ...result]; // Mode complete: base content will override the generated one\n\n const mergedResults = mergeDictionaries(dictionaryToMerge);\n\n let formattedDict = targetUnmergedDictionary;\n\n if (formattedDict.locale) {\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n formattedDict.locale,\n { dictionaryKey, keyPath: [] }\n );\n\n formattedDict = {\n ...formattedDict,\n content: presetOutputContent.content,\n };\n }\n\n const reducedResult = reduceDictionaryContent(mergedResults, formattedDict);\n\n await writeContentDeclaration(\n { ...formattedDict, content: reducedResult.content },\n configuration,\n formattedDict.filePath\n );\n\n if (!formattedDict.autoFill) return;\n\n await autoFill(\n mergedResults,\n targetUnmergedDictionary,\n formattedDict.autoFill,\n outputLocalesList,\n [sourceLocale],\n configuration\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAiD;AACjD,sBAQO;AACP,oBAMO;AACP,kBAMO;AACP,gCAA+B;AAC/B,yCAAuC;AACvC,qBAAmB;AACnB,kBAAiD;AACjD,2BAA8B;AAE9B,MAAM,6BAA6B;AAmBnC,MAAM,cAAc,CAAI,UAAwB,CAAC,KAAK,EAAE,KAAK;AAE7D,MAAM,sBAAsB,OAAO,YAAyB;AAC1D,QAAM,oBAAgB,gCAAiB,QAAQ,aAAa;AAE5D,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,MAAI,SAAS,OAAO,OAAO,mCAAAA,OAA0B,EAAE,KAAK;AAG5D,MAAI,OAAO,QAAQ,SAAS,aAAa;AACvC,UAAM,YAAY,YAAY,QAAQ,IAAI;AAC1C,UAAM,oBAAoB,UAAU,IAAI,CAAC,aAAS,kBAAK,SAAS,IAAI,CAAC;AAErE,aAAS,OAAO;AAAA,MAC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AEzD,QAAI,gBAAgB;AAEpB,QAAI,cAAc,QAAQ;AACxB,YAAM,0BAAsB;AAAA,QAC1B;AAAA,QACA,cAAc;AAAA,QACd,EAAE,eAAe,SAAS,CAAC,EAAE;AAAA,MAC/B;AAEA,sBAAgB;AAAA,QACd,GAAG;AAAA,QACH,SAAS,oBAAoB;AAAA,MAC/B;AAAA,IACF;AAEA,UAAM,oBAAgB,yCAAwB,eAAe,aAAa;AAE1E,cAAM;AAAA,MACJ,EAAE,GAAG,eAAe,SAAS,cAAc,QAAQ;AAAA,MACnD;AAAA,MACA,cAAc;AAAA,IAChB;AAEA,QAAI,CAAC,cAAc,SAAU;AAE7B,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA,CAAC,YAAY;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":["unmergedDictionariesRecord","localeList","dictionariesRecord","pLimit"]}
package/dist/esm/fill.mjs CHANGED
@@ -9,15 +9,19 @@ import {
9
9
  } from "@intlayer/chokidar";
10
10
  import {
11
11
  getAppLogger,
12
- getConfiguration
12
+ getConfiguration,
13
+ Locales
13
14
  } from "@intlayer/config";
14
15
  import {
16
+ getLocaleName,
15
17
  getLocalisedContent
16
18
  } from "@intlayer/core";
17
19
  import dictionariesRecord from "@intlayer/dictionaries-entry";
18
20
  import unmergedDictionariesRecord from "@intlayer/unmerged-dictionaries-entry";
19
- import { dirname, extname, join } from "path";
21
+ import pLimit from "p-limit";
22
+ import { dirname, extname, join, relative } from "path";
20
23
  import { checkAIAccess } from "./utils/checkAIAccess.mjs";
24
+ const NB_CONCURRENT_TRANSLATIONS = 5;
21
25
  const ensureArray = (value) => [value].flat();
22
26
  const getTargetDictionary = async (options) => {
23
27
  const configuration = getConfiguration(options.configOptions);
@@ -238,12 +242,22 @@ const fill = async (options) => {
238
242
  );
239
243
  continue;
240
244
  }
241
- appLogger(
242
- `Processing content declaration: ${targetUnmergedDictionary.filePath}`,
243
- {
244
- isVerbose: true
245
- }
245
+ if (!targetUnmergedDictionary.filePath) {
246
+ appLogger(
247
+ `Dictionary with key "${dictionaryKey}" has no file path. Skipping.`,
248
+ {
249
+ level: "warn"
250
+ }
251
+ );
252
+ continue;
253
+ }
254
+ const relativePath = relative(
255
+ configuration.content.baseDir,
256
+ targetUnmergedDictionary.filePath
246
257
  );
258
+ appLogger(`Processing content declaration: ${relativePath}`, {
259
+ isVerbose: true
260
+ });
247
261
  const sourceLocaleContent = getLocalisedContent(
248
262
  mainDictionaryToProcess,
249
263
  sourceLocale,
@@ -259,66 +273,81 @@ const fill = async (options) => {
259
273
  continue;
260
274
  }
261
275
  const result = [];
262
- for await (const targetLocale of outputLocalesList) {
263
- appLogger(
264
- `Preparing translation for ${dictionaryKey} from ${sourceLocale} to ${targetLocale}`,
265
- {
266
- isVerbose: true
267
- }
268
- );
269
- const presetOutputContent = getLocalisedContent(
270
- mainDictionaryToProcess,
271
- targetLocale,
272
- { dictionaryKey, keyPath: [] }
273
- );
274
- try {
275
- const translationResult = await getAiAPI(
276
- void 0,
277
- configuration
278
- ).translateJSON(
279
- {
280
- entryFileContent: sourceLocaleContent.content,
281
- // Should be JSON, ensure getLocalisedContent provides this.
282
- presetOutputContent: presetOutputContent.content,
283
- // Should be JSON
284
- dictionaryDescription: mainDictionaryToProcess.description,
285
- entryLocale: sourceLocale,
286
- outputLocale: targetLocale,
287
- mode,
288
- aiOptions: options.aiOptions
289
- },
276
+ const limit = pLimit(
277
+ options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS
278
+ );
279
+ const translationPromises = outputLocalesList.map(
280
+ (targetLocale) => limit(async () => {
281
+ appLogger(
282
+ `Preparing translation for '${dictionaryKey}' dictionary from ${getLocaleName(
283
+ sourceLocale,
284
+ Locales.ENGLISH
285
+ )} (${sourceLocale}) to ${getLocaleName(targetLocale, Locales.ENGLISH)} (${targetLocale})`,
290
286
  {
291
- ...oAuth2AccessToken && {
292
- headers: {
293
- Authorization: `Bearer ${oAuth2AccessToken}`
287
+ isVerbose: true
288
+ }
289
+ );
290
+ const presetOutputContent = getLocalisedContent(
291
+ mainDictionaryToProcess,
292
+ targetLocale,
293
+ { dictionaryKey, keyPath: [] }
294
+ );
295
+ try {
296
+ const translationResult = await getAiAPI(
297
+ void 0,
298
+ configuration
299
+ ).translateJSON(
300
+ {
301
+ entryFileContent: sourceLocaleContent.content,
302
+ // Should be JSON, ensure getLocalisedContent provides this.
303
+ presetOutputContent: presetOutputContent.content,
304
+ // Should be JSON
305
+ dictionaryDescription: mainDictionaryToProcess.description,
306
+ entryLocale: sourceLocale,
307
+ outputLocale: targetLocale,
308
+ mode,
309
+ aiOptions: options.aiOptions
310
+ },
311
+ {
312
+ ...oAuth2AccessToken && {
313
+ headers: {
314
+ Authorization: `Bearer ${oAuth2AccessToken}`
315
+ }
294
316
  }
295
317
  }
318
+ );
319
+ if (!translationResult.data?.fileContent) {
320
+ appLogger(
321
+ `No content result found for ${dictionaryKey} to ${targetLocale}`,
322
+ {
323
+ level: "error"
324
+ }
325
+ );
326
+ return null;
296
327
  }
297
- );
298
- if (!translationResult.data?.fileContent) {
328
+ const processedPerLocaleDictionary = processPerLocaleDictionary({
329
+ ...mainDictionaryToProcess,
330
+ content: translationResult.data?.fileContent,
331
+ locale: targetLocale
332
+ });
333
+ return processedPerLocaleDictionary;
334
+ } catch (error) {
299
335
  appLogger(
300
- `No content result found for ${dictionaryKey} to ${targetLocale}`,
336
+ `Error filling ${dictionaryKey} to ${targetLocale}:` + error,
301
337
  {
302
338
  level: "error"
303
339
  }
304
340
  );
305
- continue;
341
+ return null;
306
342
  }
307
- const processedPerLocaleDictionary = processPerLocaleDictionary({
308
- ...mainDictionaryToProcess,
309
- content: translationResult.data?.fileContent,
310
- locale: targetLocale
311
- });
312
- result.push(processedPerLocaleDictionary);
313
- } catch (error) {
314
- appLogger(
315
- `Error filling ${dictionaryKey} to ${targetLocale}:` + error,
316
- {
317
- level: "error"
318
- }
319
- );
343
+ })
344
+ );
345
+ const translationResults = await Promise.all(translationPromises);
346
+ translationResults.forEach((translationResult) => {
347
+ if (translationResult) {
348
+ result.push(translationResult);
320
349
  }
321
- }
350
+ });
322
351
  const dictionaryToMerge = mode === "review" ? [...result, mainDictionaryToProcess] : [mainDictionaryToProcess, ...result];
323
352
  const mergedResults = mergeDictionaries(dictionaryToMerge);
324
353
  let formattedDict = targetUnmergedDictionary;
@@ -339,6 +368,7 @@ const fill = async (options) => {
339
368
  configuration,
340
369
  formattedDict.filePath
341
370
  );
371
+ if (!formattedDict.autoFill) return;
342
372
  await autoFill(
343
373
  mergedResults,
344
374
  targetUnmergedDictionary,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fill.ts"],"sourcesContent":["import { AIOptions, getAiAPI, getOAuthAPI } from '@intlayer/api'; // Importing only getAiAPI for now\nimport {\n getFilteredLocalesContent,\n listGitFiles,\n ListGitFilesOptions,\n mergeDictionaries,\n processPerLocaleDictionary,\n reduceDictionaryContent,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n type IntlayerConfig,\n Locales,\n} from '@intlayer/config';\nimport {\n type AutoFill,\n type ContentNode,\n type Dictionary,\n getLocalisedContent,\n} from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport unmergedDictionariesRecord from '@intlayer/unmerged-dictionaries-entry';\nimport { dirname, extname, join } from 'path';\nimport { checkAIAccess } from './utils/checkAIAccess';\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locales;\n outputLocales?: Locales | Locales[];\n file?: string | string[];\n mode?: 'complete' | 'review';\n keys?: string | string[];\n excludedKeys?: string | string[];\n filter?: (entry: Dictionary) => boolean; // DictionaryEntry needs to be defined\n pathFilter?: string | string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n};\n\nconst ensureArray = <T>(value: T | T[]): T[] => [value].flat() as T[];\n\nconst getTargetDictionary = async (options: FillOptions) => {\n const configuration = getConfiguration(options.configOptions);\n\n const { baseDir } = configuration.content;\n\n let result = Object.values(unmergedDictionariesRecord).flat();\n\n // 1. if filePath not defined, list all content declaration files based on unmerged dictionaries list\n if (typeof options.file !== 'undefined') {\n const fileArray = ensureArray(options.file);\n const absoluteFilePaths = fileArray.map((file) => join(baseDir, file));\n\n result = result.filter(\n (dict) =>\n dict.filePath &&\n (absoluteFilePaths.includes(dict.filePath) ||\n absoluteFilePaths.includes(join(baseDir, dict.filePath)))\n );\n }\n\n if (typeof options.keys !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.keys)?.includes(dict.key)\n );\n }\n\n if (typeof options.excludedKeys !== 'undefined') {\n result = result.filter(\n (dict) => !ensureArray(options.excludedKeys)?.includes(dict.key)\n );\n }\n\n if (typeof options.pathFilter !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.pathFilter)?.includes(dict.filePath ?? '')\n );\n }\n\n if (typeof options.filter !== 'undefined') {\n result = result.filter(options.filter);\n }\n\n const gitOptions = options.gitOptions;\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n result = result.filter((dict) => {\n if (!dict.filePath) return false;\n\n return gitChangedFiles.some((gitFile) => dict.filePath === gitFile);\n });\n }\n }\n\n return result.filter((dict) => !dict.autoFilled);\n};\n\nconst transformUriToAbsolutePath = (\n uri: string,\n filePath: string,\n baseDir: string\n) => {\n if (uri.startsWith('/')) {\n return join(baseDir, uri);\n }\n\n if (uri.startsWith('./')) {\n return join(dirname(filePath), uri);\n }\n\n return filePath;\n};\n\nexport type AutoFillData = {\n localeList: Locales[];\n filePath: string;\n};\n\nconst formatAutoFillData = (\n autoFillOptions: AutoFill,\n localeList: Locales[],\n filePath: string,\n dictionaryKey: string,\n configuration: IntlayerConfig\n): AutoFillData[] => {\n const outputContentDeclarationFile: AutoFillData[] = [];\n\n if (!Boolean(autoFillOptions)) return outputContentDeclarationFile;\n\n if (autoFillOptions === true) {\n // wanted jsonFilePath: /..../src/components/home/index.content.json\n // replace file extension in json\n let jsonFilePath = filePath.replace(extname(filePath), '.json');\n\n // if both filePath jsonFilePath are same path, change it as : /..../src/components/home/index.fill.content.json\n if (filePath === jsonFilePath) {\n jsonFilePath = jsonFilePath.replace(extname(jsonFilePath), '.fill.json');\n }\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: jsonFilePath,\n });\n }\n\n if (typeof autoFillOptions === 'string') {\n if (autoFillOptions.includes('{{locale}}')) {\n const output = localeList.map((locale) => ({\n localeList: [locale],\n filePath: transformUriToAbsolutePath(\n autoFillOptions\n .replace('{{locale}}', locale)\n .replace('{{key}}', dictionaryKey),\n filePath,\n configuration.content.baseDir\n ),\n }));\n\n outputContentDeclarationFile.push(...output);\n } else {\n outputContentDeclarationFile.push({\n localeList,\n filePath: transformUriToAbsolutePath(\n autoFillOptions,\n filePath,\n configuration.content.baseDir\n ),\n });\n }\n\n return outputContentDeclarationFile;\n }\n\n if (typeof autoFillOptions === 'object') {\n const localeList = Object.keys(autoFillOptions).filter(\n (locale) => typeof autoFillOptions[locale] === 'string'\n ) as Locales[];\n\n const output: AutoFillData[] = localeList.map((locale) => ({\n localeList: [locale],\n filePath: transformUriToAbsolutePath(\n autoFillOptions[locale].replace('{{key}}', dictionaryKey),\n filePath,\n configuration.content.baseDir\n ),\n }));\n\n // Group by filePath and merge localeList\n const groupedByFilePath = output.reduce((acc, curr) => {\n const existing = acc.find((item) => item.filePath === curr.filePath);\n if (existing) {\n existing.localeList.push(...curr.localeList);\n } else {\n acc.push(curr);\n }\n return acc;\n }, [] as AutoFillData[]);\n\n outputContentDeclarationFile.push(...groupedByFilePath);\n }\n\n return outputContentDeclarationFile;\n};\n\nconst autoFill = async (\n fullDictionary: Dictionary,\n contentDeclarationFile: Dictionary,\n autoFillOptions: AutoFill,\n outputLocales: Locales[],\n parentLocales: Locales[],\n configuration: IntlayerConfig\n) => {\n const appLogger = getAppLogger(configuration);\n let localeList: Locales[] = (\n outputLocales ?? configuration.internationalization.locales\n ).filter((locale) => !parentLocales?.includes(locale));\n\n const filePath = contentDeclarationFile.filePath;\n\n if (!filePath) {\n appLogger('No file path found for dictionary', {\n level: 'error',\n });\n return;\n }\n\n const autoFillData: AutoFillData[] = formatAutoFillData(\n autoFillOptions,\n localeList,\n filePath,\n fullDictionary.key,\n configuration\n );\n\n appLogger(`Auto fill data: ${JSON.stringify(autoFillData, null, 2)}`, {\n level: 'info',\n isVerbose: true,\n });\n\n for await (const output of autoFillData) {\n const reducedDictionary = reduceDictionaryContent(\n fullDictionary,\n contentDeclarationFile\n );\n\n const isPerLocaleDeclarationFile = output.localeList.length === 1;\n\n if (isPerLocaleDeclarationFile) {\n const sourceLocale = output.localeList[0];\n\n const sourceLocaleContent = getLocalisedContent(\n reducedDictionary as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey: reducedDictionary.key, keyPath: [] }\n );\n\n await writeContentDeclaration({\n ...fullDictionary,\n locale: sourceLocale,\n autoFilled: true,\n autoFill: undefined,\n content: sourceLocaleContent.content,\n filePath: output.filePath,\n });\n } else {\n const content = getFilteredLocalesContent(\n reducedDictionary.content as unknown as ContentNode,\n output.localeList,\n { dictionaryKey: reducedDictionary.key, keyPath: [] }\n );\n\n // write file\n await writeContentDeclaration({\n ...fullDictionary,\n autoFilled: true,\n autoFill: undefined,\n content,\n filePath: output.filePath,\n });\n }\n }\n};\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options.mode ?? 'review';\n const baseLocale = options.sourceLocale ?? defaultLocale;\n\n checkAIAccess(configuration, options.aiOptions);\n\n let oAuth2AccessToken: string | undefined;\n if (configuration.editor.clientId) {\n const intlayerAuthAPI = getOAuthAPI(configuration);\n const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();\n\n oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n }\n\n appLogger('Starting fill function', {\n level: 'info',\n });\n\n const targetUnmergedDictionaries = await getTargetDictionary(options);\n\n // Determine output locales\n const outputLocalesList: Locales[] = (\n options.outputLocales ? ensureArray(options.outputLocales) : locales\n ).filter((locale) =>\n // If mode is review, translate all locales\n // If mode is complete, translate only the locales that are not the source locale\n mode === 'review' ? true : locale !== baseLocale\n );\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n appLogger(\n [\n 'Affected dictionary keys for processing:',\n Array.from(affectedDictionaryKeys).join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n\n for (const targetUnmergedDictionary of targetUnmergedDictionaries) {\n const dictionaryKey = targetUnmergedDictionary.key;\n const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];\n const sourceLocale: Locales =\n (targetUnmergedDictionary.locale as Locales) ?? baseLocale;\n\n if (!mainDictionaryToProcess) {\n appLogger(\n `Dictionary with key \"${dictionaryKey}\" not found in dictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n appLogger(\n `Processing content declaration: ${targetUnmergedDictionary.filePath}`,\n {\n isVerbose: true,\n }\n );\n\n const sourceLocaleContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n if (Object.keys(sourceLocaleContent).length === 0) {\n appLogger(\n `No content found for dictionary ${dictionaryKey} in source locale ${sourceLocale}. Skipping translation for this dictionary.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const result: Dictionary[] = [];\n\n // 5. for each locale to translate (exclude base locale) generate json translations\n for await (const targetLocale of outputLocalesList) {\n appLogger(\n `Preparing translation for ${dictionaryKey} from ${sourceLocale} to ${targetLocale}`,\n {\n isVerbose: true,\n }\n );\n\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n targetLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n try {\n const translationResult = await getAiAPI(\n undefined,\n configuration\n ).translateJSON(\n {\n entryFileContent: sourceLocaleContent.content, // Should be JSON, ensure getLocalisedContent provides this.\n presetOutputContent: presetOutputContent.content, // Should be JSON\n dictionaryDescription: mainDictionaryToProcess.description,\n entryLocale: sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions: options.aiOptions,\n },\n {\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n }\n );\n\n if (!translationResult.data?.fileContent) {\n appLogger(\n `No content result found for ${dictionaryKey} to ${targetLocale}`,\n {\n level: 'error',\n }\n );\n continue;\n }\n\n const processedPerLocaleDictionary = processPerLocaleDictionary({\n ...mainDictionaryToProcess,\n content: translationResult.data?.fileContent,\n locale: targetLocale,\n });\n\n result.push(processedPerLocaleDictionary);\n } catch (error) {\n appLogger(\n `Error filling ${dictionaryKey} to ${targetLocale}:` + error,\n {\n level: 'error',\n }\n );\n }\n }\n\n const dictionaryToMerge =\n mode === 'review'\n ? [...result, mainDictionaryToProcess] // Mode review: generated content will override the base one\n : [mainDictionaryToProcess, ...result]; // Mode complete: base content will override the generated one\n\n const mergedResults = mergeDictionaries(dictionaryToMerge);\n\n let formattedDict = targetUnmergedDictionary;\n\n if (formattedDict.locale) {\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n formattedDict.locale,\n { dictionaryKey, keyPath: [] }\n );\n formattedDict = {\n ...formattedDict,\n content: presetOutputContent.content,\n };\n }\n\n const reducedResult = reduceDictionaryContent(mergedResults, formattedDict);\n\n await writeContentDeclaration(\n { ...formattedDict, content: reducedResult.content },\n configuration,\n formattedDict.filePath\n );\n\n await autoFill(\n mergedResults,\n targetUnmergedD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F;AAAA,IACF;AAEA,UAAM,oBACJ,SAAS,WACL,CAAC,GAAG,QAAQ,uBAAuB,IACnC,CAAC,yBAAyB,GAAG,MAAM;AAEzC,UAAM,gBAAgB,kBAAkB,iBAAiB;AAEzD,QAAI,gBAAgB;AAEpB,QAAI,cAAc,QAAQ;AACxB,YAAM,sBAAsB;AAAA,QAC1B;AAAA,QACA,cAAc;AAAA,QACd,EAAE,eAAe,SAAS,CAAC,EAAE;AAAA,MAC/B;AACA,sBAAgB;AAAA,QACd,GAAG;AAAA,QACH,SAAS,oBAAoB;AAAA,MAC/B;AAAA,IACF;AAEA,UAAM,gBAAgB,wBAAwB,eAAe,aAAa;AAE1E,UAAM;AAAA,MACJ,EAAE,GAAG,eAAe,SAAS,cAAc,QAAQ;AAAA,MACnD;AAAA,MACA,cAAc;AAAA,IAChB;AAEA,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA,CAAC,YAAY;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":["localeList"]}
1
+ {"version":3,"sources":["../../src/fill.ts"],"sourcesContent":["import { AIOptions, getAiAPI, getOAuthAPI } from '@intlayer/api'; // Importing only getAiAPI for now\nimport {\n getFilteredLocalesContent,\n listGitFiles,\n ListGitFilesOptions,\n mergeDictionaries,\n processPerLocaleDictionary,\n reduceDictionaryContent,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n type IntlayerConfig,\n Locales,\n} from '@intlayer/config';\nimport {\n type AutoFill,\n type ContentNode,\n type Dictionary,\n getLocaleName,\n getLocalisedContent,\n} from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport unmergedDictionariesRecord from '@intlayer/unmerged-dictionaries-entry';\nimport pLimit from 'p-limit';\nimport { dirname, extname, join, relative } from 'path';\nimport { checkAIAccess } from './utils/checkAIAccess';\n\nconst NB_CONCURRENT_TRANSLATIONS = 5;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locales;\n outputLocales?: Locales | Locales[];\n file?: string | string[];\n mode?: 'complete' | 'review';\n keys?: string | string[];\n excludedKeys?: string | string[];\n filter?: (entry: Dictionary) => boolean; // DictionaryEntry needs to be defined\n pathFilter?: string | string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n};\n\nconst ensureArray = <T>(value: T | T[]): T[] => [value].flat() as T[];\n\nconst getTargetDictionary = async (options: FillOptions) => {\n const configuration = getConfiguration(options.configOptions);\n\n const { baseDir } = configuration.content;\n\n let result = Object.values(unmergedDictionariesRecord).flat();\n\n // 1. if filePath not defined, list all content declaration files based on unmerged dictionaries list\n if (typeof options.file !== 'undefined') {\n const fileArray = ensureArray(options.file);\n const absoluteFilePaths = fileArray.map((file) => join(baseDir, file));\n\n result = result.filter(\n (dict) =>\n dict.filePath &&\n (absoluteFilePaths.includes(dict.filePath) ||\n absoluteFilePaths.includes(join(baseDir, dict.filePath)))\n );\n }\n\n if (typeof options.keys !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.keys)?.includes(dict.key)\n );\n }\n\n if (typeof options.excludedKeys !== 'undefined') {\n result = result.filter(\n (dict) => !ensureArray(options.excludedKeys)?.includes(dict.key)\n );\n }\n\n if (typeof options.pathFilter !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.pathFilter)?.includes(dict.filePath ?? '')\n );\n }\n\n if (typeof options.filter !== 'undefined') {\n result = result.filter(options.filter);\n }\n\n const gitOptions = options.gitOptions;\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n result = result.filter((dict) => {\n if (!dict.filePath) return false;\n\n return gitChangedFiles.some((gitFile) => dict.filePath === gitFile);\n });\n }\n }\n\n return result.filter((dict) => !dict.autoFilled);\n};\n\nconst transformUriToAbsolutePath = (\n uri: string,\n filePath: string,\n baseDir: string\n) => {\n if (uri.startsWith('/')) {\n return join(baseDir, uri);\n }\n\n if (uri.startsWith('./')) {\n return join(dirname(filePath), uri);\n }\n\n return filePath;\n};\n\nexport type AutoFillData = {\n localeList: Locales[];\n filePath: string;\n};\n\nconst formatAutoFillData = (\n autoFillOptions: AutoFill,\n localeList: Locales[],\n filePath: string,\n dictionaryKey: string,\n configuration: IntlayerConfig\n): AutoFillData[] => {\n const outputContentDeclarationFile: AutoFillData[] = [];\n\n if (!Boolean(autoFillOptions)) return outputContentDeclarationFile;\n\n if (autoFillOptions === true) {\n // wanted jsonFilePath: /..../src/components/home/index.content.json\n // replace file extension in json\n let jsonFilePath = filePath.replace(extname(filePath), '.json');\n\n // if both filePath jsonFilePath are same path, change it as : /..../src/components/home/index.fill.content.json\n if (filePath === jsonFilePath) {\n jsonFilePath = jsonFilePath.replace(extname(jsonFilePath), '.fill.json');\n }\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: jsonFilePath,\n });\n }\n\n if (typeof autoFillOptions === 'string') {\n if (autoFillOptions.includes('{{locale}}')) {\n const output = localeList.map((locale) => ({\n localeList: [locale],\n filePath: transformUriToAbsolutePath(\n autoFillOptions\n .replace('{{locale}}', locale)\n .replace('{{key}}', dictionaryKey),\n filePath,\n configuration.content.baseDir\n ),\n }));\n\n outputContentDeclarationFile.push(...output);\n } else {\n outputContentDeclarationFile.push({\n localeList,\n filePath: transformUriToAbsolutePath(\n autoFillOptions,\n filePath,\n configuration.content.baseDir\n ),\n });\n }\n\n return outputContentDeclarationFile;\n }\n\n if (typeof autoFillOptions === 'object') {\n const localeList = Object.keys(autoFillOptions).filter(\n (locale) => typeof autoFillOptions[locale] === 'string'\n ) as Locales[];\n\n const output: AutoFillData[] = localeList.map((locale) => ({\n localeList: [locale],\n filePath: transformUriToAbsolutePath(\n autoFillOptions[locale].replace('{{key}}', dictionaryKey),\n filePath,\n configuration.content.baseDir\n ),\n }));\n\n // Group by filePath and merge localeList\n const groupedByFilePath = output.reduce((acc, curr) => {\n const existing = acc.find((item) => item.filePath === curr.filePath);\n if (existing) {\n existing.localeList.push(...curr.localeList);\n } else {\n acc.push(curr);\n }\n return acc;\n }, [] as AutoFillData[]);\n\n outputContentDeclarationFile.push(...groupedByFilePath);\n }\n\n return outputContentDeclarationFile;\n};\n\nconst autoFill = async (\n fullDictionary: Dictionary,\n contentDeclarationFile: Dictionary,\n autoFillOptions: AutoFill,\n outputLocales: Locales[],\n parentLocales: Locales[],\n configuration: IntlayerConfig\n) => {\n const appLogger = getAppLogger(configuration);\n let localeList: Locales[] = (\n outputLocales ?? configuration.internationalization.locales\n ).filter((locale) => !parentLocales?.includes(locale));\n\n const filePath = contentDeclarationFile.filePath;\n\n if (!filePath) {\n appLogger('No file path found for dictionary', {\n level: 'error',\n });\n return;\n }\n\n const autoFillData: AutoFillData[] = formatAutoFillData(\n autoFillOptions,\n localeList,\n filePath,\n fullDictionary.key,\n configuration\n );\n\n appLogger(`Auto fill data: ${JSON.stringify(autoFillData, null, 2)}`, {\n level: 'info',\n isVerbose: true,\n });\n\n for await (const output of autoFillData) {\n const reducedDictionary = reduceDictionaryContent(\n fullDictionary,\n contentDeclarationFile\n );\n\n const isPerLocaleDeclarationFile = output.localeList.length === 1;\n\n if (isPerLocaleDeclarationFile) {\n const sourceLocale = output.localeList[0];\n\n const sourceLocaleContent = getLocalisedContent(\n reducedDictionary as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey: reducedDictionary.key, keyPath: [] }\n );\n\n await writeContentDeclaration({\n ...fullDictionary,\n locale: sourceLocale,\n autoFilled: true,\n autoFill: undefined,\n content: sourceLocaleContent.content,\n filePath: output.filePath,\n });\n } else {\n const content = getFilteredLocalesContent(\n reducedDictionary.content as unknown as ContentNode,\n output.localeList,\n { dictionaryKey: reducedDictionary.key, keyPath: [] }\n );\n\n // write file\n await writeContentDeclaration({\n ...fullDictionary,\n autoFilled: true,\n autoFill: undefined,\n content,\n filePath: output.filePath,\n });\n }\n }\n};\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options.mode ?? 'review';\n const baseLocale = options.sourceLocale ?? defaultLocale;\n\n checkAIAccess(configuration, options.aiOptions);\n\n let oAuth2AccessToken: string | undefined;\n if (configuration.editor.clientId) {\n const intlayerAuthAPI = getOAuthAPI(configuration);\n const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();\n\n oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n }\n\n appLogger('Starting fill function', {\n level: 'info',\n });\n\n const targetUnmergedDictionaries = await getTargetDictionary(options);\n\n // Determine output locales\n const outputLocalesList: Locales[] = (\n options.outputLocales ? ensureArray(options.outputLocales) : locales\n ).filter((locale) =>\n // If mode is review, translate all locales\n // If mode is complete, translate only the locales that are not the source locale\n mode === 'review' ? true : locale !== baseLocale\n );\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n appLogger(\n [\n 'Affected dictionary keys for processing:',\n Array.from(affectedDictionaryKeys).join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n\n for (const targetUnmergedDictionary of targetUnmergedDictionaries) {\n const dictionaryKey = targetUnmergedDictionary.key;\n const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];\n const sourceLocale: Locales =\n (targetUnmergedDictionary.locale as Locales) ?? baseLocale;\n\n if (!mainDictionaryToProcess) {\n appLogger(\n `Dictionary with key \"${dictionaryKey}\" not found in dictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n if (!targetUnmergedDictionary.filePath) {\n appLogger(\n `Dictionary with key \"${dictionaryKey}\" has no file path. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const relativePath = relative(\n configuration.content.baseDir,\n targetUnmergedDictionary.filePath\n );\n\n appLogger(`Processing content declaration: ${relativePath}`, {\n isVerbose: true,\n });\n\n const sourceLocaleContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n if (Object.keys(sourceLocaleContent).length === 0) {\n appLogger(\n `No content found for dictionary ${dictionaryKey} in source locale ${sourceLocale}. Skipping translation for this dictionary.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const result: Dictionary[] = [];\n\n // 5. for each locale to translate (exclude base locale) generate json translations\n // Limit concurrent translations to 5 at a time\n const limit = pLimit(\n options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS\n );\n\n const translationPromises = outputLocalesList.map((targetLocale) =>\n limit(async () => {\n appLogger(\n `Preparing translation for '${dictionaryKey}' dictionary from ${getLocaleName(\n sourceLocale,\n Locales.ENGLISH\n )} (${sourceLocale}) to ${getLocaleName(targetLocale, Locales.ENGLISH)} (${targetLocale})`,\n {\n isVerbose: true,\n }\n );\n\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n targetLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n try {\n const translationResult = await getAiAPI(\n undefined,\n configuration\n ).translateJSON(\n {\n entryFileContent: sourceLocaleContent.content, // Should be JSON, ensure getLocalisedContent provides this.\n presetOutputContent: presetOutputContent.content, // Should be JSON\n dictionaryDescription: mainDictionaryToProcess.description,\n entryLocale: sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions: options.aiOptions,\n },\n {\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n }\n );\n\n if (!translationResult.data?.fileContent) {\n appLogger(\n `No content result found for ${dictionaryKey} to ${targetLocale}`,\n {\n level: 'error',\n }\n );\n return null;\n }\n\n const processedPerLocaleDictionary = processPerLocaleDictionary({\n ...mainDictionaryToProcess,\n content: translationResult.data?.fileContent,\n locale: targetLocale,\n });\n\n return processedPerLocaleDictionary;\n } catch (error) {\n appLogger(\n `Error filling ${dictionaryKey} to ${targetLocale}:` + error,\n {\n level: 'error',\n }\n );\n return null;\n }\n })\n );\n\n // Wait for all translations to complete\n const translationResults = await Promise.all(translationPromises);\n\n // Filter out null results and add to result array\n translationResults.forEach((translationResult) => {\n if (translationResult) {\n result.push(translationResult);\n }\n });\n\n const dictionaryToMerge =\n mode === 'review'\n ? [...result, mainDictionaryToProcess] // Mode review: generated content will override the base one\n : [mainDictionaryToProcess, ...result]; // Mode complete: base content will override the generated one\n\n const mergedResults = mergeDictionaries(dictionaryToMerge);\n\n let formattedDict = targetUnmergedDictionary;\n\n if (formattedDict.locale) {\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n formattedDict.locale,\n { dictionaryKey, keyPath: [] }\n );\n\n formattedDict = {\n ...formattedDict,\n content: presetOutputContent.content,\n };\n }\n\n const reducedResult = reduceDictionaryContent(mergedResults, formattedDict);\n\n await writeContentDeclaration(\n { ...formattedDict, content: reducedResult.content },\n configuration,\n formattedDict.filePath\n );\n\n if (!formattedDict.autoFill) return;\n\n await autoFill(\n mergedResults,\n targetUnmergedDictionary,\n formattedDict.autoFill,\n outputLocalesList,\n [sourceLocale],\n configuration\n );\n }\n};\n"],"mappings":"AAAA,SAAoB,UAAU,mBAAmB;AACjD;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EAGA;AAAA,OACK;AACP;AAAA,EAIE;AAAA,EACA;AAAA,OACK;AACP,OAAO,wBAAwB;AAC/B,OAAO,gCAAgC;AACvC,OAAO,YAAY;AACnB,SAAS,SAAS,SAAS,MAAM,gBAAgB;AACjD,SAAS,qBAAqB;AAE9B,MAAM,6BAA6B;AAmBnC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;AAAA,UACF;AACA,iBAAO;AAAA,QACT;AAAA,MACF,CAAC;AAAA,IACH;AAGA,UAAM,qBAAqB,MAAM,QAAQ,IAAI,mBAAmB;AAGhE,uBAAmB,QAAQ,CAAC,sBAAsB;AAChD,UAAI,mBAAmB;AACrB,eAAO,KAAK,iBAAiB;AAAA,MAC/B;AAAA,IACF,CAAC;AAED,UAAM,oBACJ,SAAS,WACL,CAAC,GAAG,QAAQ,uBAAuB,IACnC,CAAC,yBAAyB,GAAG,MAAM;AAEzC,UAAM,gBAAgB,kBAAkB,iBAAiB;AAEzD,QAAI,gBAAgB;AAEpB,QAAI,cAAc,QAAQ;AACxB,YAAM,sBAAsB;AAAA,QAC1B;AAAA,QACA,cAAc;AAAA,QACd,EAAE,eAAe,SAAS,CAAC,EAAE;AAAA,MAC/B;AAEA,sBAAgB;AAAA,QACd,GAAG;AAAA,QACH,SAAS,oBAAoB;AAAA,MAC/B;AAAA,IACF;AAEA,UAAM,gBAAgB,wBAAwB,eAAe,aAAa;AAE1E,UAAM;AAAA,MACJ,EAAE,GAAG,eAAe,SAAS,cAAc,QAAQ;AAAA,MACnD;AAAA,MACA,cAAc;AAAA,IAChB;AAEA,QAAI,CAAC,cAAc,SAAU;AAE7B,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA,CAAC,YAAY;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":["localeList"]}
@@ -15,6 +15,7 @@ export type FillOptions = {
15
15
  configOptions?: GetConfigurationOptions;
16
16
  aiOptions?: AIOptions;
17
17
  verbose?: boolean;
18
+ nbConcurrentTranslations?: number;
18
19
  };
19
20
  export type AutoFillData = {
20
21
  localeList: Locales[];
@@ -1 +1 @@
1
- {"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../../src/fill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAyB,MAAM,eAAe,CAAC;AACjE,OAAO,EAGL,mBAAmB,EAKpB,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