lingo.dev 0.119.0 → 0.120.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.
package/build/cli.mjs CHANGED
@@ -9982,10 +9982,67 @@ function setNestedLocale(obj, path20, locale, value, originalLocale) {
9982
9982
  }
9983
9983
  }
9984
9984
 
9985
+ // src/cli/loaders/csv-per-locale.ts
9986
+ import { parse as parse4 } from "csv-parse/sync";
9987
+ import { stringify as stringify2 } from "csv-stringify/sync";
9988
+ function dedupeHeaders(headers) {
9989
+ const seen = /* @__PURE__ */ new Map();
9990
+ return headers.map((h) => {
9991
+ const count = seen.get(h) ?? 0;
9992
+ seen.set(h, count + 1);
9993
+ return count === 0 ? h : `${h}__${count + 1}`;
9994
+ });
9995
+ }
9996
+ function createCsvPerLocaleLoader() {
9997
+ return createLoader({
9998
+ async pull(_locale, input2) {
9999
+ if (!input2?.trim()) return {};
10000
+ const parsed = parse4(input2, {
10001
+ skip_empty_lines: true,
10002
+ columns: (headers) => {
10003
+ const dedupedHeaders = dedupeHeaders(headers);
10004
+ return dedupedHeaders;
10005
+ }
10006
+ });
10007
+ if (parsed.length === 0) return {};
10008
+ return parsed;
10009
+ },
10010
+ async push(_locale, data, originalInput) {
10011
+ const rawRows = parse4(originalInput || "", {
10012
+ skip_empty_lines: true
10013
+ });
10014
+ const originalHeaders = rawRows[0];
10015
+ const dedupedHeaders = dedupeHeaders(originalHeaders);
10016
+ const columns = originalHeaders.map((header, i) => ({
10017
+ key: dedupedHeaders[i],
10018
+ header
10019
+ }));
10020
+ const rows = Object.values(data).filter(
10021
+ (row) => row && Object.values(row).some(
10022
+ (v) => v !== void 0 && v !== null
10023
+ )
10024
+ );
10025
+ const output = stringify2(rows, {
10026
+ header: true,
10027
+ columns
10028
+ }).trimEnd();
10029
+ return output;
10030
+ }
10031
+ });
10032
+ }
10033
+
9985
10034
  // src/cli/loaders/index.ts
9986
10035
  function encodeKeys(keys) {
9987
10036
  return keys.map((key) => encodeURIComponent(key));
9988
10037
  }
10038
+ function normalizeCsvPatterns(patterns) {
10039
+ return patterns.map((pattern) => {
10040
+ if (pattern.includes("/") || pattern.startsWith("*/")) {
10041
+ return pattern;
10042
+ }
10043
+ return `*/${pattern}`;
10044
+ });
10045
+ }
9989
10046
  function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys, lockedPatterns, ignoredKeys) {
9990
10047
  switch (bucketType) {
9991
10048
  default:
@@ -10026,6 +10083,18 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys,
10026
10083
  createSyncLoader(),
10027
10084
  createUnlocalizableLoader(options.returnUnlocalizedKeys)
10028
10085
  );
10086
+ case "csv-per-locale":
10087
+ return composeLoaders(
10088
+ createTextFileLoader(bucketPathPattern),
10089
+ createLockedPatternsLoader(lockedPatterns),
10090
+ createCsvPerLocaleLoader(),
10091
+ createEnsureKeyOrderLoader(),
10092
+ createFlatLoader(),
10093
+ createLockedKeysLoader(normalizeCsvPatterns(lockedKeys || [])),
10094
+ createIgnoredKeysLoader(normalizeCsvPatterns(ignoredKeys || [])),
10095
+ createSyncLoader(),
10096
+ createUnlocalizableLoader(options.returnUnlocalizedKeys)
10097
+ );
10029
10098
  case "html":
10030
10099
  return composeLoaders(
10031
10100
  createTextFileLoader(bucketPathPattern),
@@ -12581,7 +12650,7 @@ function createExplicitLocalizer(provider) {
12581
12650
  function createAiSdkLocalizer(params) {
12582
12651
  const skipAuth = params.skipAuth === true;
12583
12652
  const apiKey = process.env[params?.apiKeyName ?? ""];
12584
- if (!skipAuth && !apiKey || !params.apiKeyName) {
12653
+ if (!skipAuth && (!apiKey || !params.apiKeyName)) {
12585
12654
  throw new Error(
12586
12655
  dedent7`
12587
12656
  You're trying to use raw ${chalk10.dim(params.id)} API for translation. ${params.apiKeyName ? `However, ${chalk10.dim(
@@ -13051,13 +13120,19 @@ import chalk13 from "chalk";
13051
13120
  import { Listr as Listr3 } from "listr2";
13052
13121
  import pLimit from "p-limit";
13053
13122
  import _35 from "lodash";
13054
- var MAX_WORKER_COUNT = 10;
13123
+ var WARN_CONCURRENCY_COUNT = 30;
13055
13124
  async function execute(input2) {
13056
13125
  const effectiveConcurrency = Math.min(
13057
13126
  input2.flags.concurrency,
13058
- input2.tasks.length,
13059
- MAX_WORKER_COUNT
13127
+ input2.tasks.length
13060
13128
  );
13129
+ if (effectiveConcurrency >= WARN_CONCURRENCY_COUNT) {
13130
+ console.warn(
13131
+ chalk13.yellow(
13132
+ `\u26A0\uFE0F High concurrency (${effectiveConcurrency}) may cause failures in some environments.`
13133
+ )
13134
+ );
13135
+ }
13061
13136
  console.log(chalk13.hex(colors.orange)(`[Localization]`));
13062
13137
  return new Listr3(
13063
13138
  [
@@ -15160,7 +15235,7 @@ async function renderHero2() {
15160
15235
  // package.json
15161
15236
  var package_default = {
15162
15237
  name: "lingo.dev",
15163
- version: "0.119.0",
15238
+ version: "0.120.0",
15164
15239
  description: "Lingo.dev CLI",
15165
15240
  private: false,
15166
15241
  repository: {