gt-i18n 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/{TranslationsCache-DQt4Es4G.d.cts → TranslationsCache-C12Vb-dZ.d.mts} +3 -4
  3. package/dist/{TranslationsCache-DdoHhP9C.d.mts → TranslationsCache-DKw8slPx.d.cts} +3 -4
  4. package/dist/fallbacks.cjs +1 -1
  5. package/dist/fallbacks.d.cts +1 -1
  6. package/dist/fallbacks.d.mts +1 -1
  7. package/dist/fallbacks.mjs +1 -1
  8. package/dist/{functions-DsYQxTQp.d.cts → functions-DI1QpQoC.d.cts} +3 -3
  9. package/dist/{functions-DdlVwVU8.d.mts → functions-Dojd5CfY.d.mts} +3 -3
  10. package/dist/{index-XRxZZ8E4.d.mts → index-B7BrS8Jn.d.mts} +2 -2
  11. package/dist/{index-v3fx8YUH.d.cts → index-BLWcN0wI.d.cts} +2 -2
  12. package/dist/index.cjs +5 -5
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +2 -2
  15. package/dist/index.d.mts +2 -2
  16. package/dist/index.mjs +4 -4
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/internal-types.d.cts +3 -3
  19. package/dist/internal-types.d.mts +3 -3
  20. package/dist/internal.cjs +69 -47
  21. package/dist/internal.cjs.map +1 -1
  22. package/dist/internal.d.cts +15 -11
  23. package/dist/internal.d.mts +15 -11
  24. package/dist/internal.mjs +65 -47
  25. package/dist/internal.mjs.map +1 -1
  26. package/dist/{isEncodedTranslationOptions-DdHEzDDM.mjs → isEncodedTranslationOptions-BOwWa_-J.mjs} +2 -2
  27. package/dist/isEncodedTranslationOptions-BOwWa_-J.mjs.map +1 -0
  28. package/dist/{isEncodedTranslationOptions-D7ltjc4f.cjs → isEncodedTranslationOptions-eqrZWcmP.cjs} +5 -5
  29. package/dist/isEncodedTranslationOptions-eqrZWcmP.cjs.map +1 -0
  30. package/dist/{localeResolver-DcN9SGPs.d.cts → localeResolver-CYvrEtm0.d.cts} +3 -3
  31. package/dist/{localeResolver-DPayN_xR.d.mts → localeResolver-Ci80ksxO.d.mts} +3 -3
  32. package/dist/{mFallback-CoPRtKyL.cjs → mFallback-DSBMUg3c.cjs} +2 -2
  33. package/dist/{mFallback-CoPRtKyL.cjs.map → mFallback-DSBMUg3c.cjs.map} +1 -1
  34. package/dist/{mFallback-BQX_yiE-.mjs → mFallback-pqVm9wDk.mjs} +2 -2
  35. package/dist/{mFallback-BQX_yiE-.mjs.map → mFallback-pqVm9wDk.mjs.map} +1 -1
  36. package/dist/{options-C1xolwBY.d.cts → options-CczghSzj.d.mts} +3 -3
  37. package/dist/{options-DeF1NEbe.d.mts → options-D0Lnxv2X.d.cts} +3 -3
  38. package/dist/types.d.cts +3 -3
  39. package/dist/types.d.mts +3 -3
  40. package/dist/{versionId-D0t6HuUM.mjs → versionId-B2xfz6jP.mjs} +50 -30
  41. package/dist/versionId-B2xfz6jP.mjs.map +1 -0
  42. package/dist/{versionId-qtCCdgKr.cjs → versionId-BZf-o3gk.cjs} +82 -38
  43. package/dist/versionId-BZf-o3gk.cjs.map +1 -0
  44. package/package.json +6 -5
  45. package/dist/isEncodedTranslationOptions-D7ltjc4f.cjs.map +0 -1
  46. package/dist/isEncodedTranslationOptions-DdHEzDDM.mjs.map +0 -1
  47. package/dist/versionId-D0t6HuUM.mjs.map +0 -1
  48. package/dist/versionId-qtCCdgKr.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # gt-i18n
2
2
 
