gt-i18n 1.0.16 → 1.0.18

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/{DictionaryCache-DjAdDNiM.d.cts → DictionaryCache-B7XwB7Al.d.cts} +1 -1
  3. package/dist/{DictionaryCache-B7oTBs5W.d.mts → DictionaryCache-D2X-D5Km.d.mts} +2 -2
  4. package/dist/{WritableConditionStore-B0Ly3KFF.d.mts → WritableConditionStore-CXSAqNf8.d.cts} +4 -4
  5. package/dist/{WritableConditionStore-Bn55y9M5.d.cts → WritableConditionStore-DwBYQYJK.d.mts} +4 -4
  6. package/dist/decodeOptions-BeDpvpRG.d.mts +12 -0
  7. package/dist/decodeOptions-DEMOo8JG.d.cts +12 -0
  8. package/dist/{functions-BZ_xopQU.d.mts → functions-BlAp7Ico.d.mts} +3 -11
  9. package/dist/{functions-BiA2tWER.d.cts → functions-DY3ckTRN.d.cts} +2 -10
  10. package/dist/index.cjs +8 -6
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +5 -11
  13. package/dist/index.d.mts +5 -11
  14. package/dist/index.mjs +7 -5
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/internal-cookies.cjs +51 -0
  17. package/dist/internal-cookies.cjs.map +1 -0
  18. package/dist/internal-cookies.d.cts +35 -0
  19. package/dist/internal-cookies.d.mts +35 -0
  20. package/dist/internal-cookies.mjs +44 -0
  21. package/dist/internal-cookies.mjs.map +1 -0
  22. package/dist/internal-string.cjs +7 -0
  23. package/dist/internal-string.d.cts +32 -0
  24. package/dist/internal-string.d.mts +32 -0
  25. package/dist/internal-string.mjs +3 -0
  26. package/dist/internal-types.d.cts +2 -2
  27. package/dist/internal-types.d.mts +3 -3
  28. package/dist/internal.cjs +8 -36
  29. package/dist/internal.cjs.map +1 -1
  30. package/dist/internal.d.cts +8 -24
  31. package/dist/internal.d.mts +8 -24
  32. package/dist/internal.mjs +3 -31
  33. package/dist/internal.mjs.map +1 -1
  34. package/dist/isEncodedTranslationOptions-Bi2U2td4.d.mts +11 -0
  35. package/dist/isEncodedTranslationOptions-CmlRuckr.mjs +29 -0
  36. package/dist/isEncodedTranslationOptions-CmlRuckr.mjs.map +1 -0
  37. package/dist/isEncodedTranslationOptions-ab8RTutO.cjs +40 -0
  38. package/dist/isEncodedTranslationOptions-ab8RTutO.cjs.map +1 -0
  39. package/dist/isEncodedTranslationOptions-tCBySftT.d.cts +11 -0
  40. package/dist/message-BxBVYC3J.d.cts +10 -0
  41. package/dist/message-CYsuGTre.d.mts +10 -0
  42. package/dist/msgString-C-b5XBju.mjs +56 -0
  43. package/dist/msgString-C-b5XBju.mjs.map +1 -0
  44. package/dist/msgString-CSHG5PMt.cjs +73 -0
  45. package/dist/msgString-CSHG5PMt.cjs.map +1 -0
  46. package/dist/{options-DDUyXaLT.d.mts → options-D_Ry5muW.d.mts} +1 -1
  47. package/dist/request-B4J2mLiA.cjs +44 -0
  48. package/dist/request-B4J2mLiA.cjs.map +1 -0
  49. package/dist/request-B7giWTEv.d.cts +13 -0
  50. package/dist/request-BmknfARt.mjs +33 -0
  51. package/dist/request-BmknfARt.mjs.map +1 -0
  52. package/dist/request-Bs7NclA3.d.mts +13 -0
  53. package/dist/{types-wiJpMiR8.d.cts → types-C0RazRKy.d.cts} +2 -2
  54. package/dist/{types-CRivFf_D.d.mts → types-DzSeRi70.d.mts} +3 -3
  55. package/dist/types.d.cts +4 -3
  56. package/dist/types.d.mts +5 -4
  57. package/dist/{versionId-0COhh5UX.d.cts → versionId-BSCcbrCd.d.mts} +1 -1
  58. package/dist/{versionId-BrRvCzwH.cjs → versionId-Bd7hW7x_.cjs} +1 -38
  59. package/dist/versionId-Bd7hW7x_.cjs.map +1 -0
  60. package/dist/{versionId-Zel3fqtC.d.mts → versionId-CGNwvk_T.d.cts} +1 -1
  61. package/dist/{versionId-I8qWZjrR.mjs → versionId-DQnENeZa.mjs} +3 -28
  62. package/dist/versionId-DQnENeZa.mjs.map +1 -0
  63. package/package.json +29 -3
  64. package/dist/versionId-BrRvCzwH.cjs.map +0 -1
  65. package/dist/versionId-I8qWZjrR.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # gt-i18n
2
2
 
