langsys-js-typescript 0.2.1 → 0.2.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/dist/index.mjs CHANGED
@@ -440,6 +440,18 @@ var Translations = class {
440
440
  this.debug.log(`SSR environment detected - using '${strategy}' token strategy`);
441
441
  }
442
442
  }
443
+ /**
444
+ * Record that a locale's catalog is already present without fetching —
445
+ * e.g. after an SSR handoff seeds `sTranslations` + `currentlyLoadedLocale`.
446
+ * This primes the same `lastLoaded` cache `change()` consults, so the first
447
+ * settle for that locale is a cache hit (no redundant fetch) while every
448
+ * later switch *to* it still flows through `change()` normally.
449
+ */
450
+ markLoaded(locale) {
451
+ if (!locale) return;
452
+ this.locale = locale;
453
+ this.lastLoaded[locale] = (/* @__PURE__ */ new Date()).getTime() / 1e3;
454
+ }
443
455
  /**
444
456
  * React to a user-locale change. Fetches translations if we haven't
445
457
  * loaded this locale within the last 60s (or if forced).
@@ -654,12 +666,14 @@ var LangsysAppClass = class {
654
666
  this.debug.log("Populated sTranslations with initial data for locale:", initialTranslationsLocale);
655
667
  }
656
668
  this.Translations.setup(this.config);
669
+ if (initialTranslations2 && initialTranslationsLocale) {
670
+ this.Translations.markLoaded(initialTranslationsLocale);
671
+ }
657
672
  this.config.sUserLocale.subscribe((locale) => {
658
673
  if (!validateResponse.status) return;
659
674
  this.getLocalesData(locale);
660
675
  this.debug.log("SUBSCRIBING TO USER LOCALE STORE");
661
- const skipFetch = initialTranslationsLocale === locale && !!initialTranslations2;
662
- this.translationsLoadingPromise = this.Translations.change(locale, false, skipFetch);
676
+ this.translationsLoadingPromise = this.Translations.change(locale, false);
663
677
  });
664
678
  return validateResponse;
665
679
  }