poly-lexis 0.5.1 → 0.5.3

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.
@@ -1201,6 +1201,11 @@ function preserveVariables(text) {
1201
1201
  variableMap.set(placeholder, match);
1202
1202
  placeholderIndex++;
1203
1203
  return placeholder;
1204
+ }).replace(/\{([^}]+)\}/g, (match) => {
1205
+ const placeholder = `XXX_${placeholderIndex}_XXX`;
1206
+ variableMap.set(placeholder, match);
1207
+ placeholderIndex++;
1208
+ return placeholder;
1204
1209
  });
1205
1210
  return { textWithPlaceholders, variableMap };
1206
1211
  }
@@ -1295,6 +1300,11 @@ function preserveVariables2(text) {
1295
1300
  variableMap.set(placeholder, match);
1296
1301
  placeholderIndex++;
1297
1302
  return placeholder;
1303
+ }).replace(/\{([^}]+)\}/g, (match) => {
1304
+ const placeholder = `XXX_${placeholderIndex}_XXX`;
1305
+ variableMap.set(placeholder, match);
1306
+ placeholderIndex++;
1307
+ return placeholder;
1298
1308
  });
1299
1309
  return { textWithPlaceholders, variableMap };
1300
1310
  }
@@ -1782,10 +1792,30 @@ function getMissingForLanguage(projectRoot, language) {
1782
1792
  }
1783
1793
 
1784
1794
  // src/translations/cli/auto-fill.ts
1795
+ async function processConcurrently(items, concurrency, processor) {
1796
+ const results = [];
1797
+ const executing = [];
1798
+ for (let i = 0; i < items.length; i++) {
1799
+ const item = items[i];
1800
+ const promise = processor(item, i).then((result) => {
1801
+ results[i] = result;
1802
+ });
1803
+ executing.push(promise);
1804
+ if (executing.length >= concurrency) {
1805
+ await Promise.race(executing);
1806
+ const index = executing.indexOf(promise);
1807
+ if (index !== -1) {
1808
+ executing.splice(index, 1);
1809
+ }
1810
+ }
1811
+ }
1812
+ await Promise.all(executing);
1813
+ return results;
1814
+ }
1785
1815
  async function autoFillTranslations(projectRoot = process.cwd(), options = {}) {
1786
1816
  const config = loadConfig(projectRoot);
1787
1817
  const translationsPath = path8.join(projectRoot, config.translationsPath);
1788
- const { apiKey, limit = 1e3, delayMs = 100, dryRun = false } = options;
1818
+ const { apiKey, limit = Infinity, delayMs = 50, dryRun = false, concurrency = 5 } = options;
1789
1819
  const currentProvider = getTranslationProvider();
1790
1820
  const isDefaultGoogleProvider = currentProvider.constructor.name === "GoogleTranslateProvider";
1791
1821
  if (isDefaultGoogleProvider) {
@@ -1812,7 +1842,8 @@ async function autoFillTranslations(projectRoot = process.cwd(), options = {}) {
1812
1842
  console.log("Auto-filling translations");
1813
1843
  console.log("=====");
1814
1844
  console.log(`Languages: ${languagesToProcess.join(", ")}`);
1815
- console.log(`Limit: ${limit}`);
1845
+ console.log(`Limit: ${limit === Infinity ? "unlimited" : limit}`);
1846
+ console.log(`Concurrency: ${concurrency}`);
1816
1847
  console.log(`Dry run: ${dryRun}`);
1817
1848
  console.log("=====");
1818
1849
  let totalProcessed = 0;
@@ -1832,11 +1863,12 @@ Processing language: ${language}`);
1832
1863
  }
1833
1864
  console.log(` Found ${missing.length} translations to fill`);
1834
1865
  const remainingLimit = limit - totalProcessed;
1835
- const itemsToProcess = missing.slice(0, remainingLimit);
1836
- for (const item of itemsToProcess) {
1837
- totalProcessed++;
1866
+ const itemsToProcess = missing.slice(0, remainingLimit === Infinity ? missing.length : remainingLimit);
1867
+ const results = await processConcurrently(itemsToProcess, concurrency, async (item, index) => {
1868
+ const currentCount = totalProcessed + index + 1;
1869
+ const limitDisplay = limit === Infinity ? itemsToProcess.length : limit;
1838
1870
  try {
1839
- console.log(` [${totalProcessed}/${limit}] Translating ${item.namespace}.${item.key}`);
1871
+ console.log(` [${currentCount}/${limitDisplay}] Translating ${item.namespace}.${item.key}`);
1840
1872
  console.log(` EN: "${item.sourceValue}"`);
1841
1873
  const translated = await translateText(
1842
1874
  item.sourceValue,
@@ -1858,14 +1890,17 @@ Processing language: ${language}`);
1858
1890
  } else {
1859
1891
  console.log(" \u2713 Dry run - not saved");
1860
1892
  }
1861
- totalTranslated++;
1862
- if (delayMs > 0 && totalProcessed < limit) {
1893
+ if (delayMs > 0) {
1863
1894
  await new Promise((resolve) => setTimeout(resolve, delayMs));
1864
1895
  }
1896
+ return { success: true, item };
1865
1897
  } catch (error) {
1866
1898
  console.error(` \u2717 Error: ${error instanceof Error ? error.message : "Unknown error"}`);
1899
+ return { success: false, item };
1867
1900
  }
1868
- }
1901
+ });
1902
+ totalProcessed += itemsToProcess.length;
1903
+ totalTranslated += results.filter((r) => r.success).length;
1869
1904
  }
