poly-lexis 0.5.1 → 0.5.2

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.
@@ -1782,10 +1782,30 @@ function getMissingForLanguage(projectRoot, language) {
1782
1782
  }
1783
1783
 
1784
1784
  // src/translations/cli/auto-fill.ts
1785
+ async function processConcurrently(items, concurrency, processor) {
1786
+ const results = [];
1787
+ const executing = [];
1788
+ for (let i = 0; i < items.length; i++) {
1789
+ const item = items[i];
1790
+ const promise = processor(item, i).then((result) => {
1791
+ results[i] = result;
1792
+ });
1793
+ executing.push(promise);
1794
+ if (executing.length >= concurrency) {
1795
+ await Promise.race(executing);
1796
+ const index = executing.indexOf(promise);
1797
+ if (index !== -1) {
1798
+ executing.splice(index, 1);
1799
+ }
1800
+ }
1801
+ }
1802
+ await Promise.all(executing);
1803
+ return results;
1804
+ }
1785
1805
  async function autoFillTranslations(projectRoot = process.cwd(), options = {}) {
1786
1806
  const config = loadConfig(projectRoot);
1787
1807
  const translationsPath = path8.join(projectRoot, config.translationsPath);
1788
- const { apiKey, limit = 1e3, delayMs = 100, dryRun = false } = options;
1808
+ const { apiKey, limit = Infinity, delayMs = 50, dryRun = false, concurrency = 5 } = options;
1789
1809
  const currentProvider = getTranslationProvider();
1790
1810
  const isDefaultGoogleProvider = currentProvider.constructor.name === "GoogleTranslateProvider";
1791
1811
  if (isDefaultGoogleProvider) {
@@ -1812,7 +1832,8 @@ async function autoFillTranslations(projectRoot = process.cwd(), options = {}) {
1812
1832
  console.log("Auto-filling translations");
1813
1833
  console.log("=====");
1814
1834
  console.log(`Languages: ${languagesToProcess.join(", ")}`);
1815
- console.log(`Limit: ${limit}`);
1835
+ console.log(`Limit: ${limit === Infinity ? "unlimited" : limit}`);
1836
+ console.log(`Concurrency: ${concurrency}`);
1816
1837
  console.log(`Dry run: ${dryRun}`);
1817
1838
  console.log("=====");
1818
1839
  let totalProcessed = 0;
@@ -1832,11 +1853,12 @@ Processing language: ${language}`);
1832
1853
  }
1833
1854
  console.log(` Found ${missing.length} translations to fill`);
1834
1855
  const remainingLimit = limit - totalProcessed;
1835
- const itemsToProcess = missing.slice(0, remainingLimit);
1836
- for (const item of itemsToProcess) {
1837
- totalProcessed++;
1856
+ const itemsToProcess = missing.slice(0, remainingLimit === Infinity ? missing.length : remainingLimit);
1857
+ const results = await processConcurrently(itemsToProcess, concurrency, async (item, index) => {
1858
+ const currentCount = totalProcessed + index + 1;
1859
+ const limitDisplay = limit === Infinity ? itemsToProcess.length : limit;
1838
1860
  try {
1839
- console.log(` [${totalProcessed}/${limit}] Translating ${item.namespace}.${item.key}`);
1861
+ console.log(` [${currentCount}/${limitDisplay}] Translating ${item.namespace}.${item.key}`);
1840
1862
  console.log(` EN: "${item.sourceValue}"`);
1841
1863
  const translated = await translateText(
1842
1864
  item.sourceValue,
@@ -1858,14 +1880,17 @@ Processing language: ${language}`);
1858
1880
  } else {
1859
1881
  console.log(" \u2713 Dry run - not saved");
1860
1882
  }
1861
- totalTranslated++;
1862
- if (delayMs > 0 && totalProcessed < limit) {
1883
+ if (delayMs > 0) {
1863
1884
  await new Promise((resolve) => setTimeout(resolve, delayMs));
1864
1885
  }
1886
+ return { success: true, item };
1865
1887
  } catch (error) {
1866
1888
  console.error(` \u2717 Error: ${error instanceof Error ? error.message : "Unknown error"}`);
1889
+ return { success: false, item };
1867
1890
  }
1868
- }
1891
+ });
1892
+ totalProcessed += itemsToProcess.length;
1893
+ totalTranslated += results.filter((r) => r.success).length;
1869
1894
  }
