gt-react 11.0.0-odysseus.4 → 11.0.0

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.
@@ -201,7 +201,7 @@ function deleteExpiredEntries(cache, now = Date.now()) {
201
201
  for (const key of Object.keys(cache)) if (cache[key].exp <= now) delete cache[key];
202
202
  }
203
203
  //#endregion
204
- //#region ../core/dist/base64-r7YWJYWt.mjs
204
+ //#region ../core/dist/api-BOEGbEF6.mjs
205
205
  function ensureSentence(text) {
206
206
  const trimmed = text.trim();
207
207
  if (!trimmed) return "";
@@ -265,7 +265,7 @@ var BrowserI18nCache = class extends gt_i18n_internal.I18nCache {
265
265
  ...DEFAULT_HTML_TAG_OPTIONS,
266
266
  ...htmlTagOptions
267
267
  };
268
- if (devHotReloadEnabled) this.subscribe("translations-cache-miss", ({ locale, hash, translation }) => {
268
+ if (devHotReloadEnabled) this.onTranslationsCacheMiss = ({ locale, hash, translation }) => {
269
269
  const cache = localStorageCaches[locale];
270
270
  if (cache) cache.write(hash, translation);
271
271
  else localStorageCaches[locale] = new LocalStorageTranslationCache({
@@ -273,7 +273,7 @@ var BrowserI18nCache = class extends gt_i18n_internal.I18nCache {
273
273
  projectId,
274
274
  init: { [hash]: translation }
275
275
  });
276
- });
276
+ };
277
277
  }
278
278
  /**
279
279
  * Whether dev hot reload JSX (Suspense-based <T>) is active
@@ -287,7 +287,7 @@ var BrowserI18nCache = class extends gt_i18n_internal.I18nCache {
287
287
  * Returns undefined if not in development mode.
288
288
  */
289
289
  getLocalStorageTranslationCache(locale, init) {
290
- if (!{}?.DEV) return void 0;
290
+ if ((0, gt_i18n_internal.getRuntimeEnvironment)() !== "development") return void 0;
291
291
  if (!this._localStorageCaches[locale]) this._localStorageCaches[locale] = new LocalStorageTranslationCache({
292
292
  locale,
293
293
  projectId: this.config.projectId,
@@ -375,27 +375,6 @@ function readBrowserLocale(localeCookieName) {
375
375
  return candidates;
376
376
  }
377
377
  //#endregion
378
- //#region src/cookie-names.ts
379
- /**
380
- * Cookie name for tracking the user's selected locale.
381
- */
382
- const defaultLocaleCookieName = "generaltranslation.locale";
383
- /**
384
- * Cookie name for tracking the user's selected region.
385
- */
386
- const defaultRegionCookieName = "generaltranslation.region";
387
- /**
388
- * Cookie name for persisting the enableI18n feature flag.
389
- */
390
- const defaultEnableI18nCookieName = "generaltranslation.enable-i18n";
391
- /**
392
- * Cookie name for tracking the locale reset
393
- * Used by gt-next middleware
394
- *
395
- * TODO: remove this cookie when come up with better solution
396
- */
397
- const defaultResetLocaleCookieName = "generaltranslation.locale-reset";
398
- //#endregion
399
378
  //#region src/condition-store/BrowserConditionStore.ts
400
379
  /**
401
380
  * Condition store implementation for Browser.
@@ -403,18 +382,18 @@ const defaultResetLocaleCookieName = "generaltranslation.locale-reset";
403
382
  var BrowserConditionStore = class {
404
383
  constructor(config) {
405
384
  this.getLocale = () => {
406
- return getBrowserLocale(this.localeCookieName, this.customGetLocale);
385
+ return getBrowserLocale(this.customGetLocale);
407
386
  };
408
387
  this.setLocale = (locale) => {
409
388
  this.updateLocale(locale);
410
389
  setCookieValue({
411
- cookieName: defaultResetLocaleCookieName,
390
+ cookieName: _generaltranslation_react_core_pure.defaultResetLocaleCookieName,
412
391
  value: "true"
413
392
  });
414
393
  this.reload();
415
394
  };
416
395
  this.getRegion = () => {
417
- const cookieRegion = getCookieValue({ cookieName: this.regionCookieName });
396
+ const cookieRegion = getCookieValue({ cookieName: (0, _generaltranslation_react_core_pure.getI18nConfig)().getRegionCookieName() });
418
397
  if (cookieRegion) return cookieRegion;
419
398
  return this.customGetRegion?.();
420
399
  };
@@ -423,7 +402,7 @@ var BrowserConditionStore = class {
423
402
  this.reload();
424
403
  };
425
404
  this.getEnableI18n = () => {
426
- const cookieEnableI18n = getCookieValue({ cookieName: this.enableI18nCookieName });
405
+ const cookieEnableI18n = getCookieValue({ cookieName: (0, _generaltranslation_react_core_pure.getI18nConfig)().getEnableI18nCookieName() });
427
406
  if (cookieEnableI18n === void 0) return this.customGetEnableI18n?.() ?? true;
428
407
  return cookieEnableI18n === "true";
429
408
  };
@@ -432,21 +411,21 @@ var BrowserConditionStore = class {
432
411
  this.reload();
433
412
  };
434
413
  this.updateLocale = (locale) => {
435
- const i18nConfig = (0, gt_i18n_internal.getI18nConfig)();
414
+ const i18nConfig = (0, _generaltranslation_react_core_pure.getI18nConfig)();
436
415
  setCookieValue({
437
- cookieName: this.localeCookieName,
438
- value: i18nConfig.determineLocale(locale) || i18nConfig.getDefaultLocale()
416
+ cookieName: i18nConfig.getLocaleCookieName(),
417
+ value: i18nConfig.resolveSupportedLocale(locale)
439
418
  });
440
419
  };
441
420
  this.updateRegion = (region) => {
442
421
  setCookieValue({
443
- cookieName: this.regionCookieName,
422
+ cookieName: (0, _generaltranslation_react_core_pure.getI18nConfig)().getRegionCookieName(),
444
423
  value: region ?? ""
445
424
  });
446
425
  };
447
426
  this.updateEnableI18n = (enableI18n) => {
448
427
  setCookieValue({
449
- cookieName: this.enableI18nCookieName,
428
+ cookieName: (0, _generaltranslation_react_core_pure.getI18nConfig)().getEnableI18nCookieName(),
450
429
  value: enableI18n ? "true" : "false"
451
430
  });
452
431
  };
@@ -458,35 +437,39 @@ var BrowserConditionStore = class {
458
437
  };
459
438
  this.customReload(state);
460
439
  };
440
+ const i18nConfig = (0, _generaltranslation_react_core_pure.getI18nConfig)();
461
441
  this.customReload = config._reload ?? (() => typeof window !== "undefined" ? window.location.reload() : void 0);
462
442
  this.customGetLocale = config._getLocale;
463
443
  this.customGetRegion = config._getRegion;
464
444
  this.customGetEnableI18n = config._getEnableI18n;
465
- this.localeCookieName = config.localeCookieName ?? "generaltranslation.locale";
466
- this.regionCookieName = config.regionCookieName ?? "generaltranslation.region";
467
- this.enableI18nCookieName = config.enableI18nCookieName ?? "generaltranslation.enable-i18n";
468
- const i18nConfig = (0, gt_i18n_internal.getI18nConfig)();
469
445
  setCookieValue({
470
- cookieName: this.localeCookieName,
471
- value: i18nConfig.determineLocale(config.locale) || i18nConfig.getDefaultLocale()
446
+ cookieName: i18nConfig.getLocaleCookieName(),
447
+ value: i18nConfig.resolveSupportedLocale(config.locale)
472
448
  });
473
449
  if (config.region !== void 0) setCookieValue({
474
- cookieName: this.regionCookieName,
450
+ cookieName: i18nConfig.getRegionCookieName(),
475
451
  value: config.region
476
452
  });
477
453
  this.updateEnableI18n(config.enableI18n ?? true);
478
454
  }
479
455
  };
480
- function getBrowserLocale(cookieName, getLocale) {
481
- const candidates = readBrowserLocale(cookieName);
456
+ function getBrowserLocale(getLocale) {
457
+ const i18nConfig = (0, _generaltranslation_react_core_pure.getI18nConfig)();
458
+ const candidates = readBrowserLocale(i18nConfig.getLocaleCookieName());
482
459
  if (getLocale) candidates.push(getLocale());
483
- const i18nConfig = (0, gt_i18n_internal.getI18nConfig)();
484
- return i18nConfig.determineLocale(candidates) || i18nConfig.getDefaultLocale();
460
+ return i18nConfig.resolveSupportedLocale(candidates);
485
461
  }
486
462
  //#endregion
487
463
  //#region src/condition-store/singleton-operations.ts
488
- const { setConditionStore: setReadonlyConditionStore, isConditionStoreInitialized: isReadonlyConditionStoreInitialized } = (0, gt_i18n_internal.createConditionStoreSingleton)("ReadonlyConditionStore is not initialized.");
489
- const { getConditionStore: getBrowserConditionStore, setConditionStore: setBrowserConditionStore, isConditionStoreInitialized: isBrowserConditionStoreInitialized } = (0, gt_i18n_internal.createConditionStoreSingleton)("BrowserConditionStore is not initialized.");
464
+ const conditionStoreNotInitializedError = createDiagnosticMessage({
465
+ source: "gt-react",
466
+ severity: "Error",
467
+ whatHappened: "Cannot read GT runtime context before it has been initialized",
468
+ why: "the internal ConditionStore singleton is unavailable",
469
+ fix: "Call initializeGT() (or initializeGTSPA() in SPA apps) before rendering and add a <GTProvider> at the root of your component tree."
470
+ });
471
+ const { setConditionStore: setReadonlyConditionStore, isConditionStoreInitialized: isReadonlyConditionStoreInitialized } = (0, gt_i18n_internal.createConditionStoreSingleton)(conditionStoreNotInitializedError);
472
+ const { getConditionStore: getBrowserConditionStore, setConditionStore: setBrowserConditionStore, isConditionStoreInitialized: isBrowserConditionStoreInitialized } = (0, gt_i18n_internal.createConditionStoreSingleton)(conditionStoreNotInitializedError);
490
473
  //#endregion
491
474
  //#region src/condition-store/createBrowserConditionStore.ts
492
475
  /**
@@ -494,8 +477,11 @@ const { getConditionStore: getBrowserConditionStore, setConditionStore: setBrows
494
477
  *
495
478
  * This exists so we can keep the locale param as required in the constructor
496
479
  *
497
- * We want the values that we read from the cookies to override as this
498
- * persists state across page reloads
480
+ * Server-provided props are the first candidates for hydration consistency.
481
+ * Cookies fill in missing values to persist state across page reloads.
482
+ *
483
+ * Cookie names come from the I18nConfig singleton so custom names passed to
484
+ * initializeGT() apply here without being threaded through provider props.
499
485
  */
500
486
  function createOrUpdateBrowserConditionStore(config) {
501
487
  const locale = determineLocale(config);
@@ -510,9 +496,6 @@ function createOrUpdateBrowserConditionStore(config) {
510
496
  }
511
497
  const conditionStore = new BrowserConditionStore({
512
498
  ...config,
513
- localeCookieName: defaultLocaleCookieName,
514
- regionCookieName: defaultRegionCookieName,
515
- enableI18nCookieName: defaultEnableI18nCookieName,
516
499
  locale,
517
500
  region,
518
501
  enableI18n
@@ -520,26 +503,64 @@ function createOrUpdateBrowserConditionStore(config) {
520
503
  setBrowserConditionStore(conditionStore);
521
504
  return conditionStore;
522
505
  }
523
- function determineLocale({ localeCookieName = defaultLocaleCookieName, _getLocale: getLocale, locale }) {
506
+ function determineLocale({ _getLocale: getLocale, locale }) {
507
+ const i18nConfig = (0, _generaltranslation_react_core_pure.getI18nConfig)();
524
508
  const candidates = [];
525
509
  if (locale) candidates.push(...Array.isArray(locale) ? locale : [locale]);
526
510
  if (getLocale) candidates.push(getLocale());
527
- candidates.push(...readBrowserLocale(localeCookieName));
528
- return resolveLocale(candidates);
511
+ candidates.push(...readBrowserLocale(i18nConfig.getLocaleCookieName()));
512
+ return i18nConfig.resolveSupportedLocale(candidates);
529
513
  }
530
- function resolveLocale(candidates) {
531
- const i18nConfig = (0, gt_i18n_internal.getI18nConfig)();
532
- return i18nConfig.determineLocale(candidates) || i18nConfig.getDefaultLocale();
514
+ function determineRegion({ _getRegion: getRegion, region }) {
515
+ return getCookieValue({ cookieName: (0, _generaltranslation_react_core_pure.getI18nConfig)().getRegionCookieName() }) || getRegion?.() || region;
533
516
  }
534
- function determineRegion({ regionCookieName = defaultRegionCookieName, _getRegion: getRegion, region }) {
535
- return getCookieValue({ cookieName: regionCookieName }) || getRegion?.() || region;
536
- }
537
- function determineEnableI18n({ enableI18n, enableI18nCookieName = defaultEnableI18nCookieName, _getEnableI18n: getEnableI18n }) {
538
- const cookieEnableI18n = getCookieValue({ cookieName: enableI18nCookieName });
539
- if (cookieEnableI18n === void 0) return getEnableI18n?.() ?? enableI18n ?? true;
517
+ function determineEnableI18n({ enableI18n, _getEnableI18n: getEnableI18n }) {
518
+ if (enableI18n !== void 0) return enableI18n;
519
+ const cookieEnableI18n = getCookieValue({ cookieName: (0, _generaltranslation_react_core_pure.getI18nConfig)().getEnableI18nCookieName() });
520
+ if (cookieEnableI18n === void 0) return getEnableI18n?.() ?? true;
540
521
  return cookieEnableI18n === "true";
541
522
  }
542
523
  //#endregion
524
+ //#region src/setup/runtimeCredentials.ts
525
+ function addRuntimeCredentials(config) {
526
+ const credentials = getRuntimeCredentials();
527
+ return {
528
+ ...config,
529
+ projectId: config.projectId || credentials.projectId,
530
+ devApiKey: config.devApiKey || credentials.devApiKey
531
+ };
532
+ }
533
+ function getRuntimeCredentials() {
534
+ return {
535
+ projectId: readImportMetaVite(() => ({}).env?.VITE_GT_PROJECT_ID) || readProcessEnvViteProjectId(),
536
+ devApiKey: (0, gt_i18n_internal.getRuntimeEnvironment)() === "development" ? readImportMetaVite(() => ({}).env?.DEV ? {}.env?.VITE_GT_DEV_API_KEY : void 0) || readProcessEnvViteDevApiKey() : void 0
537
+ };
538
+ }
539
+ function readImportMetaVite(readValue) {
540
+ try {
541
+ return normalizeEnvValue(readValue());
542
+ } catch {
543
+ return;
544
+ }
545
+ }
546
+ function readProcessEnvViteProjectId() {
547
+ try {
548
+ return normalizeEnvValue(process.env.VITE_GT_PROJECT_ID);
549
+ } catch {
550
+ return;
551
+ }
552
+ }
553
+ function readProcessEnvViteDevApiKey() {
554
+ try {
555
+ return normalizeEnvValue(process.env.VITE_GT_DEV_API_KEY);
556
+ } catch {
557
+ return;
558
+ }
559
+ }
560
+ function normalizeEnvValue(value) {
561
+ return value || void 0;
562
+ }
563
+ //#endregion
543
564
  //#region src/setup/initializeGTSPA.ts
544
565
  /**
545
566
  * Initialize GT for an SPA
@@ -550,12 +571,23 @@ function determineEnableI18n({ enableI18n, enableI18nCookieName = defaultEnableI
550
571
  * This is SPA for browser runtime
551
572
  */
552
573
  async function initializeGTSPA(config) {
553
- (0, gt_i18n_internal.setupGTServicesEnabled)(config);
554
- (0, _generaltranslation_react_core_pure.initializeI18nConfig)(config, "SPA");
555
- (0, _generaltranslation_react_core_pure.setReactI18nCache)(new BrowserI18nCache(config));
556
- createOrUpdateBrowserConditionStore(config);
574
+ const runtimeConfig = addRuntimeCredentials(config);
575
+ (0, _generaltranslation_react_core_pure.initializeI18nConfig)(runtimeConfig, "SPA");
576
+ (0, _generaltranslation_react_core_pure.setReactI18nCache)(new BrowserI18nCache(runtimeConfig));
577
+ createOrUpdateBrowserConditionStore(runtimeConfig);
557
578
  (0, _generaltranslation_react_core_pure.setI18nStore)(new _generaltranslation_react_core_pure.I18nStore());
558
- await (0, _generaltranslation_react_core_pure.getTranslationsSnapshot)((0, _generaltranslation_react_core_pure.getReadonlyConditionStoreWithFallback)().getLocale());
579
+ await (0, _generaltranslation_react_core_pure.getTranslationsSnapshot)((0, _generaltranslation_react_core_pure.getReadonlyConditionStore)().getLocale());
580
+ }
581
+ //#endregion
582
+ //#region src/setup/initializeGTSRAClient.ts
583
+ /**
584
+ * Initialize GT for client-side rendering.
585
+ */
586
+ function initializeGTSRAClient(config) {
587
+ (0, _generaltranslation_react_core_pure.internalInitializeGTSRA)(addRuntimeCredentials({
588
+ cacheExpiryTime: null,
589
+ ...config
590
+ }));
559
591
  }
560
592
  //#endregion
561
593
  //#region src/hooks/conditions-store.ts
@@ -842,9 +874,6 @@ Object.defineProperty(exports, "decodeVars", {
842
874
  return _generaltranslation_react_core_pure.decodeVars;
843
875
  }
844
876
  });
845
- exports.defaultEnableI18nCookieName = defaultEnableI18nCookieName;
846
- exports.defaultLocaleCookieName = defaultLocaleCookieName;
847
- exports.defaultRegionCookieName = defaultRegionCookieName;
848
877
  Object.defineProperty(exports, "derive", {
849
878
  enumerable: true,
850
879
  get: function() {
@@ -863,12 +892,6 @@ Object.defineProperty(exports, "getFormatLocales", {
863
892
  return _generaltranslation_react_core_pure.getFormatLocales;
864
893
  }
865
894
  });
866
- Object.defineProperty(exports, "getGTClass", {
867
- enumerable: true,
868
- get: function() {
869
- return _generaltranslation_react_core_pure.getGTClass;
870
- }
871
- });
872
895
  Object.defineProperty(exports, "getLocaleProperties", {
873
896
  enumerable: true,
874
897
  get: function() {
@@ -905,12 +928,7 @@ Object.defineProperty(exports, "gtFallback", {
905
928
  return _generaltranslation_react_core_pure.gtFallback;
906
929
  }
907
930
  });
908
- Object.defineProperty(exports, "initializeGT", {
909
- enumerable: true,
910
- get: function() {
911
- return _generaltranslation_react_core_pure.initializeGT;
912
- }
913
- });
931
+ exports.initializeGT = initializeGTSRAClient;
914
932
  exports.initializeGTSPA = initializeGTSPA;
915
933
  Object.defineProperty(exports, "mFallback", {
916
934
  enumerable: true,
@@ -924,6 +942,12 @@ Object.defineProperty(exports, "msg", {
924
942
  return _generaltranslation_react_core_pure.msg;
925
943
  }
926
944
  });
945
+ Object.defineProperty(exports, "resolveCanonicalLocale", {
946
+ enumerable: true,
947
+ get: function() {
948
+ return _generaltranslation_react_core_pure.resolveCanonicalLocale;
949
+ }
950
+ });
927
951
  Object.defineProperty(exports, "setReactI18nCache", {
928
952
  enumerable: true,
929
953
  get: function() {
@@ -966,12 +990,6 @@ Object.defineProperty(exports, "useGT", {
966
990
  return _generaltranslation_react_core_hooks.useGT;
967
991
  }
968
992
  });
969
- Object.defineProperty(exports, "useGTClass", {
970
- enumerable: true,
971
- get: function() {
972
- return _generaltranslation_react_core_hooks.useGTClass;
973
- }
974
- });
975
993
  Object.defineProperty(exports, "useLocale", {
976
994
  enumerable: true,
977
995
  get: function() {
@@ -1019,11 +1037,5 @@ Object.defineProperty(exports, "useTranslations", {
1019
1037
  return _generaltranslation_react_core_hooks.useTranslations;
1020
1038
  }
1021
1039
  });
1022
- Object.defineProperty(exports, "useVersionId", {
1023
- enumerable: true,
1024
- get: function() {
1025
- return _generaltranslation_react_core_hooks.useVersionId;
1026
- }
1027
- });
1028
1040
 
1029
1041
  //# sourceMappingURL=index.client.cjs.map