lingo.dev 0.74.17 → 0.75.1

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
@@ -287,6 +287,8 @@ function findLocaleFiles(bucket) {
287
287
  return findLocaleFilesWithExtension(".xml");
288
288
  case "markdown":
289
289
  return findLocaleFilesWithExtension(".md");
290
+ case "php":
291
+ return findLocaleFilesWithExtension(".php");
290
292
  case "xcode-xcstrings":
291
293
  return findLocaleFilesForFilename("Localizable.xcstrings");
292
294
  case "xcode-strings":
@@ -301,24 +303,31 @@ function findLocaleFilesWithExtension(ext) {
301
303
  const files = glob.sync(`**/*${ext}`, {
302
304
  ignore: ["node_modules/**", "package*.json", "i18n.json", "lingo.json"]
303
305
  });
304
- const localeFilePattern = new RegExp(`[/\\\\]([a-z]{2}(-[A-Z]{2})?)${ext}$`);
305
- const localeDirectoryPattern = new RegExp(`[/\\\\]([a-z]{2}(-[A-Z]{2})?)[/\\\\][^/\\\\]+${ext}$`);
306
+ const localeFilePattern = new RegExp(`/([a-z]{2}(-[A-Z]{2})?)${ext}$`);
307
+ const localeDirectoryPattern = new RegExp(`/([a-z]{2}(-[A-Z]{2})?)/[^/]+${ext}$`);
306
308
  const potentialLocaleFiles = files.filter(
307
309
  (file) => localeFilePattern.test(file) || localeDirectoryPattern.test(file)
308
310
  );
309
- const localeFilesAndPatterns = potentialLocaleFiles.map((file) => {
310
- const match = file.match(new RegExp(`[/|\\\\]([a-z]{2}(-[A-Z]{2})?)(/|\\\\|${ext})`));
311
- const locale = match?.[1];
312
- const localeInDir = match?.[3] !== ext;
313
- const filePattern = localeInDir ? file.replace(`/${locale}/`, `/[locale]/`) : path3.join(path3.dirname(file), `[locale]${ext}`);
314
- return { file, locale, pattern: filePattern };
315
- }).filter(({ locale }) => {
316
- try {
317
- resolveLocaleCode(locale);
318
- return true;
319
- } catch (e) {
311
+ const potantialLocaleFilesAndPatterns = potentialLocaleFiles.map((file) => {
312
+ const matchPotentialLocales = Array.from(
313
+ file.matchAll(new RegExp(`/([a-z]{2}(-[A-Z]{2})?|[^/]+)(?=/|${ext})`, "g"))
314
+ );
315
+ const potantialLocales = matchPotentialLocales.map((match) => match[1]);
316
+ return { file, potantialLocales };
317
+ }).map(({ file, potantialLocales }) => {
318
+ for (const locale of potantialLocales) {
319
+ try {
320
+ resolveLocaleCode(locale);
321
+ return { locale, file };
322
+ } catch (e) {
323
+ }
320
324
  }
321
- return false;
325
+ return { file, locale: null };
326
+ }).filter(({ locale }) => locale !== null);
327
+ const localeFilesAndPatterns = potantialLocaleFilesAndPatterns.map(({ file, locale }) => {
328
+ const localeInDir = file.match(`/${locale}/`);
329
+ const pattern = localeInDir ? file.replace(`/${locale}/`, `/[locale]/`) : path3.join(path3.dirname(file), `[locale]${ext}`);
330
+ return { pattern, file };
322
331
  });
323
332
  const grouppedFilesAndPatterns = _2.groupBy(localeFilesAndPatterns, "pattern");
324
333
  const patterns = Object.keys(grouppedFilesAndPatterns);
@@ -517,6 +526,8 @@ var init_default = new InteractiveCommand().command("init").description("Initial
517
526
  });
518
527
  } else {
519
528
  spinner.succeed("No existing locale files found.");
529
+ }
530
+ if (selectedPatterns.length === 0) {
520
531
  const useDefault = await confirm({
521
532
  message: `Use (and create) default path ${patterns.join(", ")}?`
522
533
  });
@@ -2537,10 +2548,10 @@ function createSyncLoader() {
2537
2548
 
2538
2549
  // src/cli/utils/plutil-formatter.ts
2539
2550
  function formatPlutilStyle(jsonData, existingJson) {
2540
- const indent = existingJson ? detectIndentation(existingJson) : " ";
2551
+ const indent2 = existingJson ? detectIndentation(existingJson) : " ";
2541
2552
  function format(data, level = 0) {
2542
- const currentIndent = indent.repeat(level);
2543
- const nextIndent = indent.repeat(level + 1);
2553
+ const currentIndent = indent2.repeat(level);
2554
+ const nextIndent = indent2.repeat(level + 1);
2544
2555
  if (typeof data !== "object" || data === null) {
2545
2556
  return JSON.stringify(data);
2546
2557
  }
@@ -2594,6 +2605,66 @@ function createPlutilJsonTextLoader() {
2594
2605
  });
2595
2606
  }
2596
2607
 
2608
+ // src/cli/loaders/php.ts
2609
+ import { fromString } from "php-array-reader";
2610
+ function createPhpLoader() {
2611
+ return createLoader({
2612
+ pull: async (locale, input2) => {
2613
+ try {
2614
+ const output = fromString(input2);
2615
+ return output;
2616
+ } catch (error) {
2617
+ throw new Error(`Error parsing PHP file for locale ${locale}`);
2618
+ }
2619
+ },
2620
+ push: async (locale, data, originalInput) => {
2621
+ const output = toPhpString(data, originalInput);
2622
+ return output;
2623
+ }
2624
+ });
2625
+ }
2626
+ function toPhpString(data, originalPhpString) {
2627
+ const defaultFilePrefix = "<?php\n\n";
2628
+ if (originalPhpString) {
2629
+ const [filePrefix = defaultFilePrefix] = originalPhpString.split("return ");
2630
+ const shortArraySyntax = !originalPhpString.includes("array(");
2631
+ const output = `${filePrefix}return ${toPhpArray(data, shortArraySyntax)};`;
2632
+ return output;
2633
+ }
2634
+ return `${defaultFilePrefix}return ${toPhpArray(data)};`;
2635
+ }
2636
+ function toPhpArray(data, shortSyntax = true, indentLevel = 1) {
2637
+ if (data === null || data === void 0) {
2638
+ return "null";
2639
+ }
2640
+ if (typeof data === "string") {
2641
+ return `'${escapePhpString(data)}'`;
2642
+ }
2643
+ if (typeof data === "number") {
2644
+ return data.toString();
2645
+ }
2646
+ if (typeof data === "boolean") {
2647
+ return data ? "true" : "false";
2648
+ }
2649
+ const arrayStart = shortSyntax ? "[" : "array(";
2650
+ const arrayEnd = shortSyntax ? "]" : ")";
2651
+ if (Array.isArray(data)) {
2652
+ return `${arrayStart}
2653
+ ${data.map((value) => `${indent(indentLevel)}${toPhpArray(value, shortSyntax, indentLevel + 1)}`).join(",\n")}
2654
+ ${indent(indentLevel - 1)}${arrayEnd}`;
2655
+ }
2656
+ const output = `${arrayStart}
2657
+ ${Object.entries(data).map(([key, value]) => `${indent(indentLevel)}'${key}' => ${toPhpArray(value, shortSyntax, indentLevel + 1)}`).join(",\n")}
2658
+ ${indent(indentLevel - 1)}${arrayEnd}`;
2659
+ return output;
2660
+ }
2661
+ function indent(level) {
2662
+ return " ".repeat(level);
2663
+ }
2664
+ function escapePhpString(str) {
2665
+ return str.replaceAll("\\", "\\\\").replaceAll("'", "\\'").replaceAll("\r", "\\r").replaceAll("\n", "\\n").replaceAll(" ", "\\t");
2666
+ }
2667
+
2597
2668
  // src/cli/loaders/index.ts
2598
2669
  function createBucketLoader(bucketType, bucketPathPattern, { isCacheRestore = false } = {}) {
2599
2670
  switch (bucketType) {
@@ -2748,6 +2819,14 @@ function createBucketLoader(bucketType, bucketPathPattern, { isCacheRestore = fa
2748
2819
  createSyncLoader(),
2749
2820
  createUnlocalizableLoader(isCacheRestore)
2750
2821
  );
2822
+ case "php":
2823
+ return composeLoaders(
2824
+ createTextFileLoader(bucketPathPattern),
2825
+ createPhpLoader(),
2826
+ createSyncLoader(),
2827
+ createFlatLoader(),
2828
+ createUnlocalizableLoader()
2829
+ );
2751
2830
  }
2752
2831
  }
2753
2832
 
@@ -3441,7 +3520,7 @@ function displaySummary(results) {
3441
3520
  // package.json
3442
3521
  var package_default = {
3443
3522
  name: "lingo.dev",
3444
- version: "0.74.17",
3523
+ version: "0.75.1",
3445
3524
  description: "Lingo.dev CLI",
3446
3525
  private: false,
3447
3526
  publishConfig: {
@@ -3485,10 +3564,10 @@ var package_default = {
3485
3564
  author: "",
3486
3565
  license: "Apache-2.0",
3487
3566
  dependencies: {
3488
- "@lingo.dev/_sdk": "workspace:*",
3489
- "@lingo.dev/_spec": "workspace:*",
3490
3567
  "@datocms/cma-client-node": "^3.4.0",
3491
3568
  "@inquirer/prompts": "^7.2.3",
3569
+ "@lingo.dev/_sdk": "workspace:*",
3570
+ "@lingo.dev/_spec": "workspace:*",
3492
3571
  "@paralleldrive/cuid2": "^2.2.2",
3493
3572
  chalk: "^5.4.1",
3494
3573
  cors: "^2.8.5",
@@ -3522,6 +3601,7 @@ var package_default = {
3522
3601
  open: "^10.1.0",
3523
3602
  ora: "^8.1.1",
3524
3603
  "p-limit": "^6.2.0",
3604
+ "php-array-reader": "^2.1.2",
3525
3605
  plist: "^3.1.0",
3526
3606
  prettier: "^3.4.2",
3527
3607
  "properties-parser": "^0.6.0",