gt-react 10.19.16 → 10.19.17

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/macros.mjs CHANGED
@@ -28,7 +28,46 @@ var __copyProps = (to, from, except, desc) => {
28
28
  };
29
29
  var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
30
  //#endregion
31
- //#region ../core/dist/base64-CWITCfhU.mjs
31
+ //#region ../core/dist/base64-r7YWJYWt.mjs
32
+ function ensureSentence(text) {
33
+ const trimmed = text.trim();
34
+ if (!trimmed) return "";
35
+ return /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;
36
+ }
37
+ function stripSentence(text) {
38
+ const trimmed = text.trim();
39
+ let end = trimmed.length;
40
+ while (end > 0) {
41
+ const char = trimmed[end - 1];
42
+ if (char !== "." && char !== "!" && char !== "?") break;
43
+ end -= 1;
44
+ }
45
+ return trimmed.slice(0, end);
46
+ }
47
+ function lowercaseFirstWord(text) {
48
+ return text.replace(/^[A-Z][a-z]/, (match) => match.toLowerCase());
49
+ }
50
+ function formatDetails(details) {
51
+ if (!details) return "";
52
+ const detailText = Array.isArray(details) ? details.join(", ") : details;
53
+ if (!detailText.trim()) return "";
54
+ return ensureSentence(`Details: ${detailText}`);
55
+ }
56
+ function createDiagnosticMessage({ source, severity, whatHappened, reassurance, why, fix, wayOut, details, docsUrl }) {
57
+ const prefix = source ? severity ? `${source} ${severity}:` : `${source}:` : severity ? `${severity}:` : "";
58
+ const whatAndWhy = why ? `${stripSentence(whatHappened)} because ${lowercaseFirstWord(stripSentence(why))}` : whatHappened;
59
+ const shouldCombineWayOut = !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));
60
+ const messageParts = [
61
+ whatAndWhy,
62
+ reassurance,
63
+ shouldCombineWayOut ? `${stripSentence(fix)}, or ${lowercaseFirstWord(stripSentence(wayOut))}` : fix,
64
+ shouldCombineWayOut ? void 0 : wayOut,
65
+ formatDetails(details)
66
+ ].filter((part) => !!part).map(ensureSentence);
67
+ if (docsUrl) messageParts.push(`Learn more: ${docsUrl}`);
68
+ const message = messageParts.join(" ");
69
+ return prefix ? `${prefix} ${message}` : message;
70
+ }
32
71
  const defaultCacheUrl = "https://cdn.gtx.dev";
33
72
  //#endregion
34
73
  //#region ../core/dist/isVariable-fAKEB7gF.mjs
@@ -4303,7 +4342,7 @@ function sanitizeJsxChildren(childrenAsObjects) {
4303
4342
  return Array.isArray(childrenAsObjects) ? childrenAsObjects.map(sanitizeChild) : sanitizeChild(childrenAsObjects);
4304
4343
  }
4305
4344
  //#endregion
4306
- //#region ../i18n/dist/versionId-B2xfz6jP.mjs
4345
+ //#region ../i18n/dist/versionId-BkJZGHXr.mjs
4307
4346
  /**
4308
4347
  * Throw errors if there are any errors and log warnings if there are any warnings
4309
4348
  * @param {ValidationResult[]} results - The results to print
@@ -4349,9 +4388,9 @@ function getLoadTranslationsType(config) {
4349
4388
  * Requirements:
4350
4389
  * - REMOTE:
4351
4390
  * - GT_REMOTE:
4352
- * - projectId is required
4391
+ * - projectId is needed
4353
4392
  * - CUSTOM:
4354
- * - loadTranslations is required
4393
+ * - loadTranslations is needed
4355
4394
  * - DISABLED:
4356
4395
  * - no requirements
4357
4396
  */
