lingo.dev 0.92.13 → 0.92.14

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.
package/build/cli.mjs CHANGED
@@ -1025,7 +1025,7 @@ import {
1025
1025
  } from "@lingo.dev/_spec";
1026
1026
  import { Command as Command6 } from "interactive-commander";
1027
1027
  import Z3 from "zod";
1028
- import _25 from "lodash";
1028
+ import _26 from "lodash";
1029
1029
  import Ora5 from "ora";
1030
1030
 
1031
1031
  // src/cli/loaders/_utils.ts
@@ -1249,7 +1249,7 @@ function createTextFileLoader(pathPattern) {
1249
1249
  const trimmedResult = result.trim();
1250
1250
  return trimmedResult;
1251
1251
  },
1252
- async push(locale, data, _29, originalLocale) {
1252
+ async push(locale, data, _30, originalLocale) {
1253
1253
  const draftPath = pathPattern.replaceAll("[locale]", locale);
1254
1254
  const finalPath = path10.resolve(draftPath);
1255
1255
  const dirPath = path10.dirname(finalPath);
@@ -1778,7 +1778,7 @@ function createPropertiesLoader() {
1778
1778
  return result;
1779
1779
  },
1780
1780
  async push(locale, payload) {
1781
- const result = Object.entries(payload).filter(([_29, value]) => value != null).map(([key, value]) => `${key}=${value}`).join("\n");
1781
+ const result = Object.entries(payload).filter(([_30, value]) => value != null).map(([key, value]) => `${key}=${value}`).join("\n");
1782
1782
  return result;
1783
1783
  }
1784
1784
  });
@@ -2045,10 +2045,10 @@ function createUnlocalizableLoader(isCacheRestore = false, returnUnlocalizedKeys
2045
2045
  }
2046
2046
  }
2047
2047
  return false;
2048
- }).map(([key, _29]) => key);
2049
- const result = _10.omitBy(input2, (_29, key) => passthroughKeys.includes(key));
2048
+ }).map(([key, _30]) => key);
2049
+ const result = _10.omitBy(input2, (_30, key) => passthroughKeys.includes(key));
2050
2050
  if (returnUnlocalizedKeys) {
2051
- result.unlocalizable = _10.omitBy(input2, (_29, key) => !passthroughKeys.includes(key));
2051
+ result.unlocalizable = _10.omitBy(input2, (_30, key) => !passthroughKeys.includes(key));
2052
2052
  }
2053
2053
  return result;
2054
2054
  },