3
+ ## 0.9.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1397](https://github.com/generaltranslation/gt/pull/1397) [`73f3ac1`](https://github.com/generaltranslation/gt/commit/73f3ac1308df11c1e6230c13c1999bfc5f6afc99) Thanks [@bgub](https://github.com/bgub)! - Extract locale and formatting primitives into the new `@generaltranslation/format` package and update `generaltranslation/core` to re-export the shared helpers.
8
+
9
+ - [#1409](https://github.com/generaltranslation/gt/pull/1409) [`8650ae9`](https://github.com/generaltranslation/gt/commit/8650ae9ced69755bf3eebc1bafdf7743ba0c5136) Thanks [@bgub](https://github.com/bgub)! - Prevent callers from mutating internal translation caches through `getInternalCache()` and start locale cache TTLs after async loads complete.
10
+
11
+ - Updated dependencies [[`73f3ac1`](https://github.com/generaltranslation/gt/commit/73f3ac1308df11c1e6230c13c1999bfc5f6afc99), [`425d3e4`](https://github.com/generaltranslation/gt/commit/425d3e4e6c61afd108c65c27f7693ba2470b33c6)]:
12
+ - @generaltranslation/format@0.1.0
13
+ - generaltranslation@8.2.14
14
+ - @generaltranslation/supported-locales@2.0.72
15
+
16
+ ## 0.9.1
17
+
18
+ ### Patch Changes
19
+
20
+ - [#1374](https://github.com/generaltranslation/gt/pull/1374) [`4d77edf`](https://github.com/generaltranslation/gt/commit/4d77edf7cb2bca5c20911c20c58f702803c9acc9) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - chore(gt-i18n): add comment documentation for t.obj()
21
+
22
+ - [#1380](https://github.com/generaltranslation/gt/pull/1380) [`feffb35`](https://github.com/generaltranslation/gt/commit/feffb35f75b3deee12e29878792461b8d32fad3e) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Export i18n manager cache-miss event-name constants from `gt-i18n/internal` so downstream packages such as `@generaltranslation/react-core` can consume one shared source of truth.
23
+
24
+ - [#1375](https://github.com/generaltranslation/gt/pull/1375) [`86263b3`](https://github.com/generaltranslation/gt/commit/86263b3aa8f2d283200515d609d69f570b97a84f) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Fix dictionary getTranslations fallback to use loaded translations when a target dictionary entry is missing.
25
+
26
+ - Updated dependencies [[`e88fd39`](https://github.com/generaltranslation/gt/commit/e88fd399683868d5af1fe2b0ba2974fe5b17d7a7), [`95f852a`](https://github.com/generaltranslation/gt/commit/95f852ae086ac79d2c446f4d3072d8fd18688796)]:
27
+ - generaltranslation@8.2.13
28
+ - @generaltranslation/supported-locales@2.0.71
29
+
3
30
  ## 0.9.0
4
31
 
5
32
  ### Minor Changes
@@ -1,7 +1,6 @@
1
- import { r as DictionaryOptions } from "./options-C1xolwBY.cjs";
2
- import { Content } from "generaltranslation/types";
1
+ import { r as DictionaryOptions } from "./options-CczghSzj.mjs";
3
2
  import { RuntimeTranslateManyOptions } from "generaltranslation/internal";
4
-
3
+ import { Content } from "@generaltranslation/format/types";
5
4
  //#region src/i18n-manager/translations-manager/utils/types/translation-data.d.ts
6
5
  /**
7
6
  * A single string translation
@@ -103,4 +102,4 @@ type TranslationBatchConfig = {
103
102
  type Hash = string;
104
103
  //#endregion
105
104
  export { Dictionary as a, DictionaryLeaf as c, DictionaryValue as d, Locale as f, DictionaryLoader as i, DictionaryObject as l, TranslationBatchConfig as n, DictionaryEntry as o, Translation as p, LifecycleCallbacks as r, DictionaryKey as s, Hash as t, DictionaryPath as u };
106
- //# sourceMappingURL=TranslationsCache-DQt4Es4G.d.cts.map
105
+ //# sourceMappingURL=TranslationsCache-C12Vb-dZ.d.mts.map
@@ -1,7 +1,6 @@
1
- import { r as DictionaryOptions } from "./options-DeF1NEbe.mjs";
1
+ import { r as DictionaryOptions } from "./options-D0Lnxv2X.cjs";
2
+ import { Content } from "@generaltranslation/format/types";
2
3
  import { RuntimeTranslateManyOptions } from "generaltranslation/internal";
3
- import { Content } from "generaltranslation/types";
4
-
5
4
  //#region src/i18n-manager/translations-manager/utils/types/translation-data.d.ts
6
5
  /**
7
6
  * A single string translation
@@ -103,4 +102,4 @@ type TranslationBatchConfig = {
103
102
  type Hash = string;
104
103
  //#endregion
105
104
  export { Dictionary as a, DictionaryLeaf as c, DictionaryValue as d, Locale as f, DictionaryLoader as i, DictionaryObject as l, TranslationBatchConfig as n, DictionaryEntry as o, Translation as p, LifecycleCallbacks as r, DictionaryKey as s, Hash as t, DictionaryPath as u };
106
- //# sourceMappingURL=TranslationsCache-DdoHhP9C.d.mts.map
105
+ //# sourceMappingURL=TranslationsCache-DKw8slPx.d.cts.map
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_mFallback = require("./mFallback-CoPRtKyL.cjs");
2
+ const require_mFallback = require("./mFallback-DSBMUg3c.cjs");
3
3
  exports.gtFallback = require_mFallback.gtFallback;
4
4
  exports.mFallback = require_mFallback.mFallback;
@@ -1,2 +1,2 @@
1
- import { n as gtFallback, t as mFallback } from "./index-v3fx8YUH.cjs";
1
+ import { n as gtFallback, t as mFallback } from "./index-BLWcN0wI.cjs";
2
2
  export { gtFallback, mFallback };
@@ -1,2 +1,2 @@
1
- import { n as gtFallback, t as mFallback } from "./index-XRxZZ8E4.mjs";
1
+ import { n as gtFallback, t as mFallback } from "./index-B7BrS8Jn.mjs";
2
2
  export { gtFallback, mFallback };
@@ -1,2 +1,2 @@
1
- import { n as gtFallback, t as mFallback } from "./mFallback-BQX_yiE-.mjs";
1
+ import { n as gtFallback, t as mFallback } from "./mFallback-pqVm9wDk.mjs";
2
2
  export { gtFallback, mFallback };
@@ -1,5 +1,5 @@
1
- import { c as JsxTranslationOptions, i as DictionaryTranslationOptions, s as InlineTranslationOptions } from "./options-C1xolwBY.cjs";
2
- import { JsxChildren } from "generaltranslation/types";
1
+ import { c as JsxTranslationOptions, i as DictionaryTranslationOptions, s as InlineTranslationOptions } from "./options-D0Lnxv2X.cjs";
2
+ import { JsxChildren } from "@generaltranslation/format/types";
3
3
 
4
4
  //#region src/translation-functions/types/functions.d.ts
5
5
  type DictionaryObjectTranslation = string | {
@@ -63,4 +63,4 @@ type TFunctionType = ((id: string, options?: DictionaryTranslationOptions) => st
63
63
  type ResolveJsxTranslationFunction = (locale: string, children: JsxChildren, options?: JsxTranslationOptions) => JsxChildren | undefined;
64
64
  //#endregion
65
65
  export { SyncResolutionFunction as a, ResolveJsxTranslationFunction as i, GTFunctionType as n, SyncResolutionFunctionWithFallback as o, MFunctionType as r, TFunctionType as s, DictionaryObjectTranslation as t };
66
- //# sourceMappingURL=functions-DsYQxTQp.d.cts.map
66
+ //# sourceMappingURL=functions-DI1QpQoC.d.cts.map
@@ -1,5 +1,5 @@
1
- import { c as JsxTranslationOptions, i as DictionaryTranslationOptions, s as InlineTranslationOptions } from "./options-DeF1NEbe.mjs";
2
- import { JsxChildren } from "generaltranslation/types";
1
+ import { c as JsxTranslationOptions, i as DictionaryTranslationOptions, s as InlineTranslationOptions } from "./options-CczghSzj.mjs";
2
+ import { JsxChildren } from "@generaltranslation/format/types";
3
3
 
4
4
  //#region src/translation-functions/types/functions.d.ts
5
5
  type DictionaryObjectTranslation = string | {
@@ -63,4 +63,4 @@ type TFunctionType = ((id: string, options?: DictionaryTranslationOptions) => st
63
63
  type ResolveJsxTranslationFunction = (locale: string, children: JsxChildren, options?: JsxTranslationOptions) => JsxChildren | undefined;
64
64
  //#endregion
65
65
  export { SyncResolutionFunction as a, ResolveJsxTranslationFunction as i, GTFunctionType as n, SyncResolutionFunctionWithFallback as o, MFunctionType as r, TFunctionType as s, DictionaryObjectTranslation as t };
66
- //# sourceMappingURL=functions-DdlVwVU8.d.mts.map
66
+ //# sourceMappingURL=functions-Dojd5CfY.d.mts.map
@@ -1,4 +1,4 @@
1
- import { n as GTFunctionType, r as MFunctionType } from "./functions-DdlVwVU8.mjs";
1
+ import { n as GTFunctionType, r as MFunctionType } from "./functions-Dojd5CfY.mjs";
2
2
 
3
3
  //#region src/translation-functions/fallbacks/gtFallback.d.ts
4
4
  /**
@@ -57,4 +57,4 @@ declare const gtFallback: GTFunctionType;
57
57
  declare const mFallback: MFunctionType;
58
58
  //#endregion
59
59
  export { gtFallback as n, mFallback as t };
60
- //# sourceMappingURL=index-XRxZZ8E4.d.mts.map
60
+ //# sourceMappingURL=index-B7BrS8Jn.d.mts.map
@@ -1,4 +1,4 @@
1
- import { n as GTFunctionType, r as MFunctionType } from "./functions-DsYQxTQp.cjs";
1
+ import { n as GTFunctionType, r as MFunctionType } from "./functions-DI1QpQoC.cjs";
2
2
 
3
3
  //#region src/translation-functions/fallbacks/gtFallback.d.ts
4
4
  /**
@@ -57,4 +57,4 @@ declare const gtFallback: GTFunctionType;
57
57
  declare const mFallback: MFunctionType;
58
58
  //#endregion
59
59
  export { gtFallback as n, mFallback as t };
60
- //# sourceMappingURL=index-v3fx8YUH.d.cts.map
60
+ //# sourceMappingURL=index-BLWcN0wI.d.cts.map
package/dist/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_isEncodedTranslationOptions = require("./isEncodedTranslationOptions-D7ltjc4f.cjs");
3
- const require_versionId = require("./versionId-qtCCdgKr.cjs");
4
- const require_mFallback = require("./mFallback-CoPRtKyL.cjs");
2
+ const require_isEncodedTranslationOptions = require("./isEncodedTranslationOptions-eqrZWcmP.cjs");
3
+ const require_versionId = require("./versionId-BZf-o3gk.cjs");
4
+ const require_mFallback = require("./mFallback-DSBMUg3c.cjs");
5
5
  let generaltranslation_internal = require("generaltranslation/internal");
6
- let generaltranslation_core = require("generaltranslation/core");
6
+ let _generaltranslation_format = require("@generaltranslation/format");
7
7
  //#region src/translation-functions/t.ts
8
8
  /**
9
9
  * Translate a message
@@ -31,7 +31,7 @@ function msg(message, options) {
31
31
  const variables = require_isEncodedTranslationOptions.extractVariables(options);
32
32
  let interpolatedString = message;
33
33
  try {
34
- interpolatedString = (0, generaltranslation_core.formatMessage)(message, {
34
+ interpolatedString = (0, _generaltranslation_format.formatMessage)(message, {
35
35
  locales: [generaltranslation_internal.libraryDefaultLocale],
36
36
  variables: {
37
37
  ...variables,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["resolveStringContentWithFallback","getCurrentLocale","extractVariables","libraryDefaultLocale","VAR_IDENTIFIER","createInterpolationFailureMessage","hashMessage"],"sources":["../src/translation-functions/t.ts","../src/translation-functions/msg/msg.ts"],"sourcesContent":["import { resolveStringContentWithFallback } from './internal/helpers';\nimport { InlineTranslationOptions } from './types/options';\nimport { getCurrentLocale } from '../i18n-manager/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 function t(message: string, options: InlineTranslationOptions = {}) {\n const locale = options.$locale ?? getCurrentLocale();\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...options,\n });\n}\n","import type {\n EncodedTranslationOptions,\n InlineTranslationOptions,\n} from '../types/options';\nimport { formatMessage } from 'generaltranslation/core';\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 {InlineTranslationOptions} [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 i18nManager 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?: InlineTranslationOptions\n): T extends string ? string : string[];\nexport function msg(\n message: RegisterableMessages,\n options?: InlineTranslationOptions\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"],"mappings":";;;;;;;;;;;;;AAUA,SAAgB,EAAE,SAAiB,UAAoC,EAAE,EAAE;AAEzE,QAAOA,kBAAAA,iCADQ,QAAQ,WAAWC,kBAAAA,kBAAkB,EACJ,SAAS;EACvD,SAAS;EACT,GAAG;EACJ,CAAC;;;;ACwCJ,SAAgB,IACd,SACA,SACsB;AAEtB,KAAI,OAAO,YAAY,UAAU;AAC/B,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,KAAK,GAAG,MACrB,IAAI,GAAG;GACL,GAAG;GAEH,GAAI,QAAQ,OAAO,EAAE,KAAK,GAAG,QAAQ,IAAI,GAAG,KAAK;GAClD,CAAC,CACH;;AAGH,KAAI,CAAC,QACH,QAAO;CAIT,MAAM,YAAYC,oCAAAA,iBAAiB,QAAQ;CAG3C,IAAI,qBAA6B;AACjC,KAAI;AACF,wBAAA,GAAA,wBAAA,eAAmC,SAAS;GAC1C,SAAS,CAACC,4BAAAA,qBAAqB;GAC/B,WAAW;IACT,GAAG;KACFC,4BAAAA,iBAAiB;IACnB;GACF,CAAC;SACI;AACN,sCAAA,eAAO,KAAKC,oCAAAA,kCAAkC,QAAQ,CAAC;AACvD,SAAO;;CAIT,MAAM,WAAW;CACjB,MAAM,SACJ,QAAQ,UACRC,kBAAAA,YAAY,SAAS;EACnB,SAAS;EACT,GAAG;EACJ,CAAC;CAEJ,MAAM,iBAA4C;EAChD,GAAG;EACH;EACA;EACD;CACD,MAAM,mBAAA,GAAA,4BAAA,QAAyB,KAAK,UAAU,eAAe,CAAC;AAG9D,QAAO,GAAG,mBAAmB,GAAG"}
1
+ {"version":3,"file":"index.cjs","names":["resolveStringContentWithFallback","getCurrentLocale","extractVariables","libraryDefaultLocale","VAR_IDENTIFIER","createInterpolationFailureMessage","hashMessage"],"sources":["../src/translation-functions/t.ts","../src/translation-functions/msg/msg.ts"],"sourcesContent":["import { resolveStringContentWithFallback } from './internal/helpers';\nimport { InlineTranslationOptions } from './types/options';\nimport { getCurrentLocale } from '../i18n-manager/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 function t(message: string, options: InlineTranslationOptions = {}) {\n const locale = options.$locale ?? getCurrentLocale();\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...options,\n });\n}\n","import type {\n EncodedTranslationOptions,\n InlineTranslationOptions,\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 {InlineTranslationOptions} [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 i18nManager 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?: InlineTranslationOptions\n): T extends string ? string : string[];\nexport function msg(\n message: RegisterableMessages,\n options?: InlineTranslationOptions\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"],"mappings":";;;;;;;;;;;;;AAUA,SAAgB,EAAE,SAAiB,UAAoC,EAAE,EAAE;AAEzE,QAAOA,kBAAAA,iCADQ,QAAQ,WAAWC,kBAAAA,kBAAkB,EACJ,SAAS;EACvD,SAAS;EACT,GAAG;EACJ,CAAC;;;;ACwCJ,SAAgB,IACd,SACA,SACsB;AAEtB,KAAI,OAAO,YAAY,UAAU;AAC/B,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,KAAK,GAAG,MACrB,IAAI,GAAG;GACL,GAAG;GAEH,GAAI,QAAQ,OAAO,EAAE,KAAK,GAAG,QAAQ,IAAI,GAAG,KAAK;GAClD,CAAC,CACH;;AAGH,KAAI,CAAC,QACH,QAAO;CAIT,MAAM,YAAYC,oCAAAA,iBAAiB,QAAQ;CAG3C,IAAI,qBAA6B;AACjC,KAAI;AACF,wBAAA,GAAA,2BAAA,eAAmC,SAAS;GAC1C,SAAS,CAACC,4BAAAA,qBAAqB;GAC/B,WAAW;IACT,GAAG;KACFC,4BAAAA,iBAAiB;IACnB;GACF,CAAC;SACI;AACN,sCAAA,eAAO,KAAKC,oCAAAA,kCAAkC,QAAQ,CAAC;AACvD,SAAO;;CAIT,MAAM,WAAW;CACjB,MAAM,SACJ,QAAQ,UACRC,kBAAAA,YAAY,SAAS;EACnB,SAAS;EACT,GAAG;EACJ,CAAC;CAEJ,MAAM,iBAA4C;EAChD,GAAG;EACH;EACA;EACD;CACD,MAAM,mBAAA,GAAA,4BAAA,QAAyB,KAAK,UAAU,eAAe,CAAC;AAG9D,QAAO,GAAG,mBAAmB,GAAG"}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { s as InlineTranslationOptions } from "./options-C1xolwBY.cjs";
2
- import { n as gtFallback, t as mFallback } from "./index-v3fx8YUH.cjs";
1
+ import { s as InlineTranslationOptions } from "./options-D0Lnxv2X.cjs";
2
+ import { n as gtFallback, t as mFallback } from "./index-BLWcN0wI.cjs";
3
3
  import { t as RegisterableMessages } from "./message-C62MTLwE.cjs";
4
4
  import { a as getLocales, i as getLocaleProperties, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./index-UDlCzB02.cjs";
5
5
  import { declareStatic, declareVar, decodeVars, derive } from "generaltranslation/internal";
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { s as InlineTranslationOptions } from "./options-DeF1NEbe.mjs";
2
- import { n as gtFallback, t as mFallback } from "./index-XRxZZ8E4.mjs";
1
+ import { s as InlineTranslationOptions } from "./options-CczghSzj.mjs";
2
+ import { n as gtFallback, t as mFallback } from "./index-B7BrS8Jn.mjs";
3
3
  import { t as RegisterableMessages } from "./message-BN4DirTg.mjs";
4
4
  import { a as getLocales, i as getLocaleProperties, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./index-Bc5qKE7T.mjs";
5
5
  import { declareStatic, declareVar, decodeVars, derive } from "generaltranslation/internal";
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { a as extractVariables, i as createInterpolationFailureMessage, n as decodeOptions, o as logger_default } from "./isEncodedTranslationOptions-DdHEzDDM.mjs";
2
- import { S as hashMessage, a as getLocales, d as resolveStringContentWithFallback, i as getLocaleProperties, m as getCurrentLocale, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./versionId-D0t6HuUM.mjs";
3
- import { n as gtFallback, r as decodeMsg, t as mFallback } from "./mFallback-BQX_yiE-.mjs";
1
+ import { a as extractVariables, i as createInterpolationFailureMessage, n as decodeOptions, o as logger_default } from "./isEncodedTranslationOptions-BOwWa_-J.mjs";
2
+ import { E as hashMessage, a as getLocales, d as resolveStringContentWithFallback, i as getLocaleProperties, m as getCurrentLocale, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./versionId-B2xfz6jP.mjs";
3
+ import { n as gtFallback, r as decodeMsg, t as mFallback } from "./mFallback-pqVm9wDk.mjs";
4
4
  import { VAR_IDENTIFIER, declareStatic, declareVar, decodeVars, derive, encode, libraryDefaultLocale } from "generaltranslation/internal";
5
- import { formatMessage } from "generaltranslation/core";
5
+ import { formatMessage } from "@generaltranslation/format";
6
6
  //#region src/translation-functions/t.ts
7
7
  /**
8
8
  * Translate a message
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/translation-functions/t.ts","../src/translation-functions/msg/msg.ts"],"sourcesContent":["import { resolveStringContentWithFallback } from './internal/helpers';\nimport { InlineTranslationOptions } from './types/options';\nimport { getCurrentLocale } from '../i18n-manager/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 function t(message: string, options: InlineTranslationOptions = {}) {\n const locale = options.$locale ?? getCurrentLocale();\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...options,\n });\n}\n","import type {\n EncodedTranslationOptions,\n InlineTranslationOptions,\n} from '../types/options';\nimport { formatMessage } from 'generaltranslation/core';\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 {InlineTranslationOptions} [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 i18nManager 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?: InlineTranslationOptions\n): T extends string ? string : string[];\nexport function msg(\n message: RegisterableMessages,\n options?: InlineTranslationOptions\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"],"mappings":";;;;;;;;;;;;AAUA,SAAgB,EAAE,SAAiB,UAAoC,EAAE,EAAE;AAEzE,QAAO,iCADQ,QAAQ,WAAW,kBAAkB,EACJ,SAAS;EACvD,SAAS;EACT,GAAG;EACJ,CAAC;;;;ACwCJ,SAAgB,IACd,SACA,SACsB;AAEtB,KAAI,OAAO,YAAY,UAAU;AAC/B,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,KAAK,GAAG,MACrB,IAAI,GAAG;GACL,GAAG;GAEH,GAAI,QAAQ,OAAO,EAAE,KAAK,GAAG,QAAQ,IAAI,GAAG,KAAK;GAClD,CAAC,CACH;;AAGH,KAAI,CAAC,QACH,QAAO;CAIT,MAAM,YAAY,iBAAiB,QAAQ;CAG3C,IAAI,qBAA6B;AACjC,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;CACD,MAAM,kBAAkB,OAAO,KAAK,UAAU,eAAe,CAAC;AAG9D,QAAO,GAAG,mBAAmB,GAAG"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/translation-functions/t.ts","../src/translation-functions/msg/msg.ts"],"sourcesContent":["import { resolveStringContentWithFallback } from './internal/helpers';\nimport { InlineTranslationOptions } from './types/options';\nimport { getCurrentLocale } from '../i18n-manager/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 function t(message: string, options: InlineTranslationOptions = {}) {\n const locale = options.$locale ?? getCurrentLocale();\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...options,\n });\n}\n","import type {\n EncodedTranslationOptions,\n InlineTranslationOptions,\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 {InlineTranslationOptions} [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 i18nManager 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?: InlineTranslationOptions\n): T extends string ? string : string[];\nexport function msg(\n message: RegisterableMessages,\n options?: InlineTranslationOptions\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"],"mappings":";;;;;;;;;;;;AAUA,SAAgB,EAAE,SAAiB,UAAoC,EAAE,EAAE;AAEzE,QAAO,iCADQ,QAAQ,WAAW,kBAAkB,EACJ,SAAS;EACvD,SAAS;EACT,GAAG;EACJ,CAAC;;;;ACwCJ,SAAgB,IACd,SACA,SACsB;AAEtB,KAAI,OAAO,YAAY,UAAU;AAC/B,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,KAAK,GAAG,MACrB,IAAI,GAAG;GACL,GAAG;GAEH,GAAI,QAAQ,OAAO,EAAE,KAAK,GAAG,QAAQ,IAAI,GAAG,KAAK;GAClD,CAAC,CACH;;AAGH,KAAI,CAAC,QACH,QAAO;CAIT,MAAM,YAAY,iBAAiB,QAAQ;CAG3C,IAAI,qBAA6B;AACjC,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;CACD,MAAM,kBAAkB,OAAO,KAAK,UAAU,eAAe,CAAC;AAG9D,QAAO,GAAG,mBAAmB,GAAG"}
@@ -1,4 +1,4 @@
1
- import { a as EncodedTranslationOptions, c as JsxTranslationOptions, d as ResolutionOptions, f as RuntimeTranslationOptions, i as DictionaryTranslationOptions, l as LookupOptions, n as DictionaryLookupOptions, o as InlineResolveOptions, r as DictionaryOptions, s as InlineTranslationOptions, t as BaseTranslationOptions, u as NormalizedLookupOptions } from "./options-C1xolwBY.cjs";
2
- import { a as ConditionStore, c as I18nManagerConfig, d as WritableConditionStore, f as TranslationsLoader, l as I18nManagerConstructorParams, m as RenderMethod, o as ConditionStoreConfig, p as GTConfig, s as DictionaryConfig, t as LocaleCandidates, u as ScopedConditionStore } from "./localeResolver-DcN9SGPs.cjs";
3
- import { a as Dictionary, c as DictionaryLeaf, d as DictionaryValue, i as DictionaryLoader, l as DictionaryObject, o as DictionaryEntry, r as LifecycleCallbacks, s as DictionaryKey, u as DictionaryPath } from "./TranslationsCache-DQt4Es4G.cjs";
1
+ import { a as EncodedTranslationOptions, c as JsxTranslationOptions, d as ResolutionOptions, f as RuntimeTranslationOptions, i as DictionaryTranslationOptions, l as LookupOptions, n as DictionaryLookupOptions, o as InlineResolveOptions, r as DictionaryOptions, s as InlineTranslationOptions, t as BaseTranslationOptions, u as NormalizedLookupOptions } from "./options-D0Lnxv2X.cjs";
2
+ import { a as ConditionStore, c as I18nManagerConfig, d as WritableConditionStore, f as TranslationsLoader, l as I18nManagerConstructorParams, m as RenderMethod, o as ConditionStoreConfig, p as GTConfig, s as DictionaryConfig, t as LocaleCandidates, u as ScopedConditionStore } from "./localeResolver-CYvrEtm0.cjs";
3
+ import { a as Dictionary, c as DictionaryLeaf, d as DictionaryValue, i as DictionaryLoader, l as DictionaryObject, o as DictionaryEntry, r as LifecycleCallbacks, s as DictionaryKey, u as DictionaryPath } from "./TranslationsCache-DKw8slPx.cjs";
4
4
  export { BaseTranslationOptions, type ConditionStore, type ConditionStoreConfig, type Dictionary, type DictionaryConfig, type DictionaryEntry, type DictionaryKey, type DictionaryLeaf, type DictionaryLoader, DictionaryLookupOptions, type DictionaryObject, type DictionaryOptions, type DictionaryPath, DictionaryTranslationOptions, type DictionaryValue, EncodedTranslationOptions, GTConfig, type I18nManagerConfig, type I18nManagerConstructorParams, InlineResolveOptions, InlineTranslationOptions, JsxTranslationOptions, type LifecycleCallbacks, type LocaleCandidates, LookupOptions, NormalizedLookupOptions, RenderMethod, ResolutionOptions, RuntimeTranslationOptions, type ScopedConditionStore, type TranslationsLoader, type WritableConditionStore };
@@ -1,4 +1,4 @@
1
- import { a as EncodedTranslationOptions, c as JsxTranslationOptions, d as ResolutionOptions, f as RuntimeTranslationOptions, i as DictionaryTranslationOptions, l as LookupOptions, n as DictionaryLookupOptions, o as InlineResolveOptions, r as DictionaryOptions, s as InlineTranslationOptions, t as BaseTranslationOptions, u as NormalizedLookupOptions } from "./options-DeF1NEbe.mjs";
2
- import { a as ConditionStore, c as I18nManagerConfig, d as WritableConditionStore, f as TranslationsLoader, l as I18nManagerConstructorParams, m as RenderMethod, o as ConditionStoreConfig, p as GTConfig, s as DictionaryConfig, t as LocaleCandidates, u as ScopedConditionStore } from "./localeResolver-DPayN_xR.mjs";
3
- import { a as Dictionary, c as DictionaryLeaf, d as DictionaryValue, i as DictionaryLoader, l as DictionaryObject, o as DictionaryEntry, r as LifecycleCallbacks, s as DictionaryKey, u as DictionaryPath } from "./TranslationsCache-DdoHhP9C.mjs";
1
+ import { a as EncodedTranslationOptions, c as JsxTranslationOptions, d as ResolutionOptions, f as RuntimeTranslationOptions, i as DictionaryTranslationOptions, l as LookupOptions, n as DictionaryLookupOptions, o as InlineResolveOptions, r as DictionaryOptions, s as InlineTranslationOptions, t as BaseTranslationOptions, u as NormalizedLookupOptions } from "./options-CczghSzj.mjs";
2
+ import { a as ConditionStore, c as I18nManagerConfig, d as WritableConditionStore, f as TranslationsLoader, l as I18nManagerConstructorParams, m as RenderMethod, o as ConditionStoreConfig, p as GTConfig, s as DictionaryConfig, t as LocaleCandidates, u as ScopedConditionStore } from "./localeResolver-Ci80ksxO.mjs";
3
+ import { a as Dictionary, c as DictionaryLeaf, d as DictionaryValue, i as DictionaryLoader, l as DictionaryObject, o as DictionaryEntry, r as LifecycleCallbacks, s as DictionaryKey, u as DictionaryPath } from "./TranslationsCache-C12Vb-dZ.mjs";
4
4
  export { BaseTranslationOptions, type ConditionStore, type ConditionStoreConfig, type Dictionary, type DictionaryConfig, type DictionaryEntry, type DictionaryKey, type DictionaryLeaf, type DictionaryLoader, DictionaryLookupOptions, type DictionaryObject, type DictionaryOptions, type DictionaryPath, DictionaryTranslationOptions, type DictionaryValue, EncodedTranslationOptions, GTConfig, type I18nManagerConfig, type I18nManagerConstructorParams, InlineResolveOptions, InlineTranslationOptions, JsxTranslationOptions, type LifecycleCallbacks, type LocaleCandidates, LookupOptions, NormalizedLookupOptions, RenderMethod, ResolutionOptions, RuntimeTranslationOptions, type ScopedConditionStore, type TranslationsLoader, type WritableConditionStore };
package/dist/internal.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_isEncodedTranslationOptions = require("./isEncodedTranslationOptions-D7ltjc4f.cjs");
3
- const require_versionId = require("./versionId-qtCCdgKr.cjs");
2
+ const require_isEncodedTranslationOptions = require("./isEncodedTranslationOptions-eqrZWcmP.cjs");
3
+ const require_versionId = require("./versionId-BZf-o3gk.cjs");
4
4
  let generaltranslation_internal = require("generaltranslation/internal");
5
- let generaltranslation_core = require("generaltranslation/core");
5
+ let _generaltranslation_format = require("@generaltranslation/format");
6
6
  //#region src/translation-functions/internal/getGT.ts
7
7
  /**
8
8
  * Returns the gt function that registers a string at build time and resolves its translation at runtime.
@@ -98,7 +98,7 @@ async function getMessages() {
98
98
  async function getTranslations() {
99
99
  const i18nManager = require_versionId.getI18nManager();
100
100
  const locale = require_versionId.getCurrentLocale();
101
- await i18nManager.loadDictionary(locale);
101
+ await Promise.all([i18nManager.loadDictionary(locale), i18nManager.loadTranslations(locale)]);
102
102
  const sourceLocale = i18nManager.getDefaultLocale();
103
103
  /**
104
104
  * Dictionary resolution
@@ -119,14 +119,28 @@ async function getTranslations() {
119
119
  const t = ((id, options = {}) => {
120
120
  const sourceEntry = i18nManager.lookupDictionary(sourceLocale, id);
121
121
  if (sourceEntry === void 0) throw new Error(`Dictionary entry ${id} cannot be found`);
122
+ const targetEntry = i18nManager.lookupDictionary(locale, id);
123
+ const dictionaryOptions = require_versionId.resolveDictionaryLookupOptions(sourceEntry.options);
122
124
  return renderEntry({
123
125
  sourceLocale,
124
126
  targetLocale: locale,
125
127
  sourceEntry,
126
- targetEntry: i18nManager.lookupDictionary(locale, id),
128
+ target: targetEntry?.entry ?? i18nManager.lookupTranslation(locale, sourceEntry.entry, dictionaryOptions),
129
+ dictionaryOptions,
127
130
  options
128
131
  });
129
132
  });
133
+ /**
134
+ * Returns a subtree of the dictionary object translation based on its id.
135
+ * @param {string} id - The id of the translation to translate.
136
+ * @returns The translated object.
137
+ *
138
+ * @example
139
+ * const t = await getTranslations();
140
+ * const greetings = t.obj('greetings');
141
+ * console.log(greetings);
142
+ * // { greeting1: 'Hello', greeting2: 'Hi' }
143
+ */
130
144
  t.obj = (id) => {
131
145
  const sourceObject = i18nManager.lookupDictionaryObj(sourceLocale, id);
132
146
  if (sourceObject === void 0) throw new Error(`Dictionary entry ${id} cannot be found`);
@@ -135,10 +149,51 @@ async function getTranslations() {
135
149
  targetObject: i18nManager.lookupDictionaryObj(locale, id)
136
150
  });
137
151
  };
152
+ function renderObject({ sourceObject, targetObject }) {
153
+ const targetEntry = require_versionId.getDictionaryEntry(targetObject);
154
+ if (targetEntry !== void 0) return targetEntry.entry;
155
+ if (require_versionId.isDictionaryValue(targetObject)) {
156
+ if (!require_versionId.isDictionaryValue(sourceObject)) return renderObject({
157
+ sourceObject: targetObject,
158
+ targetObject: void 0
159
+ });
160
+ return renderDictionaryObject({
161
+ sourceObject,
162
+ targetObject
163
+ });
164
+ }
165
+ const sourceEntry = require_versionId.getDictionaryEntry(sourceObject);
166
+ if (sourceEntry !== void 0) {
167
+ const dictionaryOptions = require_versionId.resolveDictionaryLookupOptions(sourceEntry.options);
168
+ const target = i18nManager.lookupTranslation(locale, sourceEntry.entry, dictionaryOptions);
169
+ if (target !== void 0) return target;
170
+ return sourceEntry.entry;
171
+ }
172
+ if (require_versionId.isDictionaryValue(sourceObject)) return renderDictionaryObject({
173
+ sourceObject,
174
+ targetObject: void 0
175
+ });
176
+ throw new Error("Dictionary object cannot be rendered");
177
+ }
178
+ function renderDictionaryObject({ sourceObject, targetObject }) {
179
+ if (!require_versionId.isDictionaryValue(sourceObject)) return renderObject({
180
+ sourceObject,
181
+ targetObject
182
+ });
183
+ const result = {};
184
+ const keys = new Set([...Object.keys(sourceObject), ...require_versionId.isDictionaryValue(targetObject) ? Object.keys(targetObject) : []]);
185
+ for (const key of Array.from(keys)) {
186
+ const renderedChild = renderObject({
187
+ sourceObject: sourceObject[key],
188
+ targetObject: require_versionId.isDictionaryValue(targetObject) ? targetObject[key] : void 0
189
+ });
190
+ if (renderedChild !== void 0) result[key] = renderedChild;
191
+ }
192
+ return result;
193
+ }
138
194
  return t;
139
195
  }
140
- function renderEntry({ sourceLocale, targetLocale, sourceEntry, targetEntry, options = {} }) {
141
- const dictionaryOptions = require_versionId.resolveDictionaryLookupOptions(sourceEntry.options);
196
+ function renderEntry({ sourceLocale, targetLocale, sourceEntry, target, dictionaryOptions, options = {} }) {
142
197
  const interpolationOptions = require_isEncodedTranslationOptions.extractVariables(options);
143
198
  const lookupOptions = require_versionId.createLookupOptions(targetLocale, {
144
199
  ...dictionaryOptions,
@@ -146,48 +201,11 @@ function renderEntry({ sourceLocale, targetLocale, sourceEntry, targetEntry, opt
146
201
  }, dictionaryOptions.$format ?? "ICU");
147
202
  return require_versionId.interpolateMessage({
148
203
  source: sourceEntry.entry,
149
- target: targetEntry?.entry,
204
+ target,
150
205
  options: lookupOptions,
151
206
  sourceLocale
152
207
  });
153
208
  }
154
- function renderObject({ sourceObject, targetObject }) {
155
- const targetEntry = require_versionId.getDictionaryEntry(targetObject);
156
- if (targetEntry !== void 0) return targetEntry.entry;
157
- if (require_versionId.isDictionaryValue(targetObject)) {
158
- if (!require_versionId.isDictionaryValue(sourceObject)) return renderObject({
159
- sourceObject: targetObject,
160
- targetObject: void 0
161
- });
162
- return renderDictionaryObject({
163
- sourceObject,
164
- targetObject
165
- });
166
- }
167
- const sourceEntry = require_versionId.getDictionaryEntry(sourceObject);
168
- if (sourceEntry !== void 0) return sourceEntry.entry;
169
- if (require_versionId.isDictionaryValue(sourceObject)) return renderDictionaryObject({
170
- sourceObject,
171
- targetObject: void 0
172
- });
173
- throw new Error("Dictionary object cannot be rendered");
174
- }
175
- function renderDictionaryObject({ sourceObject, targetObject }) {
176
- if (!require_versionId.isDictionaryValue(sourceObject)) return renderObject({
177
- sourceObject,
178
- targetObject
179
- });
180
- const result = {};
181
- const keys = new Set([...Object.keys(sourceObject), ...require_versionId.isDictionaryValue(targetObject) ? Object.keys(targetObject) : []]);
182
- for (const key of keys) {
183
- const renderedChild = renderObject({
184
- sourceObject: sourceObject[key],
185
- targetObject: require_versionId.isDictionaryValue(targetObject) ? targetObject[key] : void 0
186
- });
187
- if (renderedChild !== void 0) result[key] = renderedChild;
188
- }
189
- return result;
190
- }
191
209
  //#endregion
192
210
  //#region src/translation-functions/internal/tx.ts
193
211
  /**
@@ -205,7 +223,7 @@ function renderDictionaryObject({ sourceObject, targetObject }) {
205
223
  * const progress = await tx(`Processing ${status}`, { $locale: 'es-MX' });
206
224
  */
207
225
  async function tx(content, options = {}) {
208
- return require_versionId.resolveStringContentWithRuntimeFallback(options.$locale ?? require_versionId.getCurrentLocale(), content, {
226
+ return require_versionId.resolveStringContentWithRuntimeFallback(typeof options.$locale === "string" ? options.$locale : require_versionId.getCurrentLocale(), content, {
209
227
  $format: "STRING",
210
228
  ...options
211
229
  });
@@ -282,7 +300,7 @@ function determineSupportedLocale(candidates, config = {}) {
282
300
  }
283
301
  function determineSupportedLocaleWithConfig(candidates, config) {
284
302
  if (candidates == null || Array.isArray(candidates) && candidates.length === 0) return;
285
- return new generaltranslation_core.LocaleConfig(config).determineLocale(candidates) || void 0;
303
+ return new _generaltranslation_format.LocaleConfig(config).determineLocale(candidates) || void 0;
286
304
  }
287
305
  /**
288
306
  * Return the best supported locale for the candidates, falling back to the default locale.
@@ -296,7 +314,11 @@ function createLocaleResolver(config = {}) {
296
314
  return (candidates) => determineSupportedLocaleWithConfig(candidates, normalizedConfig) || normalizedConfig.defaultLocale;
297
315
  }
298
316
  //#endregion
317
+ exports.DICTIONARY_CACHE_MISS_EVENT_NAME = require_versionId.DICTIONARY_CACHE_MISS_EVENT_NAME;
299
318
  exports.I18nManager = require_versionId.I18nManager;
319
+ exports.LOCALES_CACHE_MISS_EVENT_NAME = require_versionId.LOCALES_CACHE_MISS_EVENT_NAME;
320
+ exports.LOCALES_DICTIONARY_CACHE_MISS_EVENT_NAME = require_versionId.LOCALES_DICTIONARY_CACHE_MISS_EVENT_NAME;
321
+ exports.TRANSLATIONS_CACHE_MISS_EVENT_NAME = require_versionId.TRANSLATIONS_CACHE_MISS_EVENT_NAME;
300
322
  exports.createConditionStoreSingleton = createConditionStoreSingleton;
301
323
  exports.createLocaleResolver = createLocaleResolver;
302
324
  exports.createLookupOptions = require_versionId.createLookupOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"internal.cjs","names":["getI18nManager","getCurrentLocale","createLookupOptions","interpolateMessage","decodeOptions","isEncodedTranslationOptions","getI18nManager","getCurrentLocale","resolveDictionaryLookupOptions","extractVariables","createLookupOptions","interpolateMessage","getDictionaryEntry","isDictionaryValue","resolveStringContentWithRuntimeFallback","getCurrentLocale","resolveStringContent","resolveStringContentWithFallback","resolveJsx","setConditionStore","libraryDefaultLocale","LocaleConfig"],"sources":["../src/translation-functions/internal/getGT.ts","../src/translation-functions/internal/getMessages.ts","../src/translation-functions/internal/getTranslations.ts","../src/translation-functions/internal/tx.ts","../src/translation-functions/internal/sync-translation-resolution.ts","../src/translation-functions/internal/jsx-resolution.ts","../src/i18n-manager/condition-store/createConditionStoreSingleton.ts","../src/i18n-manager/condition-store/localeResolver.ts"],"sourcesContent":["import {\n getCurrentLocale,\n getI18nManager,\n} from '../../i18n-manager/singleton-operations';\nimport { InlineTranslationOptions } from '../types/options';\nimport { GTFunctionType } from '../types/functions';\nimport { interpolateMessage } from '../utils/interpolation/interpolateMessage';\nimport { createLookupOptions } from './helpers';\nimport type { StringFormat } from 'generaltranslation/types';\n\n/**\n * Returns the gt function that registers a string at build time and resolves its translation at runtime.\n * @returns A promise of the gt function\n *\n * @example\n * const gt = await getGT();\n * const greeting = gt('Hello, world!');\n */\nexport async function getGT(): Promise<GTFunctionType> {\n // Get the translation resolver\n const i18nManager = getI18nManager();\n const locale = getCurrentLocale();\n await i18nManager.loadTranslations(locale);\n const sourceLocale = i18nManager.getDefaultLocale();\n\n /**\n * Registers a message at build time and resolves its translation at runtime.\n * @param {string} message - The message to translate\n * @param {InlineTranslationOptions} options - The options for the translation\n * @returns The translated message\n *\n * @example\n * // Simple translation without interpolation\n * const gt = await getGT();\n * const greeting = gt('Hello, world!');\n *\n * @example\n * // Translation with interpolation\n * const gt = await getGT();\n * const welcome = gt('Hello, {name}!', { name: 'Alice' });\n */\n const gt: GTFunctionType = (\n message: string,\n options: InlineTranslationOptions = {}\n ) => {\n const targetLocale = options.$locale ?? locale;\n const lookupOptions = createLookupOptions<StringFormat>(\n targetLocale,\n options,\n 'ICU'\n );\n\n // Lookup translation\n const translation = i18nManager.lookupTranslation(\n lookupOptions.$locale,\n message,\n lookupOptions\n );\n\n // Format result\n return interpolateMessage({\n source: message,\n target: translation,\n options: lookupOptions,\n sourceLocale,\n });\n };\n\n return gt;\n}\n","import { InlineResolveOptions } from '../types/options';\nimport { decodeOptions } from '../msg/decodeOptions';\nimport { isEncodedTranslationOptions } from '../utils/isEncodedTranslationOptions';\nimport { getGT } from './getGT';\nimport { MFunctionType } from '../types/functions';\n\n/**\n * Returns the m function that resolves a registered message to its translation.\n * @returns A promise of the m function\n *\n * @example\n * // Registration\n * const registeredMessage = msg('Hello, world!');\n *\n * // Resolution\n * const m = await getMessages();\n * const greeting = m(registeredMessage);\n */\nexport async function getMessages(): Promise<MFunctionType> {\n // Get the gt function\n const gt = await getGT();\n\n /**\n * Resolves a registered message to its translation.\n * @param {string | null | undefined} encodedMsg - The encoded message to decode and interpolate.\n * @param {InlineTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @example\n * // Simple message without interpolation\n * const m = await getMessages();\n * const greeting = m(msg('Hello, world!'));\n *\n * @example\n * // Message with interpolation\n * const m = await getMessages();\n * const welcome = m(msg('Welcome, {user}!'), { user: 'Alice' });\n */\n const m: MFunctionType = <T extends string | null | undefined>(\n encodedMsg: T,\n options: InlineResolveOptions = {}\n ): T extends string ? string : T => {\n // Return if the encoded message is null or undefined\n if (encodedMsg == null) 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 return gt(decodedOptions.$_source, decodedOptions) as T extends string\n ? string\n : T;\n }\n\n // Use gt to interpolate\n // Separate from decoded options to match behavior in @gt/react-core\n return gt(encodedMsg, options) as T extends string ? string : T;\n };\n\n return m;\n}\n","import {\n getCurrentLocale,\n getI18nManager,\n} from '../../i18n-manager/singleton-operations';\nimport { DictionaryTranslationOptions } from '../types/options';\nimport { TFunctionType } from '../types/functions';\nimport { interpolateMessage } from '../utils/interpolation/interpolateMessage';\nimport { createLookupOptions } from './helpers';\nimport { extractVariables } from '../../utils/extractVariables';\nimport type { StringFormat } from 'generaltranslation/types';\nimport type {\n DictionaryEntry,\n DictionaryValue,\n} from '../../i18n-manager/translations-manager/DictionaryCache';\nimport {\n getDictionaryEntry,\n isDictionaryValue,\n resolveDictionaryLookupOptions,\n} from '../../i18n-manager/translations-manager/utils/dictionary-helpers';\nimport type { DictionaryObjectTranslation } from '../types/functions';\n\n/**\n * Returns the t function that translates a dictionary entry based on its id and options.\n * @returns A promise of the t function\n * @important Must be used inside of a request context\n *\n * @example\n * const t = await getTranslations();\n * const title = await t('page.title');\n */\nexport async function getTranslations(): Promise<TFunctionType> {\n const i18nManager = getI18nManager();\n const locale = getCurrentLocale();\n await i18nManager.loadDictionary(locale);\n const sourceLocale = i18nManager.getDefaultLocale();\n\n /**\n * Dictionary resolution\n * @param {string} id - The id of the translation to translate.\n * @param {DictionaryTranslationOptions} options - The options for interpolation.\n * @returns {string} The translated message.\n *\n * @example\n * // Simple dictionary lookup without interpolation\n * const t = await getTranslations();\n * const title = t('page.title');\n *\n * @example\n * // Dictionary lookup with interpolation\n * const t = await getTranslations();\n * const greeting = t('user.greeting', { name: 'Bob' });\n */\n const t = ((\n id: string,\n options: DictionaryTranslationOptions = {}\n ): string => {\n const sourceEntry = i18nManager.lookupDictionary(sourceLocale, id);\n if (sourceEntry === undefined) {\n throw new Error(`Dictionary entry ${id} cannot be found`);\n }\n const targetEntry = i18nManager.lookupDictionary(locale, id);\n return renderEntry({\n sourceLocale,\n targetLocale: locale,\n sourceEntry,\n targetEntry,\n options,\n });\n }) as TFunctionType;\n\n t.obj = (id: string): DictionaryObjectTranslation => {\n const sourceObject = i18nManager.lookupDictionaryObj(sourceLocale, id);\n if (sourceObject === undefined) {\n throw new Error(`Dictionary entry ${id} cannot be found`);\n }\n const targetObject = i18nManager.lookupDictionaryObj(locale, id);\n return renderObject({ sourceObject, targetObject });\n };\n\n return t;\n}\n\nfunction renderEntry({\n sourceLocale,\n targetLocale,\n sourceEntry,\n targetEntry,\n options = {},\n}: {\n sourceLocale: string;\n targetLocale: string;\n sourceEntry: DictionaryEntry;\n targetEntry: DictionaryEntry | undefined;\n options?: DictionaryTranslationOptions;\n}): string {\n const dictionaryOptions = resolveDictionaryLookupOptions(sourceEntry.options);\n const interpolationOptions = extractVariables(options);\n const lookupOptions = createLookupOptions<StringFormat>(\n targetLocale,\n {\n ...dictionaryOptions,\n ...interpolationOptions,\n },\n dictionaryOptions.$format ?? 'ICU'\n );\n\n return interpolateMessage({\n source: sourceEntry.entry,\n target: targetEntry?.entry,\n options: lookupOptions,\n sourceLocale,\n });\n}\n\nfunction renderObject({\n sourceObject,\n targetObject,\n}: {\n sourceObject: DictionaryValue | undefined;\n targetObject: DictionaryValue | undefined;\n}): DictionaryObjectTranslation {\n const targetEntry = getDictionaryEntry(targetObject);\n if (targetEntry !== undefined) {\n return targetEntry.entry;\n }\n\n if (isDictionaryValue(targetObject)) {\n if (!isDictionaryValue(sourceObject)) {\n return renderObject({\n sourceObject: targetObject,\n targetObject: undefined,\n });\n }\n\n return renderDictionaryObject({\n sourceObject,\n targetObject,\n });\n }\n\n const sourceEntry = getDictionaryEntry(sourceObject);\n if (sourceEntry !== undefined) {\n return sourceEntry.entry;\n }\n\n if (isDictionaryValue(sourceObject)) {\n return renderDictionaryObject({\n sourceObject,\n targetObject: undefined,\n });\n }\n\n throw new Error('Dictionary object cannot be rendered');\n}\n\nfunction renderDictionaryObject({\n sourceObject,\n targetObject,\n}: {\n sourceObject: DictionaryValue;\n targetObject: DictionaryValue | undefined;\n}): DictionaryObjectTranslation {\n if (!isDictionaryValue(sourceObject)) {\n return renderObject({ sourceObject, targetObject });\n }\n const result: Record<string, DictionaryObjectTranslation> = {};\n const keys = new Set([\n ...Object.keys(sourceObject),\n ...(isDictionaryValue(targetObject) ? Object.keys(targetObject) : []),\n ]);\n\n for (const key of keys) {\n const renderedChild = renderObject({\n sourceObject: sourceObject[key],\n targetObject: isDictionaryValue(targetObject)\n ? targetObject[key]\n : undefined,\n });\n if (renderedChild !== undefined) {\n result[key] = renderedChild;\n }\n }\n\n return result;\n}\n","import { RuntimeTranslationOptions } from '../types/options';\nimport type { StringFormat } from 'generaltranslation/types';\nimport { resolveStringContentWithRuntimeFallback } from './helpers';\nimport { getCurrentLocale } from '../../i18n-manager/singleton-operations';\n\ntype RuntimeTranslationOptionsWithFormat = Omit<\n RuntimeTranslationOptions,\n '$format'\n> & {\n $format?: StringFormat;\n};\n\n/**\n * Translates a message at runtime.\n * @param {string} message - The message to translate.\n * @param {RuntimeTranslationOptions} options - The options for the translation.\n * @returns {Promise<string>} The translated message.\n *\n * @example\n * // Simple runtime translation without interpolation\n * const status = await tx('Processing complete', { $locale: 'es-MX' });\n *\n * @example\n * // Runtime translation with interpolation\n * const progress = await tx(`Processing ${status}`, { $locale: 'es-MX' });\n */\nexport async function tx(\n content: string,\n options: RuntimeTranslationOptionsWithFormat = {}\n): Promise<string> {\n const locale = options.$locale ?? getCurrentLocale();\n return resolveStringContentWithRuntimeFallback(locale, content, {\n $format: 'STRING',\n ...options,\n });\n}\n","import { InlineTranslationOptions } from '../types/options';\nimport {\n resolveStringContent,\n resolveStringContentWithFallback,\n} from './helpers';\n\n/**\n * Synchronously resolve a translation for a given message and options\n * @param {string} message - The message to translate.\n * @param {InlineTranslationOptions} [options] - The options for the translation.\n * @returns {string | undefined} The translated message or undefined if the message is not found.\n * @deprecated use resolveTranslation instead\n */\nexport function resolveTranslationSync(\n locale: string,\n message: string,\n options: InlineTranslationOptions = {}\n) {\n return resolveStringContent(locale, message, { $format: 'ICU', ...options });\n}\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {InlineTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message or the original message interpolated if the translation is not found.\n * @deprecated use resolveTranslationWithFallback instead\n */\nexport function resolveTranslationSyncWithFallback(\n locale: string,\n message: string,\n options: InlineTranslationOptions = {}\n) {\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...options,\n });\n}\n","import { JsxChildren } from 'generaltranslation/types';\nimport { JsxTranslationOptions } from '../types/options';\nimport { resolveJsx } from './helpers';\n\n/**\n * Given a JsxChildren and any associated metadata needed for a hash calculation, resolve the associated translation.\n * @deprecated use resolveJsx instead\n */\nexport function resolveJsxTranslation(\n locale: string,\n children: JsxChildren,\n options: JsxTranslationOptions = {}\n) {\n return resolveJsx(locale, children, options);\n}\n","import type { ConditionStore } from '../types';\nimport { setConditionStore as setCurrentConditionStore } from '../singleton-operations';\n\nexport function createConditionStoreSingleton<T extends ConditionStore>(\n notInitializedMessage: string\n) {\n let conditionStore: T | undefined;\n\n function getConditionStore(): T {\n if (!conditionStore) {\n throw new Error(notInitializedMessage);\n }\n return conditionStore;\n }\n\n function setConditionStore(nextConditionStore: T): void {\n conditionStore = nextConditionStore;\n setCurrentConditionStore(nextConditionStore);\n }\n\n return {\n getConditionStore,\n setConditionStore,\n };\n}\n","import { LocaleConfig } from 'generaltranslation/core';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport type { ConditionStoreConfig } from '../types';\n\nexport type LocaleCandidates = string | string[] | undefined;\n\nfunction normalizeConditionStoreConfig({\n defaultLocale,\n locales,\n customMapping,\n}: ConditionStoreConfig = {}) {\n const fallbackLocale = defaultLocale || libraryDefaultLocale;\n return {\n defaultLocale: fallbackLocale,\n locales: locales?.length ? locales : [fallbackLocale],\n customMapping,\n };\n}\n\ntype NormalizedConditionStoreConfig = ReturnType<\n typeof normalizeConditionStoreConfig\n>;\n\n/**\n * Return the best supported locale for the candidates, or undefined when none match.\n */\nexport function determineSupportedLocale(\n candidates: LocaleCandidates,\n config: ConditionStoreConfig = {}\n): string | undefined {\n return determineSupportedLocaleWithConfig(\n candidates,\n normalizeConditionStoreConfig(config)\n );\n}\n\nfunction determineSupportedLocaleWithConfig(\n candidates: LocaleCandidates,\n config: NormalizedConditionStoreConfig\n): string | undefined {\n if (\n candidates == null ||\n (Array.isArray(candidates) && candidates.length === 0)\n ) {\n return undefined;\n }\n\n const localeConfig = new LocaleConfig(config);\n return localeConfig.determineLocale(candidates) || undefined;\n}\n\n/**\n * Return the best supported locale for the candidates, falling back to the default locale.\n */\nexport function resolveSupportedLocale(\n candidates: LocaleCandidates,\n config: ConditionStoreConfig = {}\n): string {\n const normalizedConfig = normalizeConditionStoreConfig(config);\n return (\n determineSupportedLocaleWithConfig(candidates, normalizedConfig) ||\n normalizedConfig.defaultLocale\n );\n}\n\nexport function createLocaleResolver(config: ConditionStoreConfig = {}) {\n const normalizedConfig = normalizeConditionStoreConfig(config);\n return (candidates?: LocaleCandidates): string =>\n determineSupportedLocaleWithConfig(candidates, normalizedConfig) ||\n normalizedConfig.defaultLocale;\n}\n"],"mappings":";;;;;;;;;;;;;;AAkBA,eAAsB,QAAiC;CAErD,MAAM,cAAcA,kBAAAA,gBAAgB;CACpC,MAAM,SAASC,kBAAAA,kBAAkB;AACjC,OAAM,YAAY,iBAAiB,OAAO;CAC1C,MAAM,eAAe,YAAY,kBAAkB;;;;;;;;;;;;;;;;;CAkBnD,MAAM,MACJ,SACA,UAAoC,EAAE,KACnC;EAEH,MAAM,gBAAgBC,kBAAAA,oBADD,QAAQ,WAAW,QAGtC,SACA,MACD;AAUD,SAAOC,kBAAAA,mBAAmB;GACxB,QAAQ;GACR,QATkB,YAAY,kB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,KAAA;;;;;AAMrD,SAAgB,uBACd,YACA,SAA+B,EAAE,EACzB;CACR,MAAM,mBAAmB,8BAA8B,OAAO;AAC9D,QACE,mCAAmC,YAAY,iBAAiB,IAChE,iBAAiB;;AAIrB,SAAgB,qBAAqB,SAA+B,EAAE,EAAE;CACtE,MAAM,mBAAmB,8BAA8B,OAAO;AAC9D,SAAQ,eACN,mCAAmC,YAAY,iBAAiB,IAChE,iBAAiB"}
1
+ {"version":3,"file":"internal.cjs","names":["getI18nManager","getCurrentLocale","createLookupOptions","interpolateMessage","decodeOptions","isEncodedTranslationOptions","getI18nManager","getCurrentLocale","resolveDictionaryLookupOptions","getDictionaryEntry","isDictionaryValue","extractVariables","createLookupOptions","interpolateMessage","resolveStringContentWithRuntimeFallback","getCurrentLocale","resolveStringContent","resolveStringContentWithFallback","resolveJsx","setConditionStore","libraryDefaultLocale","LocaleConfig"],"sources":["../src/translation-functions/internal/getGT.ts","../src/translation-functions/internal/getMessages.ts","../src/translation-functions/internal/getTranslations.ts","../src/translation-functions/internal/tx.ts","../src/translation-functions/internal/sync-translation-resolution.ts","../src/translation-functions/internal/jsx-resolution.ts","../src/i18n-manager/condition-store/createConditionStoreSingleton.ts","../src/i18n-manager/condition-store/localeResolver.ts"],"sourcesContent":["import {\n getCurrentLocale,\n getI18nManager,\n} from '../../i18n-manager/singleton-operations';\nimport { InlineTranslationOptions } from '../types/options';\nimport { GTFunctionType } from '../types/functions';\nimport { interpolateMessage } from '../utils/interpolation/interpolateMessage';\nimport { createLookupOptions } from './helpers';\nimport type { StringFormat } from '@generaltranslation/format/types';\n\n/**\n * Returns the gt function that registers a string at build time and resolves its translation at runtime.\n * @returns A promise of the gt function\n *\n * @example\n * const gt = await getGT();\n * const greeting = gt('Hello, world!');\n */\nexport async function getGT(): Promise<GTFunctionType> {\n // Get the translation resolver\n const i18nManager = getI18nManager();\n const locale = getCurrentLocale();\n await i18nManager.loadTranslations(locale);\n const sourceLocale = i18nManager.getDefaultLocale();\n\n /**\n * Registers a message at build time and resolves its translation at runtime.\n * @param {string} message - The message to translate\n * @param {InlineTranslationOptions} options - The options for the translation\n * @returns The translated message\n *\n * @example\n * // Simple translation without interpolation\n * const gt = await getGT();\n * const greeting = gt('Hello, world!');\n *\n * @example\n * // Translation with interpolation\n * const gt = await getGT();\n * const welcome = gt('Hello, {name}!', { name: 'Alice' });\n */\n const gt: GTFunctionType = (\n message: string,\n options: InlineTranslationOptions = {}\n ) => {\n const targetLocale = options.$locale ?? locale;\n const lookupOptions = createLookupOptions<StringFormat>(\n targetLocale,\n options,\n 'ICU'\n );\n\n // Lookup translation\n const translation = i18nManager.lookupTranslation(\n lookupOptions.$locale,\n message,\n lookupOptions\n );\n\n // Format result\n return interpolateMessage({\n source: message,\n target: translation,\n options: lookupOptions,\n sourceLocale,\n });\n };\n\n return gt;\n}\n","import { InlineResolveOptions } from '../types/options';\nimport { decodeOptions } from '../msg/decodeOptions';\nimport { isEncodedTranslationOptions } from '../utils/isEncodedTranslationOptions';\nimport { getGT } from './getGT';\nimport { MFunctionType } from '../types/functions';\n\n/**\n * Returns the m function that resolves a registered message to its translation.\n * @returns A promise of the m function\n *\n * @example\n * // Registration\n * const registeredMessage = msg('Hello, world!');\n *\n * // Resolution\n * const m = await getMessages();\n * const greeting = m(registeredMessage);\n */\nexport async function getMessages(): Promise<MFunctionType> {\n // Get the gt function\n const gt = await getGT();\n\n /**\n * Resolves a registered message to its translation.\n * @param {string | null | undefined} encodedMsg - The encoded message to decode and interpolate.\n * @param {InlineTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @example\n * // Simple message without interpolation\n * const m = await getMessages();\n * const greeting = m(msg('Hello, world!'));\n *\n * @example\n * // Message with interpolation\n * const m = await getMessages();\n * const welcome = m(msg('Welcome, {user}!'), { user: 'Alice' });\n */\n const m: MFunctionType = <T extends string | null | undefined>(\n encodedMsg: T,\n options: InlineResolveOptions = {}\n ): T extends string ? string : T => {\n // Return if the encoded message is null or undefined\n if (encodedMsg == null) 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 return gt(decodedOptions.$_source, decodedOptions) as T extends string\n ? string\n : T;\n }\n\n // Use gt to interpolate\n // Separate from decoded options to match behavior in @gt/react-core\n return gt(encodedMsg, options) as T extends string ? string : T;\n };\n\n return m;\n}\n","import {\n getCurrentLocale,\n getI18nManager,\n} from '../../i18n-manager/singleton-operations';\nimport { DictionaryTranslationOptions } from '../types/options';\nimport { TFunctionType } from '../types/functions';\nimport { interpolateMessage } from '../utils/interpolation/interpolateMessage';\nimport { createLookupOptions } from './helpers';\nimport { extractVariables } from '../../utils/extractVariables';\nimport type { StringFormat } from '@generaltranslation/format/types';\nimport type {\n DictionaryEntry,\n DictionaryValue,\n} from '../../i18n-manager/translations-manager/DictionaryCache';\nimport {\n getDictionaryEntry,\n isDictionaryValue,\n resolveDictionaryLookupOptions,\n} from '../../i18n-manager/translations-manager/utils/dictionary-helpers';\nimport type { DictionaryObjectTranslation } from '../types/functions';\n\n/**\n * Returns the t function that translates a dictionary entry based on its id and options.\n * @returns A promise of the t function\n * @important Must be used inside of a request context\n *\n * @example\n * const t = await getTranslations();\n * const title = await t('page.title');\n */\nexport async function getTranslations(): Promise<TFunctionType> {\n const i18nManager = getI18nManager();\n const locale = getCurrentLocale();\n await Promise.all([\n i18nManager.loadDictionary(locale),\n i18nManager.loadTranslations(locale),\n ]);\n const sourceLocale = i18nManager.getDefaultLocale();\n\n /**\n * Dictionary resolution\n * @param {string} id - The id of the translation to translate.\n * @param {DictionaryTranslationOptions} options - The options for interpolation.\n * @returns {string} The translated message.\n *\n * @example\n * // Simple dictionary lookup without interpolation\n * const t = await getTranslations();\n * const title = t('page.title');\n *\n * @example\n * // Dictionary lookup with interpolation\n * const t = await getTranslations();\n * const greeting = t('user.greeting', { name: 'Bob' });\n */\n const t = ((\n id: string,\n options: DictionaryTranslationOptions = {}\n ): string => {\n const sourceEntry = i18nManager.lookupDictionary(sourceLocale, id);\n if (sourceEntry === undefined) {\n throw new Error(`Dictionary entry ${id} cannot be found`);\n }\n const targetEntry = i18nManager.lookupDictionary(locale, id);\n const dictionaryOptions = resolveDictionaryLookupOptions(\n sourceEntry.options\n );\n const target =\n targetEntry?.entry ??\n i18nManager.lookupTranslation(\n locale,\n sourceEntry.entry,\n dictionaryOptions\n );\n return renderEntry({\n sourceLocale,\n targetLocale: locale,\n sourceEntry,\n target,\n dictionaryOptions,\n options,\n });\n }) as TFunctionType;\n\n /**\n * Returns a subtree of the dictionary object translation based on its id.\n * @param {string} id - The id of the translation to translate.\n * @returns The translated object.\n *\n * @example\n * const t = await getTranslations();\n * const greetings = t.obj('greetings');\n * console.log(greetings);\n * // { greeting1: 'Hello', greeting2: 'Hi' }\n */\n t.obj = (id: string): DictionaryObjectTranslation => {\n const sourceObject = i18nManager.lookupDictionaryObj(sourceLocale, id);\n if (sourceObject === undefined) {\n throw new Error(`Dictionary entry ${id} cannot be found`);\n }\n const targetObject = i18nManager.lookupDictionaryObj(locale, id);\n return renderObject({ sourceObject, targetObject });\n };\n\n function renderObject({\n sourceObject,\n targetObject,\n }: {\n sourceObject: DictionaryValue | undefined;\n targetObject: DictionaryValue | undefined;\n }): DictionaryObjectTranslation {\n const targetEntry = getDictionaryEntry(targetObject);\n if (targetEntry !== undefined) {\n return targetEntry.entry;\n }\n\n if (isDictionaryValue(targetObject)) {\n if (!isDictionaryValue(sourceObject)) {\n return renderObject({\n sourceObject: targetObject,\n targetObject: undefined,\n });\n }\n\n return renderDictionaryObject({\n sourceObject,\n targetObject,\n });\n }\n\n const sourceEntry = getDictionaryEntry(sourceObject);\n if (sourceEntry !== undefined) {\n // Fallback to translations cache\n const dictionaryOptions = resolveDictionaryLookupOptions(\n sourceEntry.options\n );\n\n const target = i18nManager.lookupTranslation(\n locale,\n sourceEntry.entry,\n dictionaryOptions\n );\n if (target !== undefined) {\n return target;\n }\n\n // Fallback to source entry\n return sourceEntry.entry;\n }\n\n if (isDictionaryValue(sourceObject)) {\n return renderDictionaryObject({\n sourceObject,\n targetObject: undefined,\n });\n }\n\n throw new Error('Dictionary object cannot be rendered');\n }\n\n function renderDictionaryObject({\n sourceObject,\n targetObject,\n }: {\n sourceObject: DictionaryValue;\n targetObject: DictionaryValue | undefined;\n }): DictionaryObjectTranslation {\n if (!isDictionaryValue(sourceObject)) {\n return renderObject({ sourceObject, targetObject });\n }\n const result: Record<string, DictionaryObjectTranslation> = {};\n const keys = new Set([\n ...Object.keys(sourceObject),\n ...(isDictionaryValue(targetObject) ? Object.keys(targetObject) : []),\n ]);\n\n for (const key of Array.from(keys)) {\n const renderedChild = renderObject({\n sourceObject: sourceObject[key],\n targetObject: isDictionaryValue(targetObject)\n ? targetObject[key]\n : undefined,\n });\n if (renderedChild !== undefined) {\n result[key] = renderedChild;\n }\n }\n\n return result;\n }\n\n return t;\n}\n\nfunction renderEntry({\n sourceLocale,\n targetLocale,\n sourceEntry,\n target,\n dictionaryOptions,\n options = {},\n}: {\n sourceLocale: string;\n targetLocale: string;\n sourceEntry: DictionaryEntry;\n target: string | undefined;\n dictionaryOptions: ReturnType<typeof resolveDictionaryLookupOptions>;\n options?: DictionaryTranslationOptions;\n}): string {\n const interpolationOptions = extractVariables(options);\n const lookupOptions = createLookupOptions<StringFormat>(\n targetLocale,\n {\n ...dictionaryOptions,\n ...interpolationOptions,\n },\n dictionaryOptions.$format ?? 'ICU'\n );\n\n return interpolateMessage({\n source: sourceEntry.entry,\n target,\n options: lookupOptions,\n sourceLocale,\n });\n}\n","import { RuntimeTranslationOptions } from '../types/options';\nimport type { StringFormat } from '@generaltranslation/format/types';\nimport { resolveStringContentWithRuntimeFallback } from './helpers';\nimport { getCurrentLocale } from '../../i18n-manager/singleton-operations';\n\ntype RuntimeTranslationOptionsWithFormat = Omit<\n RuntimeTranslationOptions,\n '$format'\n> & {\n $format?: StringFormat;\n};\n\n/**\n * Translates a message at runtime.\n * @param {string} message - The message to translate.\n * @param {RuntimeTranslationOptions} options - The options for the translation.\n * @returns {Promise<string>} The translated message.\n *\n * @example\n * // Simple runtime translation without interpolation\n * const status = await tx('Processing complete', { $locale: 'es-MX' });\n *\n * @example\n * // Runtime translation with interpolation\n * const progress = await tx(`Processing ${status}`, { $locale: 'es-MX' });\n */\nexport async function tx(\n content: string,\n options: RuntimeTranslationOptionsWithFormat = {}\n): Promise<string> {\n const locale =\n typeof options.$locale === 'string' ? options.$locale : getCurrentLocale();\n return resolveStringContentWithRuntimeFallback(locale, content, {\n $format: 'STRING',\n ...options,\n });\n}\n","import { InlineTranslationOptions } from '../types/options';\nimport {\n resolveStringContent,\n resolveStringContentWithFallback,\n} from './helpers';\n\n/**\n * Synchronously resolve a translation for a given message and options\n * @param {string} message - The message to translate.\n * @param {InlineTranslationOptions} [options] - The options for the translation.\n * @returns {string | undefined} The translated message or undefined if the message is not found.\n * @deprecated use resolveTranslation instead\n */\nexport function resolveTranslationSync(\n locale: string,\n message: string,\n options: InlineTranslationOptions = {}\n) {\n return resolveStringContent(locale, message, { $format: 'ICU', ...options });\n}\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {InlineTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message or the original message interpolated if the translation is not found.\n * @deprecated use resolveTranslationWithFallback instead\n */\nexport function resolveTranslationSyncWithFallback(\n locale: string,\n message: string,\n options: InlineTranslationOptions = {}\n) {\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...options,\n });\n}\n","import type { JsxChildren } from '@generaltranslation/format/types';\nimport { JsxTranslationOptions } from '../types/options';\nimport { resolveJsx } from './helpers';\n\n/**\n * Given a JsxChildren and any associated metadata needed for a hash calculation, resolve the associated translation.\n * @deprecated use resolveJsx instead\n */\nexport function resolveJsxTranslation(\n locale: string,\n children: JsxChildren,\n options: JsxTranslationOptions = {}\n) {\n return resolveJsx(locale, children, options);\n}\n","import type { ConditionStore } from '../types';\nimport { setConditionStore as setCurrentConditionStore } from '../singleton-operations';\n\nexport function createConditionStoreSingleton<T extends ConditionStore>(\n notInitializedMessage: string\n) {\n let conditionStore: T | undefined;\n\n function getConditionStore(): T {\n if (!conditionStore) {\n throw new Error(notInitializedMessage);\n }\n return conditionStore;\n }\n\n function setConditionStore(nextConditionStore: T): void {\n conditionStore = nextConditionStore;\n setCurrentConditionStore(nextConditionStore);\n }\n\n return {\n getConditionStore,\n setConditionStore,\n };\n}\n","import { LocaleConfig } from '@generaltranslation/format';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport type { ConditionStoreConfig } from '../types';\n\nexport type LocaleCandidates = string | string[] | undefined;\n\nfunction normalizeConditionStoreConfig({\n defaultLocale,\n locales,\n customMapping,\n}: ConditionStoreConfig = {}) {\n const fallbackLocale = defaultLocale || libraryDefaultLocale;\n return {\n defaultLocale: fallbackLocale,\n locales: locales?.length ? locales : [fallbackLocale],\n customMapping,\n };\n}\n\ntype NormalizedConditionStoreConfig = ReturnType<\n typeof normalizeConditionStoreConfig\n>;\n\n/**\n * Return the best supported locale for the candidates, or undefined when none match.\n */\nexport function determineSupportedLocale(\n candidates: LocaleCandidates,\n config: ConditionStoreConfig = {}\n): string | undefined {\n return determineSupportedLocaleWithConfig(\n candidates,\n normalizeConditionStoreConfig(config)\n );\n}\n\nfunction determineSupportedLocaleWithConfig(\n candidates: LocaleCandidates,\n config: NormalizedConditionStoreConfig\n): string | undefined {\n if (\n candidates == null ||\n (Array.isArray(candidates) && candidates.length === 0)\n ) {\n return undefined;\n }\n\n const localeConfig = new LocaleConfig(config);\n return localeConfig.determineLocale(candidates) || undefined;\n}\n\n/**\n * Return the best supported locale for the candidates, falling back to the default locale.\n */\nexport function resolveSupportedLocale(\n candidates: LocaleCandidates,\n config: ConditionStoreConfig = {}\n): string {\n const normalizedConfig = normalizeConditionStoreConfig(config);\n return (\n determineSupportedLocaleWithConfig(candidates, normalizedConfig) ||\n normalizedConfig.defaultLocale\n );\n}\n\nexport function createLocaleResolver(config: ConditionStoreConfig = {}) {\n const normalizedConfig = normalizeConditionStoreConfig(config);\n return (candidates?: LocaleCandidates): string =>\n determineSupportedLocaleWithConfig(candidates, normalizedConfig) ||\n normalizedConfig.defaultLocale;\n}\n"],"mappings":";;;;;;;;;;;;;;AAkBA,eAAsB,QAAiC;CAErD,MAAM,cAAcA,kBAAAA,gBAAgB;CACpC,MAAM,SAASC,kBAAAA,kBAAkB;AACjC,OAAM,YAAY,iBAAiB,OAAO;CAC1C,MAAM,eAAe,YAAY,kBAAkB;;;;;;;;;;;;;;;;;CAkBnD,MAAM,MACJ,SACA,UAAoC,EAAE,KACnC;EAEH,MAAM,gBAAgBC,kBAAAA,oBADD,QAAQ,WAAW,QAGtC,SACA,MACD;AAUD,SAAOC,kBAAAA,mBAAmB;GACxB,QAAQ;GACR,QATkB,YAAY,kBAC9B,cAAc,SACd,SACA,cAMmB;GACnB,SAAS;GACT;GACD,CAAC;;AAGJ,QAAO;;;;;;;;;;;;;;;;AClDT,eAAsB,cAAsC;CAE1D,MAAM,KAAK,MAAM,OAAO;;;;;;;;;;;;;;;;;CAkBxB,MAAM,KACJ,YACA,UAAgC,EAAE,KACA;AAElC,MAAI,cAAc,KAAM,QAAO;EAG/B,MAAM,iBAAiBC,oCAAAA,cAAc,WAAW,IAAI,EAAE;AAGtD,MAAIC,oCAAAA,4BAA4B,eAAe,CAC7C,QAAO,GAAG,eAAe,UAAU,eAAe;AAOpD,SAAO,GAAG,YAAY,QAAQ;;AAGhC,QAAO;;;;;;;;;;;;;AC9BT,eAAsB,kBAA0C;CAC9D,MAAM,cAAcC,kBAAAA,gBAAgB;CACpC,MAAM,SAASC,kBAAAA,kBAAkB;AACjC,OAAM,QAAQ,IAAI,CAChB,YAAY,eAAe,OAAO,EAClC,YAAY,iBAAiB,OAAO,CACrC,CAAC;CACF,MAAM,eAAe,YAAY,kBAAkB;;;;;;;;;;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