@@ -4363,13 +4402,19 @@ function validateLoadTranslations(params) {
4363
4402
  case "gt-remote":
4364
4403
  if (!projectId) results.push({
4365
4404
  type: "warning",
4366
- message: "projectId is required when loading translations from a remote store"
4405
+ message: createDiagnosticMessage({
4406
+ whatHappened: "Loading translations from a remote store needs a projectId",
4407
+ fix: "Add projectId to the I18nManager config or disable remote translation loading"
4408
+ })
4367
4409
  });
4368
4410
  break;
4369
4411
  case "custom":
4370
4412
  if (!loadTranslations) results.push({
4371
4413
  type: "error",
4372
- message: "loadTranslations is required when loading translations from a custom loader"
4414
+ message: createDiagnosticMessage({
4415
+ whatHappened: "Custom translation loading needs loadTranslations",
4416
+ fix: "Provide a loadTranslations function or disable custom translation loading"
4417
+ })
4373
4418
  });
4374
4419
  break;
4375
4420
  case "disabled": break;
@@ -4382,8 +4427,9 @@ function validateLoadTranslations(params) {
4382
4427
  * @returns The runtime translation type
4383
4428
  */
4384
4429
  function getTranslationApiType(params) {
4385
- if ((params.runtimeUrl === void 0 || params.runtimeUrl === "https://runtime2.gtx.dev") && params.projectId && (params.devApiKey || params.apiKey)) return "gt";
4386
- else if (params.runtimeUrl) return "custom";
4430
+ const usesDefaultRuntimeUrl = params.runtimeUrl === void 0 || params.runtimeUrl === "https://runtime2.gtx.dev";
4431
+ if (usesDefaultRuntimeUrl && params.projectId && (params.devApiKey || params.apiKey)) return "gt";
4432
+ else if (params.runtimeUrl && !usesDefaultRuntimeUrl) return "custom";
4387
4433
  else return "disabled";
4388
4434
  }
4389
4435
  /**
@@ -4399,8 +4445,8 @@ function getTranslationApiType(params) {
4399
4445
  * Requirements:
4400
4446
  * - CUSTOM:
4401
4447
  * - GT:
4402
- * - projectId is required
4403
- * - devApiKey or apiKey is required
4448
+ * - projectId is needed
4449
+ * - devApiKey or apiKey is needed
4404
4450
  * - DISABLED:
4405
4451
  * - no requirements
4406
4452
  *
@@ -4413,11 +4459,17 @@ function validateTranslationApi(params) {
4413
4459
  case "gt":
4414
4460
  if (!params.projectId) results.push({
4415
4461
  type: "warning",
4416
- message: "projectId is required"
4462
+ message: createDiagnosticMessage({
4463
+ whatHappened: "Runtime translation needs a projectId",
4464
+ fix: "Add projectId to the I18nManager config or disable runtime translation"
4465
+ })
4417
4466
  });
4418
4467
  if (!params.devApiKey && !params.apiKey) results.push({
4419
4468
  type: "warning",
4420
- message: "devApiKey or apiKey is required"
4469
+ message: createDiagnosticMessage({
4470
+ whatHappened: "Runtime translation needs devApiKey or apiKey",
4471
+ fix: "Add credentials to the I18nManager config or disable runtime translation"
4472
+ })
4421
4473
  });
4422
4474
  break;
4423
4475
  case "disabled": break;
@@ -4446,7 +4498,10 @@ function validateLocales(params) {
4446
4498
  new Set([...defaultLocale ? [defaultLocale] : [], ...locales || []]).forEach((locale) => {
4447
4499
  if (!isValidLocale(locale, customMapping)) results.push({
4448
4500
  type: "error",
4449
- message: `Invalid locale: ${locale}`
4501
+ message: createDiagnosticMessage({
4502
+ whatHappened: `Locale "${locale}" is not valid`,
4503
+ fix: "Use a valid BCP 47 locale code or add a custom mapping"
4504
+ })
4450
4505
  });
4451
4506
  });
4452
4507
  return results;
@@ -4461,7 +4516,10 @@ function validateDictionary(params) {
4461
4516
  const results = [];
4462
4517
  if (params.loadDictionary && !params.dictionary) results.push({
4463
4518
  type: "error",
4464
- message: "dictionary is required when loadDictionary is provided"
4519
+ message: createDiagnosticMessage({
4520
+ whatHappened: "loadDictionary needs a source dictionary",
4521
+ fix: "Provide dictionary so the default locale has source content"
4522
+ })
4465
4523
  });
4466
4524
  return results;
4467
4525
  }
@@ -5731,7 +5789,7 @@ var I18nManager = class extends EventEmitter {
5731
5789
  }
5732
5790
  resolveLocale(locale) {
5733
5791
  const resolvedLocale = this.localeConfig.determineLocale(locale);
5734
- if (!this.localeConfig.isValidLocale(locale) || !resolvedLocale) throw new Error(`I18nManager: validateLocale(): locale ${locale} is not valid`);
5792
+ if (!this.localeConfig.isValidLocale(locale) || !resolvedLocale) throw new Error(`Locale "${locale}" is not valid. Use a valid BCP 47 locale code or add a custom mapping.`);
5735
5793
  return resolvedLocale;
5736
5794
  }
5737
5795
  /**
@@ -5778,7 +5836,7 @@ var I18nManager = class extends EventEmitter {
5778
5836
  */
5779
5837
  async dictionaryRuntimeTranslate(locale, id, sourceEntry) {
5780
5838
  const translation = await this.lookupTranslationWithFallbackResolved(locale, sourceEntry.entry, resolveDictionaryLookupOptions(sourceEntry.options));
5781
- if (typeof translation !== "string") throw new Error(`I18nManager: dictionaryRuntimeTranslate(): unable to translate dictionary entry ${id}`);
5839
+ if (typeof translation !== "string") throw new Error(`Dictionary entry "${id}" could not be translated into a string. Check the source entry and translation loader output.`);
5782
5840
  return translation;
5783
5841
  }
5784
5842
  /**
@@ -5910,7 +5968,7 @@ let conditionStore = { getLocale: () => fallbackDefaultLocale };
5910
5968
  */
5911
5969
  function getI18nManager() {
5912
5970
  if (!i18nManager) {
5913
- logger_default.warn("getI18nManager(): Translation failed because I18nManager not initialized.");
5971
+ logger_default.warn("getI18nManager(): I18nManager was not initialized. Falling back to the default locale until initializeGT() configures translations.");
5914
5972
  i18nManager = new I18nManager({
5915
5973
  defaultLocale: "en",
5916
5974
  locales: ["en"]
@@ -6042,10 +6100,30 @@ function resolveTranslationSyncWithFallback(locale, message, options = {}) {
6042
6100
  //#endregion
6043
6101
  //#region src/shared/messages.ts
6044
6102
  const PACKAGE_NAME = "gt-react";
6045
- `${PACKAGE_NAME}${PACKAGE_NAME}`;
6046
- `${PACKAGE_NAME}`;
6047
- `${PACKAGE_NAME}`;
6048
- const createTranslationFailedDueToBrowserEnvironmentWarning = (message) => `${PACKAGE_NAME} Warning: Translation failed for t("${typeof message === "string" ? message : "`" + message?.join("${}") + "`"}") because it was used outside of a browser environment. Falling back to original message.`;
6103
+ createDiagnosticMessage({
6104
+ source: `${PACKAGE_NAME}/browser`,
6105
+ severity: "Error",
6106
+ whatHappened: "This module requires a browser environment",
6107
+ fix: "Import it only from client-side code"
6108
+ });
6109
+ createDiagnosticMessage({
6110
+ source: PACKAGE_NAME,
6111
+ severity: "Error",
6112
+ whatHappened: "A browser-only module was imported outside the browser",
6113
+ fix: "Move this import to client-side code"
6114
+ });
6115
+ createDiagnosticMessage({
6116
+ source: PACKAGE_NAME,
6117
+ severity: "Error",
6118
+ whatHappened: "BrowserI18nManager is not initialized",
6119
+ fix: "Call initializeGT() before using browser translation APIs"
6120
+ });
6121
+ const createTranslationFailedDueToBrowserEnvironmentWarning = (message) => createDiagnosticMessage({
6122
+ source: PACKAGE_NAME,
6123
+ severity: "Warning",
6124
+ whatHappened: `t("${typeof message === "string" ? message : "`" + message?.join("${}") + "`"}") could not be translated because it ran outside the browser`,
6125
+ wayOut: "The original message will render as a fallback"
6126
+ });
6049
6127
  //#endregion
6050
6128
  //#region src/i18n-context/functions/translation/t.ts
6051
6129
  /**
@@ -6091,7 +6169,7 @@ const t = (messageOrStrings, ...values) => {
6091
6169
  */
6092
6170
  function handleTaggedTemplateLiteralTranslation(messageOrStrings, values) {
6093
6171
  const locale = getLocale();
6094
- const translatedInterpolatedTemplate = resolveTranslationSync(locale, interpolateTemplateLiteral(messageOrStrings, values));
6172
+ const translatedInterpolatedTemplate = resolveTranslationSync(locale, messageOrStrings.map((string, index) => string + (values[index] ?? "")).join(""));
6095
6173
  if (translatedInterpolatedTemplate) return translatedInterpolatedTemplate;
6096
6174
  const { message, variables } = extractInterpolatableValues(messageOrStrings, values);
6097
6175
  return resolveTranslationSyncWithFallback(locale, message, variables);
@@ -6120,17 +6198,6 @@ function extractInterpolatableValues(strings, values) {
6120
6198
  variables
6121
6199
  };
6122
6200
  }
6123
- /**
6124
- * Interpolate a template literal
6125
- * @param message - The message to interpolate.
6126
- * @param variables - The variables to interpolate.
6127
- * @returns The interpolated message.
6128
- */
6129
- function interpolateTemplateLiteral(strings, values) {
6130
- return strings.map((string, index) => {
6131
- return string + (values[index] ?? "");
6132
- }).join("");
6133
- }
6134
6201
  //#endregion
6135
6202
  //#region src/macros.ts
6136
6203
  globalThis.t = t;