1870
1905
  console.log("\n=====");
1871
1906
  console.log(`Total processed: ${totalProcessed}`);
@@ -1880,7 +1915,7 @@ Processing language: ${language}`);
1880
1915
  init_generate_types();
1881
1916
  init_init();
1882
1917
  async function manageTranslations(projectRoot = process.cwd(), options = {}) {
1883
- const { autoFill = false, apiKey, limit = 1e3, language, skipTypes = false, dryRun = false } = options;
1918
+ const { autoFill = false, apiKey, limit, concurrency = 5, language, skipTypes = false, dryRun = false } = options;
1884
1919
  console.log("=====");
1885
1920
  console.log("Translation Management");
1886
1921
  console.log("=====");
@@ -1938,9 +1973,10 @@ async function manageTranslations(projectRoot = process.cwd(), options = {}) {
1938
1973
  await autoFillTranslations(projectRoot, {
1939
1974
  apiKey,
1940
1975
  limit,
1976
+ concurrency,
1941
1977
  language,
1942
1978
  dryRun,
1943
- delayMs: 100
1979
+ delayMs: 50
1944
1980
  });
1945
1981
  if (!dryRun) {
1946
1982
  console.log("\n\u{1F50D} Re-validating after auto-fill...\n");
@@ -2006,8 +2042,11 @@ var { values, positionals } = parseArgs({
2006
2042
  type: "string"
2007
2043
  },
2008
2044
  limit: {
2045
+ type: "string"
2046
+ },
2047
+ concurrency: {
2009
2048
  type: "string",
2010
- default: "1000"
2049
+ default: "5"
2011
2050
  },
2012
2051
  language: {
2013
2052
  type: "string",
@@ -2057,7 +2096,8 @@ Options (Smart Mode):
2057
2096
  -a, --auto-fill Auto-fill missing translations with DeepL or Google Translate
2058
2097
  --api-key <key> Translation API key (or set DEEPL_API_KEY/GOOGLE_TRANSLATE_API_KEY)
2059
2098
  -l, --language <lang> Process only this language
2060
- --limit <number> Max translations to process (default: 1000)
2099
+ --limit <number> Max translations to process (default: unlimited)
2100
+ --concurrency <number> Number of concurrent translation requests (default: 5)
2061
2101
  --skip-types Skip TypeScript type generation
2062
2102
  -d, --dry-run Preview changes without saving
2063
2103
  -h, --help Show this help
@@ -2272,11 +2312,13 @@ if (command === "find-unused") {
2272
2312
  const provider = config.provider || "deepl";
2273
2313
  const envVarName = provider === "google" ? "GOOGLE_TRANSLATE_API_KEY" : "DEEPL_API_KEY";
2274
2314
  const apiKey = values["api-key"] || process.env[envVarName];
2275
- const limit = Number.parseInt(values.limit || "1000", 10);
2315
+ const limit = values.limit ? Number.parseInt(values.limit, 10) : void 0;
2316
+ const concurrency = Number.parseInt(values.concurrency || "5", 10);
2276
2317
  manageTranslations(process.cwd(), {
2277
2318
  autoFill: values["auto-fill"],
2278
2319
  apiKey,
2279
2320
  limit,
2321
+ concurrency,
2280
2322
  language: values.language,
2281
2323
  skipTypes: values["skip-types"],
2282
2324
  dryRun: values["dry-run"]