@@ -4005,8 +4005,24 @@ function createLingoLocalizer(params) {
4005
4005
 
4006
4006
  // src/cli/processor/basic.ts
4007
4007
  import { generateText } from "ai";
4008
+ import _24 from "lodash";
4008
4009
  function createBasicTranslator(model, systemPrompt) {
4009
4010
  return async (input2, onProgress) => {
4011
+ const chunks = extractPayloadChunks(input2.processableData);
4012
+ const subResults = [];
4013
+ for (let i = 0; i < chunks.length; i++) {
4014
+ const chunk = chunks[i];
4015
+ const result2 = await doJob({
4016
+ ...input2,
4017
+ processableData: chunk
4018
+ });
4019
+ subResults.push(result2);
4020
+ onProgress(i / chunks.length * 100, chunk, result2);
4021
+ }
4022
+ const result = _24.merge({}, ...subResults);
4023
+ return result;
4024
+ };
4025
+ async function doJob(input2) {
4010
4026
  if (!Object.keys(input2.processableData).length) {
4011
4027
  return input2.processableData;
4012
4028
  }
@@ -4052,7 +4068,41 @@ function createBasicTranslator(model, systemPrompt) {
4052
4068
  });
4053
4069
  const result = JSON.parse(response.text);
4054
4070
  return result?.data || {};
4055
- };
4071
+ }
4072
+ }
4073
+ function extractPayloadChunks(payload) {
4074
+ const idealBatchItemSize = 250;
4075
+ const batchSize = 25;
4076
+ const result = [];
4077
+ let currentChunk = {};
4078
+ let currentChunkItemCount = 0;
4079
+ const payloadEntries = Object.entries(payload);
4080
+ for (let i = 0; i < payloadEntries.length; i++) {
4081
+ const [key, value] = payloadEntries[i];
4082
+ currentChunk[key] = value;
4083
+ currentChunkItemCount++;
4084
+ const currentChunkSize = countWordsInRecord(currentChunk);
4085
+ if (currentChunkSize > idealBatchItemSize || currentChunkItemCount >= batchSize || i === payloadEntries.length - 1) {
4086
+ result.push(currentChunk);
4087
+ currentChunk = {};
4088
+ currentChunkItemCount = 0;
4089
+ }
4090
+ }
4091
+ return result;
4092
+ }
4093
+ function countWordsInRecord(payload) {
4094
+ if (Array.isArray(payload)) {
4095
+ return payload.reduce((acc, item) => acc + countWordsInRecord(item), 0);
4096
+ } else if (typeof payload === "object" && payload !== null) {
4097
+ return Object.values(payload).reduce(
4098
+ (acc, item) => acc + countWordsInRecord(item),
4099
+ 0
4100
+ );
4101
+ } else if (typeof payload === "string") {
4102
+ return payload.trim().split(/\s+/).filter(Boolean).length;
4103
+ } else {
4104
+ return 0;
4105
+ }
4056
4106
  }
4057
4107
 
4058
4108
  // src/cli/processor/index.ts
@@ -4178,7 +4228,7 @@ async function trackEvent(distinctId, event, properties) {
4178
4228
  }
4179
4229
 
4180
4230
  // src/cli/utils/delta.ts
4181
- import _24 from "lodash";
4231
+ import _25 from "lodash";
4182
4232
  import z from "zod";
4183
4233
 
4184
4234
  // src/cli/utils/fs.ts
@@ -4227,9 +4277,9 @@ function createDeltaProcessor(fileKey) {
4227
4277
  return checkIfFileExists(lockfilePath);
4228
4278
  },