3
+ ## 1.0.18
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`34845f9`](https://github.com/generaltranslation/gt/commit/34845f92d64fd9c94a712e4710e8958022066b7b)]:
8
+ - generaltranslation@9.1.8
9
+
10
+ ## 1.0.17
11
+
12
+ ### Patch Changes
13
+
14
+ - [#2012](https://github.com/generaltranslation/gt/pull/2012) [`8d376e2`](https://github.com/generaltranslation/gt/commit/8d376e23c80828dfd8756e2f0fbf0f7725e0f178) Thanks [@eoinest](https://github.com/eoinest)! - Make `msg(..., { $format: 'STRING' })` preserve source text literally instead
15
+ of applying ICU interpolation. For example, `msg('Hello {name}', {
16
+ $format: 'STRING', name: 'Ada' })` now encodes `Hello {name}` rather than
17
+ `Hello Ada`. Add lightweight shared helpers for registering, hashing, and
18
+ decoding literal STRING messages, browser cookie access, and canonical GT
19
+ cookie names, and validate encoded fields by type.
20
+ - Updated dependencies [[`f2204b9`](https://github.com/generaltranslation/gt/commit/f2204b990278865c54d14d337392930ea1ec31bf), [`b05b470`](https://github.com/generaltranslation/gt/commit/b05b4703fbbfd34a3cbee335c786e2e606346167)]:
21
+ - @generaltranslation/format@0.1.8
22
+ - generaltranslation@9.1.7
23
+
24
+ ## 1.0.13-iris.0
25
+
26
+ ### Patch Changes
27
+
28
+ - 5d8b78a: Migrate the package license from FSL-1.1-ALv2 to MIT.
29
+ - Updated dependencies [f2204b9]
30
+ - Updated dependencies [b05b470]
31
+ - Updated dependencies [5d8b78a]
32
+ - @generaltranslation/format@0.1.5-iris.0
33
+ - generaltranslation@9.1.3-iris.0
34
+
35
+ ## 1.0.12-iris.0
36
+
37
+ ### Patch Changes
38
+
39
+ - 8d376e2: Make `msg(..., { $format: 'STRING' })` preserve source text literally instead
40
+ of applying ICU interpolation. For example, `msg('Hello {name}', {
41
+ $format: 'STRING', name: 'Ada' })` now encodes `Hello {name}` rather than
42
+ `Hello Ada`. Add lightweight shared helpers for registering, hashing, and
43
+ decoding literal STRING messages, browser cookie access, and canonical GT
44
+ cookie names, and validate encoded fields by type.
45
+
3
46
  ## 1.0.16
4
47
 
5
48
  ### Patch Changes
@@ -26,4 +26,4 @@ type DictionaryKey = DictionaryPath;
26
26
  type DictionaryLoader = (locale: string) => Promise<Dictionary>;
27
27
  //#endregion
28
28
  export { DictionaryLeaf as a, DictionaryValue as c, DictionaryKey as i, Translation as l, Dictionary as n, DictionaryObject as o, DictionaryEntry as r, DictionaryPath as s, DictionaryLoader as t };
29
- //# sourceMappingURL=DictionaryCache-DjAdDNiM.d.cts.map
29
+ //# sourceMappingURL=DictionaryCache-B7XwB7Al.d.cts.map
@@ -1,4 +1,4 @@
1
- import { t as DictionaryEntryOptions } from "./options-DDUyXaLT.mjs";
1
+ import { t as DictionaryEntryOptions } from "./options-D_Ry5muW.mjs";
2
2
  import { Content } from "@generaltranslation/format/types";
3
3
 
4
4
  //#region src/i18n-cache/translations-manager/utils/types/translation-data.d.ts
@@ -26,4 +26,4 @@ type DictionaryKey = DictionaryPath;
26
26
  type DictionaryLoader = (locale: string) => Promise<Dictionary>;
27
27
  //#endregion
28
28
  export { DictionaryLeaf as a, DictionaryValue as c, DictionaryKey as i, Translation as l, Dictionary as n, DictionaryObject as o, DictionaryEntry as r, DictionaryPath as s, DictionaryLoader as t };
29
- //# sourceMappingURL=DictionaryCache-B7oTBs5W.d.mts.map
29
+ //# sourceMappingURL=DictionaryCache-D2X-D5Km.d.mts.map
@@ -1,9 +1,9 @@
1
- import { n as Dictionary, t as DictionaryLoader } from "./DictionaryCache-B7oTBs5W.mjs";
1
+ import { n as Dictionary, t as DictionaryLoader } from "./DictionaryCache-B7XwB7Al.cjs";
2
+ import { CustomMapping } from "@generaltranslation/format/types";
2
3
  import { RuntimeTranslateManyOptions } from "generaltranslation/internal";
4
+ import { GTConfig } from "generaltranslation/types";
3
5
  import { LocaleConfig } from "@generaltranslation/format";
4
6
  import { GTRuntime } from "generaltranslation/runtime";
5
- import { CustomMapping } from "@generaltranslation/format/types";
6
- import { GTConfig } from "generaltranslation/types";
7
7
 
8
8
  //#region src/i18n-cache/translations-manager/TranslationsCache.d.ts
9
9
  type TranslationBatchConfig = {
@@ -187,4 +187,4 @@ declare class WritableConditionStore extends ReadonlyConditionStore implements W
187
187
  }
188
188
  //#endregion
189
189
  export { Hash as _, I18nConfig as a, AsyncReadonlyConditionStoreInterface as c, I18nCacheConstructorParams as d, LocaleResolverConfig as f, TranslationsLoader as g, WritableConditionStoreInterface as h, ReadonlyConditionStoreParams as i, DictionaryConfig as l, ScopedConditionStoreInterface as m, WritableConditionStoreParams as n, I18nConfigParams as o, ReadonlyConditionStoreInterface as p, ReadonlyConditionStore as r, LocaleCandidates as s, WritableConditionStore as t, I18nCacheConfig as u, Locale as v, GTConfig as y };
190
- //# sourceMappingURL=WritableConditionStore-B0Ly3KFF.d.mts.map
190
+ //# sourceMappingURL=WritableConditionStore-CXSAqNf8.d.cts.map
@@ -1,9 +1,9 @@
1
- import { n as Dictionary, t as DictionaryLoader } from "./DictionaryCache-DjAdDNiM.cjs";
2
- import { CustomMapping } from "@generaltranslation/format/types";
1
+ import { n as Dictionary, t as DictionaryLoader } from "./DictionaryCache-D2X-D5Km.mjs";
3
2
  import { RuntimeTranslateManyOptions } from "generaltranslation/internal";
4
- import { GTConfig } from "generaltranslation/types";
5
3
  import { LocaleConfig } from "@generaltranslation/format";
6
4
  import { GTRuntime } from "generaltranslation/runtime";
5
+ import { CustomMapping } from "@generaltranslation/format/types";
6
+ import { GTConfig } from "generaltranslation/types";
7
7
 
8
8
  //#region src/i18n-cache/translations-manager/TranslationsCache.d.ts
9
9
  type TranslationBatchConfig = {
@@ -187,4 +187,4 @@ declare class WritableConditionStore extends ReadonlyConditionStore implements W
187
187
  }
188
188
  //#endregion
189
189
  export { Hash as _, I18nConfig as a, AsyncReadonlyConditionStoreInterface as c, I18nCacheConstructorParams as d, LocaleResolverConfig as f, TranslationsLoader as g, WritableConditionStoreInterface as h, ReadonlyConditionStoreParams as i, DictionaryConfig as l, ScopedConditionStoreInterface as m, WritableConditionStoreParams as n, I18nConfigParams as o, ReadonlyConditionStoreInterface as p, ReadonlyConditionStore as r, LocaleCandidates as s, WritableConditionStore as t, I18nCacheConfig as u, Locale as v, GTConfig as y };
190
- //# sourceMappingURL=WritableConditionStore-Bn55y9M5.d.cts.map
190
+ //# sourceMappingURL=WritableConditionStore-DwBYQYJK.d.mts.map
@@ -0,0 +1,12 @@
1
+ import { d as TranslationOptions } from "./options-D_Ry5muW.mjs";
2
+
3
+ //#region src/translation-functions/msg/decodeOptions.d.ts
4
+ /**
5
+ * Decodes the options from an encoded message.
6
+ * @param encodedMsg The message to decode.
7
+ * @returns The decoded options.
8
+ */
9
+ declare function decodeOptions(encodedMsg: string): TranslationOptions | null;
10
+ //#endregion
11
+ export { decodeOptions as t };
12
+ //# sourceMappingURL=decodeOptions-BeDpvpRG.d.mts.map
@@ -0,0 +1,12 @@
1
+ import { d as TranslationOptions } from "./options-BXeFwN0R.cjs";
2
+
3
+ //#region src/translation-functions/msg/decodeOptions.d.ts
4
+ /**
5
+ * Decodes the options from an encoded message.
6
+ * @param encodedMsg The message to decode.
7
+ * @returns The decoded options.
8
+ */
9
+ declare function decodeOptions(encodedMsg: string): TranslationOptions | null;
10
+ //#endregion
11
+ export { decodeOptions as t };
12
+ //# sourceMappingURL=decodeOptions-DEMOo8JG.d.cts.map
@@ -1,13 +1,5 @@
1
- import { f as TranslationVariables, i as GTTranslationOptions } from "./options-DDUyXaLT.mjs";
1
+ import { f as TranslationVariables, i as GTTranslationOptions } from "./options-D_Ry5muW.mjs";
2
2
 
3
- //#region src/translation-functions/types/message.d.ts
4
- /**
5
- * Valid types for messages that can be registered.
6
- * msg('Hello, World!')
7
- * msg(['Hello, World!', 'Welcome, {user}!'])
8
- */
9
- type RegisterableMessages = string | string[] | readonly string[];
10
- //#endregion
11
3
  //#region src/translation-functions/types/functions.d.ts
12
4
  type DictionaryObjectTranslation = string | {
13
5
  [key: string]: DictionaryObjectTranslation;
@@ -62,5 +54,5 @@ type TFunctionType = ((id: string, options?: TranslationVariables) => string) &
62
54
  obj: (id: string) => DictionaryObjectTranslation;
63
55
  };
64
56
  //#endregion
65
- export { SyncResolutionFunctionWithFallback as a, SyncResolutionFunction as i, GTFunctionType as n, TFunctionType as o, MFunctionType as r, RegisterableMessages as s, DictionaryObjectTranslation as t };
66
- //# sourceMappingURL=functions-BZ_xopQU.d.mts.map
57
+ export { SyncResolutionFunctionWithFallback as a, SyncResolutionFunction as i, GTFunctionType as n, TFunctionType as o, MFunctionType as r, DictionaryObjectTranslation as t };
58
+ //# sourceMappingURL=functions-BlAp7Ico.d.mts.map
@@ -1,13 +1,5 @@
1
1
  import { f as TranslationVariables, i as GTTranslationOptions } from "./options-BXeFwN0R.cjs";
2
2
 
3
- //#region src/translation-functions/types/message.d.ts
4
- /**
5
- * Valid types for messages that can be registered.
6
- * msg('Hello, World!')
7
- * msg(['Hello, World!', 'Welcome, {user}!'])
8
- */
9
- type RegisterableMessages = string | string[] | readonly string[];
10
- //#endregion
11
3
  //#region src/translation-functions/types/functions.d.ts
12
4
  type DictionaryObjectTranslation = string | {
13
5
  [key: string]: DictionaryObjectTranslation;
@@ -62,5 +54,5 @@ type TFunctionType = ((id: string, options?: TranslationVariables) => string) &
62
54
  obj: (id: string) => DictionaryObjectTranslation;
63
55
  };
64
56
  //#endregion
65
- export { SyncResolutionFunctionWithFallback as a, SyncResolutionFunction as i, GTFunctionType as n, TFunctionType as o, MFunctionType as r, RegisterableMessages as s, DictionaryObjectTranslation as t };
66
- //# sourceMappingURL=functions-BiA2tWER.d.cts.map
57
+ export { SyncResolutionFunctionWithFallback as a, SyncResolutionFunction as i, GTFunctionType as n, TFunctionType as o, MFunctionType as r, DictionaryObjectTranslation as t };
58
+ //# sourceMappingURL=functions-DY3ckTRN.d.cts.map
package/dist/index.cjs CHANGED
@@ -1,5 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_versionId = require("./versionId-BrRvCzwH.cjs");
2
+ const require_versionId = require("./versionId-Bd7hW7x_.cjs");
3
+ const require_msgString = require("./msgString-CSHG5PMt.cjs");
4
+ const require_isEncodedTranslationOptions = require("./isEncodedTranslationOptions-ab8RTutO.cjs");
3
5
  let generaltranslation_internal = require("generaltranslation/internal");
4
6
  let _generaltranslation_format = require("@generaltranslation/format");
5
7
  let generaltranslation = require("generaltranslation");
@@ -53,6 +55,7 @@ function extractInterpolatableValues(strings, values) {
53
55
  //#endregion
54
56
  //#region src/translation-functions/msg/msg.ts
55
57
  function msg(message, options) {
58
+ if (options?.$format === "STRING") return require_msgString.msgString(message, options);
56
59
  if (typeof message !== "string") {
57
60
  if (!options) return message;
58
61
  return message.map((m, i) => msg(m, {
@@ -62,7 +65,7 @@ function msg(message, options) {
62
65
  }
63
66
  if (!options) return message;
64
67
  const variables = require_versionId.extractVariables(options);
65
- let interpolatedString = message;
68
+ let interpolatedString;
66
69
  try {
67
70
  interpolatedString = (0, _generaltranslation_format.formatMessage)(message, {
68
71
  locales: [generaltranslation_internal.libraryDefaultLocale],
@@ -85,8 +88,7 @@ function msg(message, options) {
85
88
  $_source,
86
89
  $_hash
87
90
  };
88
- const optionsEncoding = (0, generaltranslation_internal.encode)(JSON.stringify(encodedOptions));
89
- return `${interpolatedString}:${optionsEncoding}`;
91
+ return require_msgString.encodeMsg(interpolatedString, encodedOptions);
90
92
  }
91
93
  //#endregion
92
94
  //#region src/translation-functions/msg/decodeMsg.ts
@@ -153,7 +155,7 @@ const gtFallback = (message, options = {}) => {
153
155
  */
154
156
  const mFallback = (encodedMsg, options = {}) => {
155
157
  if (!encodedMsg) return encodedMsg;
156
- if (require_versionId.isEncodedTranslationOptions(require_versionId.decodeOptions(encodedMsg) ?? {})) return decodeMsg(encodedMsg);
158
+ if (require_isEncodedTranslationOptions.isEncodedTranslationOptions(require_isEncodedTranslationOptions.decodeOptions(encodedMsg) ?? {})) return decodeMsg(encodedMsg);
157
159
  return require_versionId.interpolateIcuMessage(encodedMsg, options);
158
160
  };
159
161
  //#endregion
@@ -164,7 +166,7 @@ Object.defineProperty(exports, "declareVar", {
164
166
  }
165
167
  });
166
168
  exports.decodeMsg = decodeMsg;
167
- exports.decodeOptions = require_versionId.decodeOptions;
169
+ exports.decodeOptions = require_isEncodedTranslationOptions.decodeOptions;
168
170
  Object.defineProperty(exports, "decodeVars", {
169
171
  enumerable: true,
170
172
  get: function() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["getWritableConditionStore","resolveStringContentWithFallback","getDefaultLocale","resolveStringContent","extractVariables","libraryDefaultLocale","VAR_IDENTIFIER","createInterpolationFailureMessage","hashMessage","interpolateIcuMessage","isEncodedTranslationOptions","decodeOptions","interpolateIcuMessage"],"sources":["../src/translation-functions/t.ts","../src/translation-functions/msg/msg.ts","../src/translation-functions/msg/decodeMsg.ts","../src/translation-functions/fallbacks/gtFallback.ts","../src/translation-functions/fallbacks/mFallback.ts"],"sourcesContent":["import {\n resolveStringContent,\n resolveStringContentWithFallback,\n} from './internal/helpers';\nimport { GTTranslationOptions } from './types/options';\nimport { getDefaultLocale } from '../helpers/locale';\nimport { getWritableConditionStore } from '../condition-store/singleton-operations';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param options - The options for the translation.\n * @returns The translated message.\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const conditionStore = getWritableConditionStore();\n const locale = conditionStore.getEnableI18n()\n ? (options?.$locale ?? conditionStore.getLocale())\n : getDefaultLocale();\n return resolveStringContentWithFallback(locale, messageOrStrings, {\n $format: 'ICU',\n ...options,\n });\n }\n\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const conditionStore = getWritableConditionStore();\n const locale = conditionStore.getEnableI18n()\n ? conditionStore.getLocale()\n : getDefaultLocale();\n const interpolatedTemplate = messageOrStrings\n .map((string, index) => string + (values[index] ?? ''))\n .join('');\n const translatedInterpolatedTemplate = resolveStringContent(\n locale,\n interpolatedTemplate,\n { $format: 'ICU' }\n );\n if (translatedInterpolatedTemplate !== undefined) {\n return translatedInterpolatedTemplate;\n }\n\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...variables,\n });\n}\n\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n const parts: string[] = [];\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n parts.push(strings[i]);\n\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\ninterface StringOrTemplateSyncResolutionFunction {\n (strings: TemplateStringsArray, ...values: unknown[]): string;\n (message: string, options?: GTTranslationOptions): string;\n}\n\nexport type TemplateSyncResolutionFunction = (\n strings: TemplateStringsArray,\n ...values: unknown[]\n) => string;\n","import type {\n EncodedTranslationOptions,\n GTTranslationOptions,\n} from '../types/options';\nimport { formatMessage } from '@generaltranslation/format';\nimport {\n encode,\n libraryDefaultLocale,\n VAR_IDENTIFIER,\n} from 'generaltranslation/internal';\nimport { createInterpolationFailureMessage } from '../utils/messages';\nimport logger from '../../logs/logger';\nimport { extractVariables } from '../../utils/extractVariables';\nimport { hashMessage } from '../../utils/hashMessage';\nimport { RegisterableMessages } from '../types/message';\n\n/**\n * Registers a message to be translated. Returns the message unchanged if no options are provided.\n * @param {string | string[]} message The message to encode.\n * @param {GTTranslationOptions} [options] The options to encode.\n * @returns The message or array of messages.\n *\n * @note - This function registers the message before the build process. The actual translation does not\n * occur until the m() function is invoked.\n *\n * @note - Message format\n * A message is broken into two parts separated by colons:\n * - interpolated content - the content with interpolated variables\n * - hash + options - a unique identifier for the source content and options for the translation\n *\n * @example - Basic usage\n *\n * const message1 = msg('Hello, World!');\n * console.log(message1); // \"Hello, World!\"\n *\n * const message2 = msg('Hello, {name}!', { name: 'Brian' });\n * console.log(message2); // \"Hello, Brian:eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9\"\n *\n * @example - Array usage\n *\n * const messages = msg(['Hello, Alice!', 'Hello, Bob!']);\n * console.log(messages); // [\"Hello, Alice!\", \"Hello, Bob!\"]\n *\n * @example - When specifying an id for an array, each message will have a unique id of `${id}.${index}`\n * const messages = msg(['Hello, Alice!', 'Hello, Bob!'], { $id: 'greetings' });\n * // \"Hello, Alice!\" id: \"greetings.0\"\n * // \"Hello, Bob!\" id: \"greetings.1\"\n *\n * @important Internal note: until other packages are updated to use i18n-context practices, msg cannot use any functions that use i18nCache at all!\n */\nexport function msg<T extends RegisterableMessages = string>(message: T): T;\nexport function msg<T extends RegisterableMessages = string>(\n message: T,\n options?: GTTranslationOptions\n): T extends string ? string : string[];\nexport function msg(\n message: RegisterableMessages,\n options?: GTTranslationOptions\n): RegisterableMessages {\n // Handle array\n if (typeof message !== 'string') {\n if (!options) return message;\n return message.map((m, i) =>\n msg(m, {\n ...options,\n // ignore if $id is an empty string or not defined\n ...(options.$id && { $id: `${options.$id}.${i}` }),\n })\n );\n }\n\n if (!options) {\n return message;\n }\n\n // Extract variables\n const variables = extractVariables(options);\n\n // Interpolate string\n let interpolatedString: string = message;\n try {\n interpolatedString = formatMessage(message, {\n locales: [libraryDefaultLocale], // TODO: use compiler to insert locales\n variables: {\n ...variables,\n [VAR_IDENTIFIER]: 'other',\n },\n });\n } catch {\n logger.warn(createInterpolationFailureMessage(message));\n return message;\n }\n\n // Encode options\n const $_source = message;\n const $_hash =\n options.$_hash ||\n hashMessage(message, {\n $format: 'ICU',\n ...options,\n });\n\n const encodedOptions: EncodedTranslationOptions = {\n ...options,\n $_source,\n $_hash,\n };\n const optionsEncoding = encode(JSON.stringify(encodedOptions));\n\n // Construct result\n return `${interpolatedString}:${optionsEncoding}`;\n}\n","/**\n * Extracts the original interpolated message string.\n * If the message cannot be decoded (i.e., it does not contain a colon separator),\n * the input is returned as-is.\n * @param encodedMsg The message to decode.\n * @returns The decoded message, or the input if it cannot be decoded.\n */\nexport function decodeMsg(encodedMsg: string): string;\nexport function decodeMsg<T extends null | undefined>(encodedMsg: T): T;\nexport function decodeMsg<T extends string | null | undefined>(\n encodedMsg: T\n): T extends string ? string : T;\nexport function decodeMsg<T extends string | null | undefined>(\n encodedMsg: T\n): string | T {\n if (typeof encodedMsg === 'string' && encodedMsg.lastIndexOf(':') !== -1) {\n return encodedMsg.slice(0, encodedMsg.lastIndexOf(':'));\n }\n return encodedMsg;\n}\n","import { GTTranslationOptions } from '../types/options';\nimport { GTFunctionType } from '../types/functions';\nimport { interpolateIcuMessage } from '../utils/interpolation/interpolateIcuMessage';\n\n/**\n * A fallback function for the gt() function that decodes and interpolates.\n * @param {string | null | undefined} message - The ICU formatted message to interpolate.\n * @param {GTTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @note This function is useful as a placeholder when for incrementally migrating to the m() function.\n * @example\n * // A backwards compatible translation function\n * function getMessage(gt: GTFunctionType = gtFallback) {\n * return gt('Hello, world!');\n * }\n *\n * // Here i18n has been implemented\n * function WithTranslation() {\n * const gt = useGT();\n * return <>{getMessage(gt)}</>;\n * }\n *\n *\n * // i18n has not yet been implemented yet\n * function WithoutTranslations() {\n * return <>{getMessage()}</>;\n * }\n */\nexport const gtFallback: GTFunctionType = <T extends string | null | undefined>(\n message: T,\n options: GTTranslationOptions = {}\n): T extends string ? string : T => {\n return interpolateIcuMessage(message, options);\n};\n","import { decodeMsg } from '../msg/decodeMsg';\nimport { GTTranslationOptions } from '../types/options';\nimport { MFunctionType } from '../types/functions';\nimport { decodeOptions } from '../msg/decodeOptions';\nimport { isEncodedTranslationOptions } from '../utils/isEncodedTranslationOptions';\nimport { interpolateIcuMessage } from '../utils/interpolation/interpolateIcuMessage';\n\n/**\n * A fallback function for the m() function that decodes and interpolates.\n * @param {string | null | undefined} encodedMsg - The encoded message to decode and interpolate.\n * @param {GTTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @note This function is useful as a placeholder when for incrementally migrating to the m() function.\n * @example\n * // A backwards compatible translation function\n * function getMessage(m: MFunctionType = mFallback) {\n * return m(msg('Hello, world!'));\n * }\n *\n * // Here i18n has been implemented\n * function WithTranslation() {\n * const m = useMessages();\n * return <>{getMessage(m)}</>;\n * }\n *\n *\n * // i18n has not yet been implemented yet\n * function WithoutTranslations() {\n * return <>{getMessage()}</>;\n * }\n */\nexport const mFallback: MFunctionType = <T extends string | null | undefined>(\n encodedMsg: T,\n options: GTTranslationOptions = {}\n): T extends string ? string : T => {\n // Return if the encoded message is null or undefined\n if (!encodedMsg) return encodedMsg as T extends string ? string : T;\n\n // Get any encoded options\n const decodedOptions = decodeOptions(encodedMsg) ?? {};\n\n // Return early if string already interpolated eg: mFallback(msg('Hello, {name}!', { name: 'Brian' }))\n if (isEncodedTranslationOptions(decodedOptions)) {\n // This is an encoded string, msg already interpolated, just return decoded string\n return decodeMsg(encodedMsg) as T extends string ? string : T;\n }\n\n // Not using decoded options to match behavior in @gt/react-core\n return interpolateIcuMessage(encodedMsg, options);\n};\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,KACX,kBACA,GAAG,WACA;AACH,KAAI,OAAO,qBAAqB,UAAU;EACx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getDefaultLocale","resolveStringContent","msgString","extractVariables","libraryDefaultLocale","VAR_IDENTIFIER","createInterpolationFailureMessage","hashMessage","encodeMsg","interpolateIcuMessage","isEncodedTranslationOptions","decodeOptions","interpolateIcuMessage"],"sources":["../src/translation-functions/t.ts","../src/translation-functions/msg/msg.ts","../src/translation-functions/msg/decodeMsg.ts","../src/translation-functions/fallbacks/gtFallback.ts","../src/translation-functions/fallbacks/mFallback.ts"],"sourcesContent":["import {\n resolveStringContent,\n resolveStringContentWithFallback,\n} from './internal/helpers';\nimport { GTTranslationOptions } from './types/options';\nimport { getDefaultLocale } from '../helpers/locale';\nimport { getWritableConditionStore } from '../condition-store/singleton-operations';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param options - The options for the translation.\n * @returns The translated message.\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const conditionStore = getWritableConditionStore();\n const locale = conditionStore.getEnableI18n()\n ? (options?.$locale ?? conditionStore.getLocale())\n : getDefaultLocale();\n return resolveStringContentWithFallback(locale, messageOrStrings, {\n $format: 'ICU',\n ...options,\n });\n }\n\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const conditionStore = getWritableConditionStore();\n const locale = conditionStore.getEnableI18n()\n ? conditionStore.getLocale()\n : getDefaultLocale();\n const interpolatedTemplate = messageOrStrings\n .map((string, index) => string + (values[index] ?? ''))\n .join('');\n const translatedInterpolatedTemplate = resolveStringContent(\n locale,\n interpolatedTemplate,\n { $format: 'ICU' }\n );\n if (translatedInterpolatedTemplate !== undefined) {\n return translatedInterpolatedTemplate;\n }\n\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...variables,\n });\n}\n\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n const parts: string[] = [];\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n parts.push(strings[i]);\n\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\ninterface StringOrTemplateSyncResolutionFunction {\n (strings: TemplateStringsArray, ...values: unknown[]): string;\n (message: string, options?: GTTranslationOptions): string;\n}\n\nexport type TemplateSyncResolutionFunction = (\n strings: TemplateStringsArray,\n ...values: unknown[]\n) => string;\n","import type {\n EncodedTranslationOptions,\n GTTranslationOptions,\n} from '../types/options';\nimport { formatMessage } from '@generaltranslation/format';\nimport {\n libraryDefaultLocale,\n VAR_IDENTIFIER,\n} from 'generaltranslation/internal';\nimport { createInterpolationFailureMessage } from '../utils/messages';\nimport logger from '../../logs/logger';\nimport { extractVariables } from '../../utils/extractVariables';\nimport { hashMessage } from '../../utils/hashMessage';\nimport { RegisterableMessages } from '../types/message';\nimport { encodeMsg } from './encodeMsg';\nimport { msgString } from './msgString';\n\n/**\n * Registers a message to be translated. Returns the message unchanged if no options are provided.\n * @param {string | string[]} message The message to encode.\n * @param {GTTranslationOptions} [options] The options to encode.\n * @returns The message or array of messages.\n *\n * @note - This function registers the message before the build process. The actual translation does not\n * occur until the m() function is invoked.\n *\n * @note - Message format\n * A message is broken into two parts separated by colons:\n * - interpolated content - the content with interpolated variables\n * - hash + options - a unique identifier for the source content and options for the translation\n *\n * @example - Basic usage\n *\n * const message1 = msg('Hello, World!');\n * console.log(message1); // \"Hello, World!\"\n *\n * const message2 = msg('Hello, {name}!', { name: 'Brian' });\n * console.log(message2); // \"Hello, Brian:eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9\"\n *\n * @example - Array usage\n *\n * const messages = msg(['Hello, Alice!', 'Hello, Bob!']);\n * console.log(messages); // [\"Hello, Alice!\", \"Hello, Bob!\"]\n *\n * @example - When specifying an id for an array, each message will have a unique id of `${id}.${index}`\n * const messages = msg(['Hello, Alice!', 'Hello, Bob!'], { $id: 'greetings' });\n * // \"Hello, Alice!\" id: \"greetings.0\"\n * // \"Hello, Bob!\" id: \"greetings.1\"\n *\n * @important Internal note: until other packages are updated to use i18n-context practices, msg cannot use any functions that use i18nCache at all!\n */\nexport function msg<T extends RegisterableMessages = string>(message: T): T;\nexport function msg<T extends RegisterableMessages = string>(\n message: T,\n options?: GTTranslationOptions\n): T extends string ? string : string[];\nexport function msg(\n message: RegisterableMessages,\n options?: GTTranslationOptions\n): RegisterableMessages {\n if (options?.$format === 'STRING') return msgString(message, options);\n\n // Handle array\n if (typeof message !== 'string') {\n if (!options) return message;\n return message.map((m, i) =>\n msg(m, {\n ...options,\n // ignore if $id is an empty string or not defined\n ...(options.$id && { $id: `${options.$id}.${i}` }),\n })\n );\n }\n\n if (!options) {\n return message;\n }\n\n const variables = extractVariables(options);\n let interpolatedString: string;\n try {\n interpolatedString = formatMessage(message, {\n locales: [libraryDefaultLocale], // TODO: use compiler to insert locales\n variables: {\n ...variables,\n [VAR_IDENTIFIER]: 'other',\n },\n });\n } catch {\n logger.warn(createInterpolationFailureMessage(message));\n return message;\n }\n\n // Encode options\n const $_source = message;\n const $_hash =\n options.$_hash ||\n hashMessage(message, {\n $format: 'ICU',\n ...options,\n });\n\n const encodedOptions: EncodedTranslationOptions = {\n ...options,\n $_source,\n $_hash,\n };\n return encodeMsg(interpolatedString, encodedOptions);\n}\n","/**\n * Extracts the original interpolated message string.\n * If the message cannot be decoded (i.e., it does not contain a colon separator),\n * the input is returned as-is.\n * @param encodedMsg The message to decode.\n * @returns The decoded message, or the input if it cannot be decoded.\n */\nexport function decodeMsg(encodedMsg: string): string;\nexport function decodeMsg<T extends null | undefined>(encodedMsg: T): T;\nexport function decodeMsg<T extends string | null | undefined>(\n encodedMsg: T\n): T extends string ? string : T;\nexport function decodeMsg<T extends string | null | undefined>(\n encodedMsg: T\n): string | T {\n if (typeof encodedMsg === 'string' && encodedMsg.lastIndexOf(':') !== -1) {\n return encodedMsg.slice(0, encodedMsg.lastIndexOf(':'));\n }\n return encodedMsg;\n}\n","import { GTTranslationOptions } from '../types/options';\nimport { GTFunctionType } from '../types/functions';\nimport { interpolateIcuMessage } from '../utils/interpolation/interpolateIcuMessage';\n\n/**\n * A fallback function for the gt() function that decodes and interpolates.\n * @param {string | null | undefined} message - The ICU formatted message to interpolate.\n * @param {GTTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @note This function is useful as a placeholder when for incrementally migrating to the m() function.\n * @example\n * // A backwards compatible translation function\n * function getMessage(gt: GTFunctionType = gtFallback) {\n * return gt('Hello, world!');\n * }\n *\n * // Here i18n has been implemented\n * function WithTranslation() {\n * const gt = useGT();\n * return <>{getMessage(gt)}</>;\n * }\n *\n *\n * // i18n has not yet been implemented yet\n * function WithoutTranslations() {\n * return <>{getMessage()}</>;\n * }\n */\nexport const gtFallback: GTFunctionType = <T extends string | null | undefined>(\n message: T,\n options: GTTranslationOptions = {}\n): T extends string ? string : T => {\n return interpolateIcuMessage(message, options);\n};\n","import { decodeMsg } from '../msg/decodeMsg';\nimport { GTTranslationOptions } from '../types/options';\nimport { MFunctionType } from '../types/functions';\nimport { decodeOptions } from '../msg/decodeOptions';\nimport { isEncodedTranslationOptions } from '../utils/isEncodedTranslationOptions';\nimport { interpolateIcuMessage } from '../utils/interpolation/interpolateIcuMessage';\n\n/**\n * A fallback function for the m() function that decodes and interpolates.\n * @param {string | null | undefined} encodedMsg - The encoded message to decode and interpolate.\n * @param {GTTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @note This function is useful as a placeholder when for incrementally migrating to the m() function.\n * @example\n * // A backwards compatible translation function\n * function getMessage(m: MFunctionType = mFallback) {\n * return m(msg('Hello, world!'));\n * }\n *\n * // Here i18n has been implemented\n * function WithTranslation() {\n * const m = useMessages();\n * return <>{getMessage(m)}</>;\n * }\n *\n *\n * // i18n has not yet been implemented yet\n * function WithoutTranslations() {\n * return <>{getMessage()}</>;\n * }\n */\nexport const mFallback: MFunctionType = <T extends string | null | undefined>(\n encodedMsg: T,\n options: GTTranslationOptions = {}\n): T extends string ? string : T => {\n // Return if the encoded message is null or undefined\n if (!encodedMsg) return encodedMsg as T extends string ? string : T;\n\n // Get any encoded options\n const decodedOptions = decodeOptions(encodedMsg) ?? {};\n\n // Return early if string already interpolated eg: mFallback(msg('Hello, {name}!', { name: 'Brian' }))\n if (isEncodedTranslationOptions(decodedOptions)) {\n // This is an encoded string, msg already interpolated, just return decoded string\n return decodeMsg(encodedMsg) as T extends string ? string : T;\n }\n\n // Not using decoded options to match behavior in @gt/react-core\n return interpolateIcuMessage(encodedMsg, options);\n};\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,KACX,kBACA,GAAG,WACA;AACH,KAAI,OAAO,qBAAqB,UAAU;EACxC,MAAM,UAAU,OAAO,GAAG,EAAE;EAC5B,MAAM,iBAAiBA,kBAAAA,2BAA2B;AAIlD,SAAOC,kBAAAA,iCAHQ,eAAe,eAAe,GACxC,SAAS,WAAW,eAAe,WAAW,GAC/CC,kBAAAA,kBAAkB,EAC0B,kBAAkB;GAChE,SAAS;GACT,GAAG;GACJ,CAAC;;AAGJ,QAAO,uCAAuC,kBAAkB,OAAO;;AAGzE,SAAS,uCACP,kBACA,QACQ;CACR,MAAM,iBAAiBF,kBAAAA,2BAA2B;CAClD,MAAM,SAAS,eAAe,eAAe,GACzC,eAAe,WAAW,GAC1BE,kBAAAA,kBAAkB;CAItB,MAAM,iCAAiCC,kBAAAA,qBACrC,QAJ2B,iBAC1B,KAAK,QAAQ,UAAU,UAAU,OAAO,UAAU,IAAI,C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ACJ,QAAQ,UACRC,kBAAAA,YAAY,SAAS;EACnB,SAAS;EACT,GAAG;EACJ,CAAC;CAEJ,MAAM,iBAA4C;EAChD,GAAG;EACH;EACA;EACD;AACD,QAAOC,kBAAAA,UAAU,oBAAoB,eAAe;;;;AC/FtD,SAAgB,UACd,YACY;AACZ,KAAI,OAAO,eAAe,YAAY,WAAW,YAAY,IAAI,KAAK,GACpE,QAAO,WAAW,MAAM,GAAG,WAAW,YAAY,IAAI,CAAC;AAEzD,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACWT,MAAa,cACX,SACA,UAAgC,EAAE,KACA;AAClC,QAAOC,kBAAAA,sBAAsB,SAAS,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACDhD,MAAa,aACX,YACA,UAAgC,EAAE,KACA;AAElC,KAAI,CAAC,WAAY,QAAO;AAMxB,KAAIC,oCAAAA,4BAHmBC,oCAAAA,cAAc,WAAW,IAAI,EAAE,CAGP,CAE7C,QAAO,UAAU,WAAW;AAI9B,QAAOC,kBAAAA,sBAAsB,YAAY,QAAQ"}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,8 @@
1
- import { d as TranslationOptions, i as GTTranslationOptions } from "./options-BXeFwN0R.cjs";
2
- import { n as GTFunctionType, r as MFunctionType, s as RegisterableMessages } from "./functions-BiA2tWER.cjs";
3
- import { t as getVersionId } from "./versionId-0COhh5UX.cjs";
1
+ import { i as GTTranslationOptions } from "./options-BXeFwN0R.cjs";
2
+ import { t as RegisterableMessages } from "./message-BxBVYC3J.cjs";
3
+ import { t as decodeOptions } from "./decodeOptions-DEMOo8JG.cjs";
4
+ import { n as GTFunctionType, r as MFunctionType } from "./functions-DY3ckTRN.cjs";
5
+ import { t as getVersionId } from "./versionId-CGNwvk_T.cjs";
4
6
  import { declareVar, decodeVars, derive } from "generaltranslation";
5
7
  import * as _$generaltranslation_internal0 from "generaltranslation/internal";
6
8
 
@@ -68,14 +70,6 @@ declare function decodeMsg(encodedMsg: string): string;
68
70
  declare function decodeMsg<T extends null | undefined>(encodedMsg: T): T;
69
71
  declare function decodeMsg<T extends string | null | undefined>(encodedMsg: T): T extends string ? string : T;
70
72
  //#endregion
71
- //#region src/translation-functions/msg/decodeOptions.d.ts
72
- /**
73
- * Decodes the options from an encoded message.
74
- * @param encodedMsg The message to decode.
75
- * @returns The decoded options.
76
- */
77
- declare function decodeOptions(encodedMsg: string): TranslationOptions | null;
78
- //#endregion
79
73
  //#region src/translation-functions/fallbacks/gtFallback.d.ts
80
74
  /**
81
75
  * A fallback function for the gt() function that decodes and interpolates.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,8 @@
1
- import { d as TranslationOptions, i as GTTranslationOptions } from "./options-DDUyXaLT.mjs";
2
- import { n as GTFunctionType, r as MFunctionType, s as RegisterableMessages } from "./functions-BZ_xopQU.mjs";
3
- import { t as getVersionId } from "./versionId-Zel3fqtC.mjs";
1
+ import { i as GTTranslationOptions } from "./options-D_Ry5muW.mjs";
2
+ import { t as RegisterableMessages } from "./message-CYsuGTre.mjs";
3
+ import { t as decodeOptions } from "./decodeOptions-BeDpvpRG.mjs";
4
+ import { n as GTFunctionType, r as MFunctionType } from "./functions-BlAp7Ico.mjs";
5
+ import { t as getVersionId } from "./versionId-BSCcbrCd.mjs";
4
6
  import * as _$generaltranslation_internal0 from "generaltranslation/internal";
5
7
  import { declareVar, decodeVars, derive } from "generaltranslation";
6
8
 
@@ -68,14 +70,6 @@ declare function decodeMsg(encodedMsg: string): string;
68
70
  declare function decodeMsg<T extends null | undefined>(encodedMsg: T): T;
69
71
  declare function decodeMsg<T extends string | null | undefined>(encodedMsg: T): T extends string ? string : T;
70
72
  //#endregion
71
- //#region src/translation-functions/msg/decodeOptions.d.ts
72
- /**
73
- * Decodes the options from an encoded message.
74
- * @param encodedMsg The message to decode.
75
- * @returns The decoded options.
76
- */
77
- declare function decodeOptions(encodedMsg: string): TranslationOptions | null;
78
- //#endregion
79
73
  //#region src/translation-functions/fallbacks/gtFallback.d.ts
80
74
  /**
81
75
  * A fallback function for the gt() function that decodes and interpolates.
package/dist/index.mjs CHANGED
@@ -1,5 +1,7 @@
1
- import { D as logger_default, S as extractVariables, _ as resolveStringContentWithFallback, a as getDefaultLocale, b as interpolateIcuMessage, c as getLocales, d as getWritableConditionStore, g as resolveStringContent, i as hashMessage, l as getRegion, n as isEncodedTranslationOptions, o as getLocale, r as decodeOptions, s as getLocaleProperties, t as getVersionId, u as resolveCanonicalLocale, x as createInterpolationFailureMessage } from "./versionId-I8qWZjrR.mjs";
2
- import { VAR_IDENTIFIER, encode, libraryDefaultLocale } from "generaltranslation/internal";
1
+ import { T as logger_default, a as getLocaleProperties, b as extractVariables, c as resolveCanonicalLocale, h as resolveStringContentWithFallback, i as getLocale, l as getWritableConditionStore, m as resolveStringContent, n as hashMessage, o as getLocales, r as getDefaultLocale, s as getRegion, t as getVersionId, v as interpolateIcuMessage, y as createInterpolationFailureMessage } from "./versionId-DQnENeZa.mjs";
2
+ import { r as encodeMsg, t as msgString } from "./msgString-C-b5XBju.mjs";
3
+ import { n as decodeOptions, t as isEncodedTranslationOptions } from "./isEncodedTranslationOptions-CmlRuckr.mjs";
4
+ import { VAR_IDENTIFIER, libraryDefaultLocale } from "generaltranslation/internal";
3
5
  import { formatMessage } from "@generaltranslation/format";
4
6
  import { declareVar, decodeVars, derive } from "generaltranslation";
5
7
  //#region src/translation-functions/t.ts
@@ -52,6 +54,7 @@ function extractInterpolatableValues(strings, values) {
52
54
  //#endregion
53
55
  //#region src/translation-functions/msg/msg.ts
54
56
  function msg(message, options) {
57
+ if (options?.$format === "STRING") return msgString(message, options);
55
58
  if (typeof message !== "string") {
56
59
  if (!options) return message;
57
60
  return message.map((m, i) => msg(m, {
@@ -61,7 +64,7 @@ function msg(message, options) {
61
64
  }
62
65
  if (!options) return message;
63
66
  const variables = extractVariables(options);
64
- let interpolatedString = message;
67
+ let interpolatedString;
65
68
  try {
66
69
  interpolatedString = formatMessage(message, {
67
70
  locales: [libraryDefaultLocale],
@@ -84,8 +87,7 @@ function msg(message, options) {
84
87
  $_source,
85
88
  $_hash
86
89
  };
87
- const optionsEncoding = encode(JSON.stringify(encodedOptions));
88
- return `${interpolatedString}:${optionsEncoding}`;
90
+ return encodeMsg(interpolatedString, encodedOptions);
89
91
  }
90
92
  //#endregion
91
93
  //#region src/translation-functions/msg/decodeMsg.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/translation-functions/t.ts","../src/translation-functions/msg/msg.ts","../src/translation-functions/msg/decodeMsg.ts","../src/translation-functions/fallbacks/gtFallback.ts","../src/translation-functions/fallbacks/mFallback.ts"],"sourcesContent":["import {\n resolveStringContent,\n resolveStringContentWithFallback,\n} from './internal/helpers';\nimport { GTTranslationOptions } from './types/options';\nimport { getDefaultLocale } from '../helpers/locale';\nimport { getWritableConditionStore } from '../condition-store/singleton-operations';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param options - The options for the translation.\n * @returns The translated message.\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const conditionStore = getWritableConditionStore();\n const locale = conditionStore.getEnableI18n()\n ? (options?.$locale ?? conditionStore.getLocale())\n : getDefaultLocale();\n return resolveStringContentWithFallback(locale, messageOrStrings, {\n $format: 'ICU',\n ...options,\n });\n }\n\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const conditionStore = getWritableConditionStore();\n const locale = conditionStore.getEnableI18n()\n ? conditionStore.getLocale()\n : getDefaultLocale();\n const interpolatedTemplate = messageOrStrings\n .map((string, index) => string + (values[index] ?? ''))\n .join('');\n const translatedInterpolatedTemplate = resolveStringContent(\n locale,\n interpolatedTemplate,\n { $format: 'ICU' }\n );\n if (translatedInterpolatedTemplate !== undefined) {\n return translatedInterpolatedTemplate;\n }\n\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...variables,\n });\n}\n\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n const parts: string[] = [];\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n parts.push(strings[i]);\n\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\ninterface StringOrTemplateSyncResolutionFunction {\n (strings: TemplateStringsArray, ...values: unknown[]): string;\n (message: string, options?: GTTranslationOptions): string;\n}\n\nexport type TemplateSyncResolutionFunction = (\n strings: TemplateStringsArray,\n ...values: unknown[]\n) => string;\n","import type {\n EncodedTranslationOptions,\n GTTranslationOptions,\n} from '../types/options';\nimport { formatMessage } from '@generaltranslation/format';\nimport {\n encode,\n libraryDefaultLocale,\n VAR_IDENTIFIER,\n} from 'generaltranslation/internal';\nimport { createInterpolationFailureMessage } from '../utils/messages';\nimport logger from '../../logs/logger';\nimport { extractVariables } from '../../utils/extractVariables';\nimport { hashMessage } from '../../utils/hashMessage';\nimport { RegisterableMessages } from '../types/message';\n\n/**\n * Registers a message to be translated. Returns the message unchanged if no options are provided.\n * @param {string | string[]} message The message to encode.\n * @param {GTTranslationOptions} [options] The options to encode.\n * @returns The message or array of messages.\n *\n * @note - This function registers the message before the build process. The actual translation does not\n * occur until the m() function is invoked.\n *\n * @note - Message format\n * A message is broken into two parts separated by colons:\n * - interpolated content - the content with interpolated variables\n * - hash + options - a unique identifier for the source content and options for the translation\n *\n * @example - Basic usage\n *\n * const message1 = msg('Hello, World!');\n * console.log(message1); // \"Hello, World!\"\n *\n * const message2 = msg('Hello, {name}!', { name: 'Brian' });\n * console.log(message2); // \"Hello, Brian:eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9\"\n *\n * @example - Array usage\n *\n * const messages = msg(['Hello, Alice!', 'Hello, Bob!']);\n * console.log(messages); // [\"Hello, Alice!\", \"Hello, Bob!\"]\n *\n * @example - When specifying an id for an array, each message will have a unique id of `${id}.${index}`\n * const messages = msg(['Hello, Alice!', 'Hello, Bob!'], { $id: 'greetings' });\n * // \"Hello, Alice!\" id: \"greetings.0\"\n * // \"Hello, Bob!\" id: \"greetings.1\"\n *\n * @important Internal note: until other packages are updated to use i18n-context practices, msg cannot use any functions that use i18nCache at all!\n */\nexport function msg<T extends RegisterableMessages = string>(message: T): T;\nexport function msg<T extends RegisterableMessages = string>(\n message: T,\n options?: GTTranslationOptions\n): T extends string ? string : string[];\nexport function msg(\n message: RegisterableMessages,\n options?: GTTranslationOptions\n): RegisterableMessages {\n // Handle array\n if (typeof message !== 'string') {\n if (!options) return message;\n return message.map((m, i) =>\n msg(m, {\n ...options,\n // ignore if $id is an empty string or not defined\n ...(options.$id && { $id: `${options.$id}.${i}` }),\n })\n );\n }\n\n if (!options) {\n return message;\n }\n\n // Extract variables\n const variables = extractVariables(options);\n\n // Interpolate string\n let interpolatedString: string = message;\n try {\n interpolatedString = formatMessage(message, {\n locales: [libraryDefaultLocale], // TODO: use compiler to insert locales\n variables: {\n ...variables,\n [VAR_IDENTIFIER]: 'other',\n },\n });\n } catch {\n logger.warn(createInterpolationFailureMessage(message));\n return message;\n }\n\n // Encode options\n const $_source = message;\n const $_hash =\n options.$_hash ||\n hashMessage(message, {\n $format: 'ICU',\n ...options,\n });\n\n const encodedOptions: EncodedTranslationOptions = {\n ...options,\n $_source,\n $_hash,\n };\n const optionsEncoding = encode(JSON.stringify(encodedOptions));\n\n // Construct result\n return `${interpolatedString}:${optionsEncoding}`;\n}\n","/**\n * Extracts the original interpolated message string.\n * If the message cannot be decoded (i.e., it does not contain a colon separator),\n * the input is returned as-is.\n * @param encodedMsg The message to decode.\n * @returns The decoded message, or the input if it cannot be decoded.\n */\nexport function decodeMsg(encodedMsg: string): string;\nexport function decodeMsg<T extends null | undefined>(encodedMsg: T): T;\nexport function decodeMsg<T extends string | null | undefined>(\n encodedMsg: T\n): T extends string ? string : T;\nexport function decodeMsg<T extends string | null | undefined>(\n encodedMsg: T\n): string | T {\n if (typeof encodedMsg === 'string' && encodedMsg.lastIndexOf(':') !== -1) {\n return encodedMsg.slice(0, encodedMsg.lastIndexOf(':'));\n }\n return encodedMsg;\n}\n","import { GTTranslationOptions } from '../types/options';\nimport { GTFunctionType } from '../types/functions';\nimport { interpolateIcuMessage } from '../utils/interpolation/interpolateIcuMessage';\n\n/**\n * A fallback function for the gt() function that decodes and interpolates.\n * @param {string | null | undefined} message - The ICU formatted message to interpolate.\n * @param {GTTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @note This function is useful as a placeholder when for incrementally migrating to the m() function.\n * @example\n * // A backwards compatible translation function\n * function getMessage(gt: GTFunctionType = gtFallback) {\n * return gt('Hello, world!');\n * }\n *\n * // Here i18n has been implemented\n * function WithTranslation() {\n * const gt = useGT();\n * return <>{getMessage(gt)}</>;\n * }\n *\n *\n * // i18n has not yet been implemented yet\n * function WithoutTranslations() {\n * return <>{getMessage()}</>;\n * }\n */\nexport const gtFallback: GTFunctionType = <T extends string | null | undefined>(\n message: T,\n options: GTTranslationOptions = {}\n): T extends string ? string : T => {\n return interpolateIcuMessage(message, options);\n};\n","import { decodeMsg } from '../msg/decodeMsg';\nimport { GTTranslationOptions } from '../types/options';\nimport { MFunctionType } from '../types/functions';\nimport { decodeOptions } from '../msg/decodeOptions';\nimport { isEncodedTranslationOptions } from '../utils/isEncodedTranslationOptions';\nimport { interpolateIcuMessage } from '../utils/interpolation/interpolateIcuMessage';\n\n/**\n * A fallback function for the m() function that decodes and interpolates.\n * @param {string | null | undefined} encodedMsg - The encoded message to decode and interpolate.\n * @param {GTTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @note This function is useful as a placeholder when for incrementally migrating to the m() function.\n * @example\n * // A backwards compatible translation function\n * function getMessage(m: MFunctionType = mFallback) {\n * return m(msg('Hello, world!'));\n * }\n *\n * // Here i18n has been implemented\n * function WithTranslation() {\n * const m = useMessages();\n * return <>{getMessage(m)}</>;\n * }\n *\n *\n * // i18n has not yet been implemented yet\n * function WithoutTranslations() {\n * return <>{getMessage()}</>;\n * }\n */\nexport const mFallback: MFunctionType = <T extends string | null | undefined>(\n encodedMsg: T,\n options: GTTranslationOptions = {}\n): T extends string ? string : T => {\n // Return if the encoded message is null or undefined\n if (!encodedMsg) return encodedMsg as T extends string ? string : T;\n\n // Get any encoded options\n const decodedOptions = decodeOptions(encodedMsg) ?? {};\n\n // Return early if string already interpolated eg: mFallback(msg('Hello, {name}!', { name: 'Brian' }))\n if (isEncodedTranslationOptions(decodedOptions)) {\n // This is an encoded string, msg already interpolated, just return decoded string\n return decodeMsg(encodedMsg) as T extends string ? string : T;\n }\n\n // Not using decoded options to match behavior in @gt/react-core\n return interpolateIcuMessage(encodedMsg, options);\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,KACX,kBACA,GAAG,WACA;AACH,KAAI,OAAO,qBAAqB,UAAU;EACxC,MAAM,UAAU,OAAO,GAAG,EAAE;EAC5B,MAAM,iBAAiB,2BAA2B;AAIlD,SAAO,iCAHQ,eAAe,eAAe,GACxC,SAAS,WAAW,eAAe,WAAW,GAC/C,kBAAkB,EAC0B,kBAAkB;GAChE,SAAS;GACT,GAAG;GACJ,CAAC;;AAGJ,QAAO,uCAAuC,kBAAkB,OAAO;;AAGzE,SAAS,uCACP,kBACA,QACQ;CACR,MAAM,iBAAiB,2BAA2B;CAClD,MAAM,SAAS,eAAe,eAAe,GACzC,eAAe,WAAW,GAC1B,kBAAkB;CAItB,MAAM,iCAA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G;EACJ,CAAC;CAEJ,MAAM,iBAA4C;EAChD,GAAG;EACH;EACA;EACD;CACD,MAAM,kBAAkB,OAAO,KAAK,UAAU,eAAe,CAAC;AAG9D,QAAO,GAAG,mBAAmB,GAAG;;;;AClGlC,SAAgB,UACd,YACY;AACZ,KAAI,OAAO,eAAe,YAAY,WAAW,YAAY,IAAI,KAAK,GACpE,QAAO,WAAW,MAAM,GAAG,WAAW,YAAY,IAAI,CAAC;AAEzD,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACWT,MAAa,cACX,SACA,UAAgC,EAAE,KACA;AAClC,QAAO,sBAAsB,SAAS,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACDhD,MAAa,aACX,YACA,UAAgC,EAAE,KACA;AAElC,KAAI,CAAC,WAAY,QAAO;AAMxB,KAAI,4BAHmB,cAAc,WAAW,IAAI,EAAE,CAGP,CAE7C,QAAO,UAAU,WAAW;AAI9B,QAAO,sBAAsB,YAAY,QAAQ"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/translation-functions/t.ts","../src/translation-functions/msg/msg.ts","../src/translation-functions/msg/decodeMsg.ts","../src/translation-functions/fallbacks/gtFallback.ts","../src/translation-functions/fallbacks/mFallback.ts"],"sourcesContent":["import {\n resolveStringContent,\n resolveStringContentWithFallback,\n} from './internal/helpers';\nimport { GTTranslationOptions } from './types/options';\nimport { getDefaultLocale } from '../helpers/locale';\nimport { getWritableConditionStore } from '../condition-store/singleton-operations';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param options - The options for the translation.\n * @returns The translated message.\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const conditionStore = getWritableConditionStore();\n const locale = conditionStore.getEnableI18n()\n ? (options?.$locale ?? conditionStore.getLocale())\n : getDefaultLocale();\n return resolveStringContentWithFallback(locale, messageOrStrings, {\n $format: 'ICU',\n ...options,\n });\n }\n\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const conditionStore = getWritableConditionStore();\n const locale = conditionStore.getEnableI18n()\n ? conditionStore.getLocale()\n : getDefaultLocale();\n const interpolatedTemplate = messageOrStrings\n .map((string, index) => string + (values[index] ?? ''))\n .join('');\n const translatedInterpolatedTemplate = resolveStringContent(\n locale,\n interpolatedTemplate,\n { $format: 'ICU' }\n );\n if (translatedInterpolatedTemplate !== undefined) {\n return translatedInterpolatedTemplate;\n }\n\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...variables,\n });\n}\n\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n const parts: string[] = [];\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n parts.push(strings[i]);\n\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\ninterface StringOrTemplateSyncResolutionFunction {\n (strings: TemplateStringsArray, ...values: unknown[]): string;\n (message: string, options?: GTTranslationOptions): string;\n}\n\nexport type TemplateSyncResolutionFunction = (\n strings: TemplateStringsArray,\n ...values: unknown[]\n) => string;\n","import type {\n EncodedTranslationOptions,\n GTTranslationOptions,\n} from '../types/options';\nimport { formatMessage } from '@generaltranslation/format';\nimport {\n libraryDefaultLocale,\n VAR_IDENTIFIER,\n} from 'generaltranslation/internal';\nimport { createInterpolationFailureMessage } from '../utils/messages';\nimport logger from '../../logs/logger';\nimport { extractVariables } from '../../utils/extractVariables';\nimport { hashMessage } from '../../utils/hashMessage';\nimport { RegisterableMessages } from '../types/message';\nimport { encodeMsg } from './encodeMsg';\nimport { msgString } from './msgString';\n\n/**\n * Registers a message to be translated. Returns the message unchanged if no options are provided.\n * @param {string | string[]} message The message to encode.\n * @param {GTTranslationOptions} [options] The options to encode.\n * @returns The message or array of messages.\n *\n * @note - This function registers the message before the build process. The actual translation does not\n * occur until the m() function is invoked.\n *\n * @note - Message format\n * A message is broken into two parts separated by colons:\n * - interpolated content - the content with interpolated variables\n * - hash + options - a unique identifier for the source content and options for the translation\n *\n * @example - Basic usage\n *\n * const message1 = msg('Hello, World!');\n * console.log(message1); // \"Hello, World!\"\n *\n * const message2 = msg('Hello, {name}!', { name: 'Brian' });\n * console.log(message2); // \"Hello, Brian:eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9\"\n *\n * @example - Array usage\n *\n * const messages = msg(['Hello, Alice!', 'Hello, Bob!']);\n * console.log(messages); // [\"Hello, Alice!\", \"Hello, Bob!\"]\n *\n * @example - When specifying an id for an array, each message will have a unique id of `${id}.${index}`\n * const messages = msg(['Hello, Alice!', 'Hello, Bob!'], { $id: 'greetings' });\n * // \"Hello, Alice!\" id: \"greetings.0\"\n * // \"Hello, Bob!\" id: \"greetings.1\"\n *\n * @important Internal note: until other packages are updated to use i18n-context practices, msg cannot use any functions that use i18nCache at all!\n */\nexport function msg<T extends RegisterableMessages = string>(message: T): T;\nexport function msg<T extends RegisterableMessages = string>(\n message: T,\n options?: GTTranslationOptions\n): T extends string ? string : string[];\nexport function msg(\n message: RegisterableMessages,\n options?: GTTranslationOptions\n): RegisterableMessages {\n if (options?.$format === 'STRING') return msgString(message, options);\n\n // Handle array\n if (typeof message !== 'string') {\n if (!options) return message;\n return message.map((m, i) =>\n msg(m, {\n ...options,\n // ignore if $id is an empty string or not defined\n ...(options.$id && { $id: `${options.$id}.${i}` }),\n })\n );\n }\n\n if (!options) {\n return message;\n }\n\n const variables = extractVariables(options);\n let interpolatedString: string;\n try {\n interpolatedString = formatMessage(message, {\n locales: [libraryDefaultLocale], // TODO: use compiler to insert locales\n variables: {\n ...variables,\n [VAR_IDENTIFIER]: 'other',\n },\n });\n } catch {\n logger.warn(createInterpolationFailureMessage(message));\n return message;\n }\n\n // Encode options\n const $_source = message;\n const $_hash =\n options.$_hash ||\n hashMessage(message, {\n $format: 'ICU',\n ...options,\n });\n\n const encodedOptions: EncodedTranslationOptions = {\n ...options,\n $_source,\n $_hash,\n };\n return encodeMsg(interpolatedString, encodedOptions);\n}\n","/**\n * Extracts the original interpolated message string.\n * If the message cannot be decoded (i.e., it does not contain a colon separator),\n * the input is returned as-is.\n * @param encodedMsg The message to decode.\n * @returns The decoded message, or the input if it cannot be decoded.\n */\nexport function decodeMsg(encodedMsg: string): string;\nexport function decodeMsg<T extends null | undefined>(encodedMsg: T): T;\nexport function decodeMsg<T extends string | null | undefined>(\n encodedMsg: T\n): T extends string ? string : T;\nexport function decodeMsg<T extends string | null | undefined>(\n encodedMsg: T\n): string | T {\n if (typeof encodedMsg === 'string' && encodedMsg.lastIndexOf(':') !== -1) {\n return encodedMsg.slice(0, encodedMsg.lastIndexOf(':'));\n }\n return encodedMsg;\n}\n","import { GTTranslationOptions } from '../types/options';\nimport { GTFunctionType } from '../types/functions';\nimport { interpolateIcuMessage } from '../utils/interpolation/interpolateIcuMessage';\n\n/**\n * A fallback function for the gt() function that decodes and interpolates.\n * @param {string | null | undefined} message - The ICU formatted message to interpolate.\n * @param {GTTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @note This function is useful as a placeholder when for incrementally migrating to the m() function.\n * @example\n * // A backwards compatible translation function\n * function getMessage(gt: GTFunctionType = gtFallback) {\n * return gt('Hello, world!');\n * }\n *\n * // Here i18n has been implemented\n * function WithTranslation() {\n * const gt = useGT();\n * return <>{getMessage(gt)}</>;\n * }\n *\n *\n * // i18n has not yet been implemented yet\n * function WithoutTranslations() {\n * return <>{getMessage()}</>;\n * }\n */\nexport const gtFallback: GTFunctionType = <T extends string | null | undefined>(\n message: T,\n options: GTTranslationOptions = {}\n): T extends string ? string : T => {\n return interpolateIcuMessage(message, options);\n};\n","import { decodeMsg } from '../msg/decodeMsg';\nimport { GTTranslationOptions } from '../types/options';\nimport { MFunctionType } from '../types/functions';\nimport { decodeOptions } from '../msg/decodeOptions';\nimport { isEncodedTranslationOptions } from '../utils/isEncodedTranslationOptions';\nimport { interpolateIcuMessage } from '../utils/interpolation/interpolateIcuMessage';\n\n/**\n * A fallback function for the m() function that decodes and interpolates.\n * @param {string | null | undefined} encodedMsg - The encoded message to decode and interpolate.\n * @param {GTTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @note This function is useful as a placeholder when for incrementally migrating to the m() function.\n * @example\n * // A backwards compatible translation function\n * function getMessage(m: MFunctionType = mFallback) {\n * return m(msg('Hello, world!'));\n * }\n *\n * // Here i18n has been implemented\n * function WithTranslation() {\n * const m = useMessages();\n * return <>{getMessage(m)}</>;\n * }\n *\n *\n * // i18n has not yet been implemented yet\n * function WithoutTranslations() {\n * return <>{getMessage()}</>;\n * }\n */\nexport const mFallback: MFunctionType = <T extends string | null | undefined>(\n encodedMsg: T,\n options: GTTranslationOptions = {}\n): T extends string ? string : T => {\n // Return if the encoded message is null or undefined\n if (!encodedMsg) return encodedMsg as T extends string ? string : T;\n\n // Get any encoded options\n const decodedOptions = decodeOptions(encodedMsg) ?? {};\n\n // Return early if string already interpolated eg: mFallback(msg('Hello, {name}!', { name: 'Brian' }))\n if (isEncodedTranslationOptions(decodedOptions)) {\n // This is an encoded string, msg already interpolated, just return decoded string\n return decodeMsg(encodedMsg) as T extends string ? string : T;\n }\n\n // Not using decoded options to match behavior in @gt/react-core\n return interpolateIcuMessage(encodedMsg, options);\n};\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,KACX,kBACA,GAAG,WACA;AACH,KAAI,OAAO,qBAAqB,UAAU;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GAEH,GAAI,QAAQ,OAAO,EAAE,KAAK,GAAG,QAAQ,IAAI,GAAG,KAAK;GAClD,CAAC,CACH;;AAGH,KAAI,CAAC,QACH,QAAO;CAGT,MAAM,YAAY,iBAAiB,QAAQ;CAC3C,IAAI;AACJ,KAAI;AACF,uBAAqB,cAAc,SAAS;GAC1C,SAAS,CAAC,qBAAqB;GAC/B,WAAW;IACT,GAAG;KACF,iBAAiB;IACnB;GACF,CAAC;SACI;AACN,iBAAO,KAAK,kCAAkC,QAAQ,CAAC;AACvD,SAAO;;CAIT,MAAM,WAAW;CACjB,MAAM,SACJ,QAAQ,UACR,YAAY,SAAS;EACnB,SAAS;EACT,GAAG;EACJ,CAAC;CAEJ,MAAM,iBAA4C;EAChD,GAAG;EACH;EACA;EACD;AACD,QAAO,UAAU,oBAAoB,eAAe;;;;AC/FtD,SAAgB,UACd,YACY;AACZ,KAAI,OAAO,eAAe,YAAY,WAAW,YAAY,IAAI,KAAK,GACpE,QAAO,WAAW,MAAM,GAAG,WAAW,YAAY,IAAI,CAAC;AAEzD,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACWT,MAAa,cACX,SACA,UAAgC,EAAE,KACA;AAClC,QAAO,sBAAsB,SAAS,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACDhD,MAAa,aACX,YACA,UAAgC,EAAE,KACA;AAElC,KAAI,CAAC,WAAY,QAAO;AAMxB,KAAI,4BAHmB,cAAc,WAAW,IAAI,EAAE,CAGP,CAE7C,QAAO,UAAU,WAAW;AAI9B,QAAO,sBAAsB,YAAY,QAAQ"}
@@ -0,0 +1,51 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_request = require("./request-B4J2mLiA.cjs");
3
+ //#region src/utils/cookieNames.ts
4
+ /** Cookie name for tracking the user's selected locale. */
5
+ const defaultLocaleCookieName = "generaltranslation.locale";
6
+ /** Cookie name for tracking the user's selected region. */
7
+ const defaultRegionCookieName = "generaltranslation.region";
8
+ /** Cookie name for persisting the enable-i18n feature flag. */
9
+ const defaultEnableI18nCookieName = "generaltranslation.enable-i18n";
10
+ /** Cookie name for tracking an explicit locale reset. */
11
+ const defaultResetLocaleCookieName = "generaltranslation.locale-reset";
12
+ //#endregion
13
+ //#region src/utils/browserCookies.ts
14
+ /**
15
+ * Reads and decodes a browser cookie without accessing `document` during SSR.
16
+ *
17
+ * @param cookieName - Exact cookie name to read.
18
+ * @returns The decoded cookie value, or `undefined` outside a browser or when
19
+ * the cookie is absent.
20
+ */
21
+ function getBrowserCookieValue(cookieName) {
22
+ const cookieDocument = getCookieDocument();
23
+ return cookieDocument ? require_request.getCookieValue(cookieDocument.cookie, cookieName) : void 0;
24
+ }
25
+ /**
26
+ * Writes a path-wide browser session cookie without accessing `document`
27
+ * during SSR.
28
+ *
29
+ * The serialized form intentionally matches the existing GT React browser
30
+ * store so all web runtimes share the same cookie contract.
31
+ *
32
+ * @param cookieName - Cookie name to write.
33
+ * @param value - Raw cookie value to persist.
34
+ */
35
+ function setBrowserCookieValue(cookieName, value) {
36
+ const cookieDocument = getCookieDocument();
37
+ if (cookieDocument) cookieDocument.cookie = `${cookieName}=${value};path=/`;
38
+ }
39
+ function getCookieDocument() {
40
+ return globalThis.document;
41
+ }
42
+ //#endregion
43
+ exports.defaultEnableI18nCookieName = defaultEnableI18nCookieName;
44
+ exports.defaultLocaleCookieName = defaultLocaleCookieName;
45
+ exports.defaultRegionCookieName = defaultRegionCookieName;
46
+ exports.defaultResetLocaleCookieName = defaultResetLocaleCookieName;
47
+ exports.getBrowserCookieValue = getBrowserCookieValue;
48
+ exports.getCookieValue = require_request.getCookieValue;
49
+ exports.setBrowserCookieValue = setBrowserCookieValue;
50
+
51
+ //# sourceMappingURL=internal-cookies.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-cookies.cjs","names":["getCookieValue"],"sources":["../src/utils/cookieNames.ts","../src/utils/browserCookies.ts"],"sourcesContent":["/** Cookie name for tracking the user's selected locale. */\nexport const defaultLocaleCookieName = 'generaltranslation.locale';\n\n/** Cookie name for tracking the user's selected region. */\nexport const defaultRegionCookieName = 'generaltranslation.region';\n\n/** Cookie name for persisting the enable-i18n feature flag. */\nexport const defaultEnableI18nCookieName = 'generaltranslation.enable-i18n';\n\n/** Cookie name for tracking an explicit locale reset. */\nexport const defaultResetLocaleCookieName = 'generaltranslation.locale-reset';\n","import { getCookieValue } from './request';\n\ntype CookieDocument = {\n cookie: string;\n};\n\n/**\n * Reads and decodes a browser cookie without accessing `document` during SSR.\n *\n * @param cookieName - Exact cookie name to read.\n * @returns The decoded cookie value, or `undefined` outside a browser or when\n * the cookie is absent.\n */\nexport function getBrowserCookieValue(cookieName: string): string | undefined {\n const cookieDocument = getCookieDocument();\n return cookieDocument\n ? getCookieValue(cookieDocument.cookie, cookieName)\n : undefined;\n}\n\n/**\n * Writes a path-wide browser session cookie without accessing `document`\n * during SSR.\n *\n * The serialized form intentionally matches the existing GT React browser\n * store so all web runtimes share the same cookie contract.\n *\n * @param cookieName - Cookie name to write.\n * @param value - Raw cookie value to persist.\n */\nexport function setBrowserCookieValue(cookieName: string, value: string): void {\n const cookieDocument = getCookieDocument();\n if (cookieDocument) {\n cookieDocument.cookie = `${cookieName}=${value};path=/`;\n }\n}\n\nfunction getCookieDocument(): CookieDocument | undefined {\n return (\n globalThis as typeof globalThis & {\n document?: CookieDocument;\n }\n ).document;\n}\n"],"mappings":";;;;AACA,MAAa,0BAA0B;;AAGvC,MAAa,0BAA0B;;AAGvC,MAAa,8BAA8B;;AAG3C,MAAa,+BAA+B;;;;;;;;;;ACG5C,SAAgB,sBAAsB,YAAwC;CAC5E,MAAM,iBAAiB,mBAAmB;AAC1C,QAAO,iBACHA,gBAAAA,eAAe,eAAe,QAAQ,WAAW,GACjD,KAAA;;;;;;;;;;;;AAaN,SAAgB,sBAAsB,YAAoB,OAAqB;CAC7E,MAAM,iBAAiB,mBAAmB;AAC1C,KAAI,eACF,gBAAe,SAAS,GAAG,WAAW,GAAG,MAAM;;AAInD,SAAS,oBAAgD;AACvD,QACE,WAGA"}
@@ -0,0 +1,35 @@
1
+ import { t as getCookieValue } from "./request-B7giWTEv.cjs";
2
+
3
+ //#region src/utils/cookieNames.d.ts
4
+ /** Cookie name for tracking the user's selected locale. */
5
+ declare const defaultLocaleCookieName = "generaltranslation.locale";
6
+ /** Cookie name for tracking the user's selected region. */
7
+ declare const defaultRegionCookieName = "generaltranslation.region";
8
+ /** Cookie name for persisting the enable-i18n feature flag. */
9
+ declare const defaultEnableI18nCookieName = "generaltranslation.enable-i18n";
10
+ /** Cookie name for tracking an explicit locale reset. */
11
+ declare const defaultResetLocaleCookieName = "generaltranslation.locale-reset";
12
+ //#endregion
13
+ //#region src/utils/browserCookies.d.ts
14
+ /**
15
+ * Reads and decodes a browser cookie without accessing `document` during SSR.
16
+ *
17
+ * @param cookieName - Exact cookie name to read.
18
+ * @returns The decoded cookie value, or `undefined` outside a browser or when
19
+ * the cookie is absent.
20
+ */
21
+ declare function getBrowserCookieValue(cookieName: string): string | undefined;
22
+ /**
23
+ * Writes a path-wide browser session cookie without accessing `document`
24
+ * during SSR.
25
+ *
26
+ * The serialized form intentionally matches the existing GT React browser
27
+ * store so all web runtimes share the same cookie contract.
28
+ *
29
+ * @param cookieName - Cookie name to write.
30
+ * @param value - Raw cookie value to persist.
31
+ */
32
+ declare function setBrowserCookieValue(cookieName: string, value: string): void;
33
+ //#endregion
34
+ export { defaultEnableI18nCookieName, defaultLocaleCookieName, defaultRegionCookieName, defaultResetLocaleCookieName, getBrowserCookieValue, getCookieValue, setBrowserCookieValue };
35
+ //# sourceMappingURL=internal-cookies.d.cts.map
@@ -0,0 +1,35 @@
1
+ import { t as getCookieValue } from "./request-Bs7NclA3.mjs";
2
+
3
+ //#region src/utils/cookieNames.d.ts
4
+ /** Cookie name for tracking the user's selected locale. */
5
+ declare const defaultLocaleCookieName = "generaltranslation.locale";
6
+ /** Cookie name for tracking the user's selected region. */
7
+ declare const defaultRegionCookieName = "generaltranslation.region";
8
+ /** Cookie name for persisting the enable-i18n feature flag. */
9
+ declare const defaultEnableI18nCookieName = "generaltranslation.enable-i18n";
10
+ /** Cookie name for tracking an explicit locale reset. */
11
+ declare const defaultResetLocaleCookieName = "generaltranslation.locale-reset";
12
+ //#endregion
13
+ //#region src/utils/browserCookies.d.ts
14
+ /**
15
+ * Reads and decodes a browser cookie without accessing `document` during SSR.
16
+ *
17
+ * @param cookieName - Exact cookie name to read.
18
+ * @returns The decoded cookie value, or `undefined` outside a browser or when
19
+ * the cookie is absent.
20
+ */
21
+ declare function getBrowserCookieValue(cookieName: string): string | undefined;
22
+ /**
23
+ * Writes a path-wide browser session cookie without accessing `document`
24
+ * during SSR.
25
+ *
26
+ * The serialized form intentionally matches the existing GT React browser
27
+ * store so all web runtimes share the same cookie contract.
28
+ *
29
+ * @param cookieName - Cookie name to write.
30
+ * @param value - Raw cookie value to persist.
31
+ */
32
+ declare function setBrowserCookieValue(cookieName: string, value: string): void;
33
+ //#endregion
34
+ export { defaultEnableI18nCookieName, defaultLocaleCookieName, defaultRegionCookieName, defaultResetLocaleCookieName, getBrowserCookieValue, getCookieValue, setBrowserCookieValue };
35
+ //# sourceMappingURL=internal-cookies.d.mts.map