lingo.dev 0.75.0 → 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
@@ -303,24 +303,31 @@ function findLocaleFilesWithExtension(ext) {
303
303
  const files = glob.sync(`**/*${ext}`, {
304
304
  ignore: ["node_modules/**", "package*.json", "i18n.json", "lingo.json"]
305
305
  });
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
+ const localeFilePattern = new RegExp(`/([a-z]{2}(-[A-Z]{2})?)${ext}$`);
307
+ const localeDirectoryPattern = new RegExp(`/([a-z]{2}(-[A-Z]{2})?)/[^/]+${ext}$`);
308
308
  const potentialLocaleFiles = files.filter(
309
309
  (file) => localeFilePattern.test(file) || localeDirectoryPattern.test(file)
310
310
  );
311
- const localeFilesAndPatterns = potentialLocaleFiles.map((file) => {
312
- const match = file.match(new RegExp(`[/|\\\\]([a-z]{2}(-[A-Z]{2})?)(/|\\\\|${ext})`));
313
- const locale = match?.[1];
314
- const localeInDir = match?.[3] !== ext;
315
- const filePattern = localeInDir ? file.replace(`/${locale}/`, `/[locale]/`) : path3.join(path3.dirname(file), `[locale]${ext}`);
316
- return { file, locale, pattern: filePattern };
317
- }).filter(({ locale }) => {
318
- try {
319
- resolveLocaleCode(locale);
320
- return true;
321
- } 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
+ }
322
324
  }
323
- 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 };
324
331
  });
325
332
  const grouppedFilesAndPatterns = _2.groupBy(localeFilesAndPatterns, "pattern");
326
333
  const patterns = Object.keys(grouppedFilesAndPatterns);
@@ -519,6 +526,8 @@ var init_default = new InteractiveCommand().command("init").description("Initial
519
526
  });
520
527
  } else {
521
528
  spinner.succeed("No existing locale files found.");
529
+ }
530
+ if (selectedPatterns.length === 0) {
522
531
  const useDefault = await confirm({
523
532
  message: `Use (and create) default path ${patterns.join(", ")}?`
524
533
  });
@@ -3511,7 +3520,7 @@ function displaySummary(results) {
3511
3520
  // package.json
3512
3521
  var package_default = {
3513
3522
  name: "lingo.dev",
3514
- version: "0.75.0",
3523
+ version: "0.75.1",
3515
3524
  description: "Lingo.dev CLI",
3516
3525
  private: false,
3517
3526
  publishConfig: {