4229
4279
  async calculateDelta(params) {
4230
- let added = _24.difference(Object.keys(params.sourceData), Object.keys(params.targetData));
4231
- let removed = _24.difference(Object.keys(params.targetData), Object.keys(params.sourceData));
4232
- const updated = _24.filter(Object.keys(params.sourceData), (key) => {
4280
+ let added = _25.difference(Object.keys(params.sourceData), Object.keys(params.targetData));
4281
+ let removed = _25.difference(Object.keys(params.targetData), Object.keys(params.sourceData));
4282
+ const updated = _25.filter(Object.keys(params.sourceData), (key) => {
4233
4283
  return md5(params.sourceData[key]) !== params.checksums[key] && params.checksums[key];
4234
4284
  });
4235
4285
  const renamed = [];
@@ -4278,7 +4328,7 @@ function createDeltaProcessor(fileKey) {
4278
4328
  await this.saveLock(lockfileData);
4279
4329
  },
4280
4330
  async createChecksums(sourceData) {
4281
- const checksums = _24.mapValues(sourceData, (value) => md5(value));
4331
+ const checksums = _25.mapValues(sourceData, (value) => md5(value));
4282
4332
  return checksums;
4283
4333
  }
4284
4334
  };
@@ -4450,7 +4500,7 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
4450
4500
  const deltaProcessor = createDeltaProcessor(bucketPath.pathPattern);
4451
4501
  const sourceChecksums = await deltaProcessor.createChecksums(sourceData);
4452
4502
  const savedChecksums = await deltaProcessor.loadChecksums();
4453
- const updatedSourceData = _25.pickBy(
4503
+ const updatedSourceData = _26.pickBy(
4454
4504
  sourceData,
4455
4505
  (value, key) => sourceChecksums[key] !== savedChecksums[key]
4456
4506
  );
@@ -4464,15 +4514,15 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
4464
4514
  bucketPath.delimiter
4465
4515
  );
4466
4516
  const { unlocalizable: targetUnlocalizable, ...targetData } = await bucketLoader.pull(targetLocale);
4467
- const missingKeys = _25.difference(
4517
+ const missingKeys = _26.difference(
4468
4518
  Object.keys(sourceData),
4469
4519
  Object.keys(targetData)
4470
4520
  );
4471
- const extraKeys = _25.difference(
4521
+ const extraKeys = _26.difference(
4472
4522
  Object.keys(targetData),
4473
4523
  Object.keys(sourceData)
4474
4524
  );
4475
- const unlocalizableDataDiff = !_25.isEqual(
4525
+ const unlocalizableDataDiff = !_26.isEqual(
4476
4526
  sourceUnlocalizable,
4477
4527
  targetUnlocalizable
4478
4528
  );
@@ -4554,13 +4604,13 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
4554
4604
  targetData,
4555
4605
  checksums: checksums2
4556
4606
  });
4557
- let processableData = _25.chain(sourceData).entries().filter(
4607
+ let processableData = _26.chain(sourceData).entries().filter(
4558
4608
  ([key, value]) => delta.added.includes(key) || delta.updated.includes(key) || !!flags.force
4559
4609
  ).fromPairs().value();
4560
4610
  if (flags.key) {
4561
- processableData = _25.pickBy(
4611
+ processableData = _26.pickBy(
4562
4612
  processableData,
4563
- (_29, key) => key === flags.key
4613
+ (_30, key) => key === flags.key
4564
4614
  );
4565
4615
  }
4566
4616
  if (flags.verbose) {
@@ -4593,13 +4643,13 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
4593
4643
  if (flags.verbose) {
4594
4644
  bucketOra.info(JSON.stringify(processedTargetData, null, 2));
4595
4645
  }
4596
- let finalTargetData = _25.merge(
4646
+ let finalTargetData = _26.merge(
4597
4647
  {},
4598
4648
  sourceData,
4599
4649
  targetData,
4600
4650
  processedTargetData
4601
4651
  );
4602
- finalTargetData = _25.chain(finalTargetData).entries().map(([key, value]) => {
4652
+ finalTargetData = _26.chain(finalTargetData).entries().map(([key, value]) => {
4603
4653
  const renaming = delta.renamed.find(
4604
4654
  ([oldKey, newKey]) => oldKey === key
4605
4655
  );
@@ -4623,7 +4673,7 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
4623
4673
  `Applying changes to ${bucketPath} (${targetLocale})`
4624
4674
  );
4625
4675
  }
4626
- const finalDiffSize = _25.chain(finalTargetData).omitBy((value, key) => value === targetData[key]).size().value();
4676
+ const finalDiffSize = _26.chain(finalTargetData).omitBy((value, key) => value === targetData[key]).size().value();
4627
4677
  await bucketLoader.push(targetLocale, finalTargetData);
4628
4678
  if (finalDiffSize > 0 || flags.force) {
4629
4679
  bucketOra.succeed(
@@ -4794,7 +4844,7 @@ Reviewing changes for ${chalk2.blue(args.pathPattern)} (${chalk2.yellow(args.tar
4794
4844
  return args.currentData;
4795
4845
  }
4796
4846
  const customData = { ...args.currentData };
4797
- const changes = _25.reduce(
4847
+ const changes = _26.reduce(
4798
4848
  args.proposedData,
4799
4849
  (result, value, key) => {
4800
4850
  if (args.currentData[key] !== value) {
@@ -4867,7 +4917,7 @@ import path14 from "path";
4867
4917
  import Z4 from "zod";
4868
4918
  import YAML5 from "yaml";
4869
4919
  import { MD5 as MD52 } from "object-hash";
4870
- import _26 from "lodash";
4920
+ import _27 from "lodash";
4871
4921
  function createLockfileHelper() {
4872
4922
  return {
4873
4923
  isLockfileExists: () => {
@@ -4877,23 +4927,23 @@ function createLockfileHelper() {
4877
4927
  registerSourceData: (pathPattern, sourceData) => {
4878
4928
  const lockfile = _loadLockfile();
4879
4929
  const sectionKey = MD52(pathPattern);
4880
- const sectionChecksums = _26.mapValues(sourceData, (value) => MD52(value));
4930
+ const sectionChecksums = _27.mapValues(sourceData, (value) => MD52(value));
4881
4931
  lockfile.checksums[sectionKey] = sectionChecksums;
4882
4932
  _saveLockfile(lockfile);
4883
4933
  },
4884
4934
  registerPartialSourceData: (pathPattern, partialSourceData) => {
4885
4935
  const lockfile = _loadLockfile();
4886
4936
  const sectionKey = MD52(pathPattern);
4887
- const sectionChecksums = _26.mapValues(partialSourceData, (value) => MD52(value));
4888
- lockfile.checksums[sectionKey] = _26.merge({}, lockfile.checksums[sectionKey] ?? {}, sectionChecksums);
4937
+ const sectionChecksums = _27.mapValues(partialSourceData, (value) => MD52(value));
4938
+ lockfile.checksums[sectionKey] = _27.merge({}, lockfile.checksums[sectionKey] ?? {}, sectionChecksums);
4889
4939
  _saveLockfile(lockfile);
4890
4940
  },
4891
4941
  extractUpdatedData: (pathPattern, sourceData) => {
4892
4942
  const lockfile = _loadLockfile();
4893
4943
  const sectionKey = MD52(pathPattern);
4894
- const currentChecksums = _26.mapValues(sourceData, (value) => MD52(value));
4944
+ const currentChecksums = _27.mapValues(sourceData, (value) => MD52(value));
4895
4945
  const savedChecksums = lockfile.checksums[sectionKey] || {};
4896
- const updatedData = _26.pickBy(sourceData, (value, key) => savedChecksums[key] !== currentChecksums[key]);
4946
+ const updatedData = _27.pickBy(sourceData, (value, key) => savedChecksums[key] !== currentChecksums[key]);
4897
4947
  return updatedData;
4898
4948
  }
4899
4949
  };
@@ -4963,7 +5013,7 @@ var flagsSchema = Z5.object({
4963
5013
  // src/cli/cmd/cleanup.ts
4964
5014
  import { resolveOverriddenLocale as resolveOverriddenLocale5 } from "@lingo.dev/_spec";
4965
5015
  import { Command as Command8 } from "interactive-commander";
4966
- import _27 from "lodash";
5016
+ import _28 from "lodash";
4967
5017
  import Ora7 from "ora";
4968
5018
  var cleanup_default = new Command8().command("cleanup").description("Remove keys from target files that do not exist in the source file").helpOption("-h, --help", "Show help").option("--locale <locale>", "Specific locale to cleanup").option("--bucket <bucket>", "Specific bucket to cleanup").option("--dry-run", "Show what would be removed without making changes").option(
4969
5019
  "--verbose",
@@ -4999,7 +5049,7 @@ var cleanup_default = new Command8().command("cleanup").description("Remove keys
4999
5049
  try {
5000
5050
  const targetData = await bucketLoader.pull(targetLocale);
5001
5051
  const targetKeys = Object.keys(targetData);
5002
- const keysToRemove = _27.difference(targetKeys, sourceKeys);
5052
+ const keysToRemove = _28.difference(targetKeys, sourceKeys);
5003
5053
  if (keysToRemove.length === 0) {
5004
5054
  bucketOra.succeed(`[${targetLocale}] No keys to remove`);
5005
5055
  continue;
@@ -5008,7 +5058,7 @@ var cleanup_default = new Command8().command("cleanup").description("Remove keys
5008
5058
  bucketOra.info(`[${targetLocale}] Keys to remove: ${JSON.stringify(keysToRemove, null, 2)}`);
5009
5059
  }
5010
5060
  if (!options.dryRun) {
5011
- const cleanedData = _27.pick(targetData, sourceKeys);
5061
+ const cleanedData = _28.pick(targetData, sourceKeys);
5012
5062
  await bucketLoader.push(targetLocale, cleanedData);
5013
5063
  bucketOra.succeed(`[${targetLocale}] Removed ${keysToRemove.length} keys`);
5014
5064
  } else {
@@ -5063,7 +5113,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
5063
5113
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5064
5114
  import Z6 from "zod";
5065
5115
  import { ReplexicaEngine } from "@lingo.dev/_sdk";
5066
- var mcp_default = new Command9().command("mcp").description("Use Lingo.dev model context provider with your AI agent").helpOption("-h, --help", "Show help").action(async (_29, program) => {
5116
+ var mcp_default = new Command9().command("mcp").description("Use Lingo.dev model context provider with your AI agent").helpOption("-h, --help", "Show help").action(async (_30, program) => {
5067
5117
  const apiKey = program.args[0];
5068
5118
  const settings = getSettings(apiKey);
5069
5119
  if (!settings.auth.apiKey) {
@@ -6317,7 +6367,7 @@ async function renderHero() {
6317
6367
  // package.json
6318
6368
  var package_default = {
6319
6369
  name: "lingo.dev",
6320
- version: "0.92.13",
6370
+ version: "0.92.14",
6321
6371
  description: "Lingo.dev CLI",
6322
6372
  private: false,
6323
6373
  publishConfig: {
@@ -6885,7 +6935,7 @@ async function plan(input2) {
6885
6935
  import chalk10 from "chalk";
6886
6936
  import { Listr as Listr3 } from "listr2";
6887
6937
  import pLimit from "p-limit";
6888
- import _28 from "lodash";
6938
+ import _29 from "lodash";
6889
6939
  var MAX_WORKER_COUNT = 10;
6890
6940
  async function execute(input2) {
6891
6941
  const effectiveConcurrency = Math.min(
@@ -6916,7 +6966,7 @@ async function execute(input2) {
6916
6966
  const workerTasks = [];
6917
6967
  for (let i = 0; i < workersCount; i++) {
6918
6968
  const assignedTasks = ctx.tasks.filter(
6919
- (_29, idx) => idx % workersCount === i
6969
+ (_30, idx) => idx % workersCount === i
6920
6970
  );
6921
6971
  workerTasks.push(
6922
6972
  createWorkerTask({
@@ -7015,7 +7065,7 @@ function createWorkerTask(args) {
7015
7065
  targetData,
7016
7066
  checksums
7017
7067
  });
7018
- const processableData = _28.chain(sourceData).entries().filter(
7068
+ const processableData = _29.chain(sourceData).entries().filter(
7019
7069
  ([key, value]) => delta.added.includes(key) || delta.updated.includes(key) || !!args.ctx.flags.force
7020
7070
  ).fromPairs().value();
7021
7071
  if (!Object.keys(processableData).length) {
@@ -7036,13 +7086,13 @@ function createWorkerTask(args) {
7036
7086
  });
7037
7087
  }
7038
7088
  );
7039
- let finalTargetData = _28.merge(
7089
+ let finalTargetData = _29.merge(
7040
7090
  {},
7041
7091
  sourceData,
7042
7092
  targetData,
7043
7093
  processedTargetData
7044
7094
  );
7045
- finalTargetData = _28.chain(finalTargetData).entries().map(([key, value]) => {
7095
+ finalTargetData = _29.chain(finalTargetData).entries().map(([key, value]) => {
7046
7096
  const renaming = delta.renamed.find(
7047
7097
  ([oldKey]) => oldKey === key
7048
7098
  );