1870
1895
  console.log("\n=====");
1871
1896
  console.log(`Total processed: ${totalProcessed}`);
@@ -1880,7 +1905,7 @@ Processing language: ${language}`);
1880
1905
  init_generate_types();
1881
1906
  init_init();
1882
1907
  async function manageTranslations(projectRoot = process.cwd(), options = {}) {
1883
- const { autoFill = false, apiKey, limit = 1e3, language, skipTypes = false, dryRun = false } = options;
1908
+ const { autoFill = false, apiKey, limit, concurrency = 5, language, skipTypes = false, dryRun = false } = options;
1884
1909
  console.log("=====");
1885
1910
  console.log("Translation Management");
1886
1911
  console.log("=====");
@@ -1938,9 +1963,10 @@ async function manageTranslations(projectRoot = process.cwd(), options = {}) {
1938
1963
  await autoFillTranslations(projectRoot, {
1939
1964
  apiKey,
1940
1965
  limit,
1966
+ concurrency,
1941
1967
  language,
1942
1968
  dryRun,
1943
- delayMs: 100
1969
+ delayMs: 50
1944
1970
  });
1945
1971
  if (!dryRun) {
1946
1972
  console.log("\n\u{1F50D} Re-validating after auto-fill...\n");
@@ -2006,8 +2032,11 @@ var { values, positionals } = parseArgs({
2006
2032
  type: "string"
2007
2033
  },
2008
2034
  limit: {
2035
+ type: "string"
2036
+ },
2037
+ concurrency: {
2009
2038
  type: "string",
2010
- default: "1000"
2039
+ default: "5"
2011
2040
  },
2012
2041
  language: {
2013
2042
  type: "string",
@@ -2057,7 +2086,8 @@ Options (Smart Mode):
2057
2086
  -a, --auto-fill Auto-fill missing translations with DeepL or Google Translate
2058
2087
  --api-key <key> Translation API key (or set DEEPL_API_KEY/GOOGLE_TRANSLATE_API_KEY)
2059
2088
  -l, --language <lang> Process only this language
2060
- --limit <number> Max translations to process (default: 1000)
2089
+ --limit <number> Max translations to process (default: unlimited)
2090
+ --concurrency <number> Number of concurrent translation requests (default: 5)
2061
2091
  --skip-types Skip TypeScript type generation
2062
2092
  -d, --dry-run Preview changes without saving
2063
2093
  -h, --help Show this help
@@ -2272,11 +2302,13 @@ if (command === "find-unused") {
2272
2302
  const provider = config.provider || "deepl";
2273
2303
  const envVarName = provider === "google" ? "GOOGLE_TRANSLATE_API_KEY" : "DEEPL_API_KEY";
2274
2304
  const apiKey = values["api-key"] || process.env[envVarName];
2275
- const limit = Number.parseInt(values.limit || "1000", 10);
2305
+ const limit = values.limit ? Number.parseInt(values.limit, 10) : void 0;
2306
+ const concurrency = Number.parseInt(values.concurrency || "5", 10);
2276
2307
  manageTranslations(process.cwd(), {
2277
2308
  autoFill: values["auto-fill"],
2278
2309
  apiKey,
2279
2310
  limit,
2311
+ concurrency,
2280
2312
  language: values.language,
2281
2313
  skipTypes: values["skip-types"],
2282
2314
  dryRun: values["dry-run"]