lingo.dev 0.78.1 → 0.78.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.
package/build/cli.mjs CHANGED
@@ -297,7 +297,7 @@ function findLocaleFiles(bucket) {
297
297
  case "xcode-stringsdict":
298
298
  return findLocaleFilesForFilename("Localizable.stringsdict");
299
299
  default:
300
- throw new Error(`Unsupported bucket type: ${bucket}`);
300
+ return null;
301
301
  }
302
302
  }
303
303
  function findLocaleFilesWithExtension(ext) {
@@ -681,38 +681,50 @@ var init_default = new InteractiveCommand().command("init").description("Initial
681
681
  };
682
682
  } else {
683
683
  let selectedPatterns = [];
684
- const { patterns, defaultPatterns } = findLocaleFiles(options.bucket);
685
- if (patterns.length > 0) {
686
- spinner.succeed("Found existing locale files:");
687
- selectedPatterns = await checkbox2({
688
- message: "Select the paths to use",
689
- choices: patterns.map((value) => ({
690
- value
691
- }))
692
- });
684
+ const localeFiles = findLocaleFiles(options.bucket);
685
+ if (!localeFiles) {
686
+ spinner.warn(
687
+ `Bucket type "${options.bucket}" does not supported automatic initialization. Add paths to "i18n.json" manually.`
688
+ );
689
+ newConfig.buckets = {
690
+ [options.bucket]: {
691
+ include: options.paths || []
692
+ }
693
+ };
693
694
  } else {
694
- spinner.succeed("No existing locale files found.");
695
- }
696
- if (selectedPatterns.length === 0) {
697
- const useDefault = await confirm2({
698
- message: `Use (and create) default path ${defaultPatterns.join(", ")}?`
699
- });
700
- if (useDefault) {
701
- ensurePatterns(defaultPatterns, options.source);
702
- selectedPatterns = defaultPatterns;
695
+ const { patterns, defaultPatterns } = localeFiles;
696
+ if (patterns.length > 0) {
697
+ spinner.succeed("Found existing locale files:");
698
+ selectedPatterns = await checkbox2({
699
+ message: "Select the paths to use",
700
+ choices: patterns.map((value) => ({
701
+ value
702
+ }))
703
+ });
704
+ } else {
705
+ spinner.succeed("No existing locale files found.");
703
706
  }
704
- }
705
- if (selectedPatterns.length === 0) {
706
- const customPaths = await input({
707
- message: "Enter paths to use"
708
- });
709
- selectedPatterns = customPaths.includes(",") ? customPaths.split(",") : customPaths.split(" ");
710
- }
711
- newConfig.buckets = {
712
- [options.bucket]: {
713
- include: selectedPatterns || []
707
+ if (selectedPatterns.length === 0) {
708
+ const useDefault = await confirm2({
709
+ message: `Use (and create) default path ${defaultPatterns.join(", ")}?`
710
+ });
711
+ if (useDefault) {
712
+ ensurePatterns(defaultPatterns, options.source);
713
+ selectedPatterns = defaultPatterns;
714
+ }
714
715
  }
715
- };
716
+ if (selectedPatterns.length === 0) {
717
+ const customPaths = await input({
718
+ message: "Enter paths to use"
719
+ });
720
+ selectedPatterns = customPaths.includes(",") ? customPaths.split(",") : customPaths.split(" ");
721
+ }
722
+ newConfig.buckets = {
723
+ [options.bucket]: {
724
+ include: selectedPatterns || []
725
+ }
726
+ };
727
+ }
716
728
  }
717
729
  await saveConfig(newConfig);
718
730
  spinner.succeed("Lingo.dev project initialized");
@@ -2857,6 +2869,41 @@ function escapePhpString(str) {
2857
2869
  return str.replaceAll("\\", "\\\\").replaceAll("'", "\\'").replaceAll("\r", "\\r").replaceAll("\n", "\\n").replaceAll(" ", "\\t");
2858
2870
  }
2859
2871
 
2872
+ // src/cli/loaders/vue-json.ts
2873
+ import { jsonrepair as jsonrepair2 } from "jsonrepair";
2874
+ function createVueJsonLoader() {
2875
+ return createLoader({
2876
+ pull: async (locale, input2, ctx) => {
2877
+ const parsed = parseVueFile(input2);
2878
+ return parsed?.i18n?.[locale] ?? {};
2879
+ },
2880
+ push: async (locale, data, originalInput) => {
2881
+ const parsed = parseVueFile(originalInput ?? "");
2882
+ if (!parsed) {
2883
+ return originalInput ?? "";
2884
+ }
2885
+ parsed.i18n[locale] = data;
2886
+ return `${parsed.before}<i18n>
2887
+ ${JSON.stringify(parsed.i18n, null, 2)}
2888
+ </i18n>${parsed.after}`;
2889
+ }
2890
+ });
2891
+ }
2892
+ function parseVueFile(input2) {
2893
+ const match = input2.match(/^([\s\S]*)<i18n>([\s\S]*)<\/i18n>([\s\S]*)$/);
2894
+ if (!match) {
2895
+ return null;
2896
+ }
2897
+ const [, before, jsonString = "{}", after] = match;
2898
+ let i18n;
2899
+ try {
2900
+ i18n = JSON.parse(jsonString);
2901
+ } catch (error) {
2902
+ i18n = JSON.parse(jsonrepair2(jsonString));
2903
+ }
2904
+ return { before, after, i18n };
2905
+ }
2906
+
2860
2907
  // src/cli/loaders/index.ts
2861
2908
  function createBucketLoader(bucketType, bucketPathPattern, options) {
2862
2909
  switch (bucketType) {
@@ -3019,6 +3066,14 @@ function createBucketLoader(bucketType, bucketPathPattern, options) {
3019
3066
  createFlatLoader(),
3020
3067
  createUnlocalizableLoader(options.isCacheRestore)
3021
3068
  );
3069
+ case "vue-json":
3070
+ return composeLoaders(
3071
+ createTextFileLoader(bucketPathPattern),
3072
+ createVueJsonLoader(),
3073
+ createSyncLoader(),
3074
+ createFlatLoader(),
3075
+ createUnlocalizableLoader()
3076
+ );
3022
3077
  }
3023
3078
  }
3024
3079
 
@@ -3782,7 +3837,7 @@ var mcp_default = new Command9().command("mcp").description("Use Lingo.dev model
3782
3837
  // package.json
3783
3838
  var package_default = {
3784
3839
  name: "lingo.dev",
3785
- version: "0.78.1",
3840
+ version: "0.78.3",
3786
3841
  description: "Lingo.dev CLI",
3787
3842
  private: false,
3788
3843
  publishConfig: {