lingo.dev 0.78.0 → 0.78.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.
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");
@@ -1691,12 +1703,10 @@ function createXcodeXcstringsLoader(defaultLocale) {
1691
1703
  }
1692
1704
  }
1693
1705
  } else if (isSourceLanguage) {
1694
- const hasOtherLocalizations = rootTranslationEntity?.localizations && Object.keys(rootTranslationEntity.localizations).length > 0;
1695
- if (hasOtherLocalizations) {
1696
- resultData[translationKey] = translationKey;
1697
- }
1706
+ resultData[translationKey] = translationKey;
1698
1707
  }
1699
1708
  }
1709
+ console.log(resultData);
1700
1710
  return resultData;
1701
1711
  },
1702
1712
  async push(locale, payload, originalInput) {
@@ -1710,7 +1720,7 @@ function createXcodeXcstringsLoader(defaultLocale) {
1710
1720
  const hasDoNotTranslateFlag = originalInput && originalInput.strings && originalInput.strings[key] && originalInput.strings[key].shouldTranslate === false;
1711
1721
  if (typeof value === "string") {
1712
1722
  langDataToMerge.strings[key] = {
1713
- extractionState: "manual",
1723
+ extractionState: originalInput?.strings?.[key]?.extractionState,
1714
1724
  localizations: {
1715
1725
  [locale]: {
1716
1726
  stringUnit: {
@@ -2859,6 +2869,34 @@ function escapePhpString(str) {
2859
2869
  return str.replaceAll("\\", "\\\\").replaceAll("'", "\\'").replaceAll("\r", "\\r").replaceAll("\n", "\\n").replaceAll(" ", "\\t");
2860
2870
  }
2861
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 { i18n } = parseVueFile(input2);
2878
+ return i18n[locale] ?? {};
2879
+ },
2880
+ push: async (locale, data, originalInput) => {
2881
+ const { before, i18n, after } = parseVueFile(originalInput ?? "");
2882
+ i18n[locale] = data;
2883
+ return `${before}<i18n>
2884
+ ${JSON.stringify(i18n, null, 2)}
2885
+ </i18n>${after}`;
2886
+ }
2887
+ });
2888
+ }
2889
+ function parseVueFile(input2) {
2890
+ const [, before, jsonString = "{}", after] = input2.match(/^([\s\S]*)<i18n>([\s\S]*)<\/i18n>([\s\S]*)$/) || [];
2891
+ let i18n;
2892
+ try {
2893
+ i18n = JSON.parse(jsonString);
2894
+ } catch (error) {
2895
+ i18n = JSON.parse(jsonrepair2(jsonString));
2896
+ }
2897
+ return { before, after, i18n };
2898
+ }
2899
+
2862
2900
  // src/cli/loaders/index.ts
2863
2901
  function createBucketLoader(bucketType, bucketPathPattern, options) {
2864
2902
  switch (bucketType) {
@@ -3021,6 +3059,14 @@ function createBucketLoader(bucketType, bucketPathPattern, options) {
3021
3059
  createFlatLoader(),
3022
3060
  createUnlocalizableLoader(options.isCacheRestore)
3023
3061
  );
3062
+ case "vue-json":
3063
+ return composeLoaders(
3064
+ createTextFileLoader(bucketPathPattern),
3065
+ createVueJsonLoader(),
3066
+ createSyncLoader(),
3067
+ createFlatLoader(),
3068
+ createUnlocalizableLoader()
3069
+ );
3024
3070
  }
3025
3071
  }
3026
3072
 
@@ -3784,7 +3830,7 @@ var mcp_default = new Command9().command("mcp").description("Use Lingo.dev model
3784
3830
  // package.json
3785
3831
  var package_default = {
3786
3832
  name: "lingo.dev",
3787
- version: "0.78.0",
3833
+ version: "0.78.2",
3788
3834
  description: "Lingo.dev CLI",
3789
3835
  private: false,
3790
3836
  publishConfig: {