gt-i18n 0.8.9 → 0.8.11

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 (38) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/fallbacks.d.cts +1 -1
  3. package/dist/fallbacks.d.mts +1 -1
  4. package/dist/{functions-CPODsB3C.d.mts → functions-BdYU6e8M.d.mts} +3 -3
  5. package/dist/{functions-8ooUv8Yo.d.cts → functions-BqtnSFF4.d.cts} +3 -3
  6. package/dist/{index-Bdz9PAYJ.d.cts → index-DJVRTYiP.d.cts} +2 -2
  7. package/dist/index-DUcoQ9y0.d.mts +56 -0
  8. package/dist/{index-DdPo_-bU.d.mts → index-YDEznmyZ.d.mts} +2 -2
  9. package/dist/index-jpLs__jj.d.cts +56 -0
  10. package/dist/index.cjs +11 -73
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +5 -58
  13. package/dist/index.d.mts +5 -58
  14. package/dist/index.mjs +5 -67
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/internal-types.d.cts +3 -3
  17. package/dist/internal-types.d.mts +3 -3
  18. package/dist/internal.cjs +93 -34
  19. package/dist/internal.cjs.map +1 -1
  20. package/dist/internal.d.cts +63 -69
  21. package/dist/internal.d.mts +63 -69
  22. package/dist/internal.mjs +72 -23
  23. package/dist/internal.mjs.map +1 -1
  24. package/dist/{types-J_6OXeaq.d.cts → localeResolver-BOaF2BhP.d.cts} +45 -36
  25. package/dist/{types-tZ12Fev6.d.mts → localeResolver-DToW87uU.d.mts} +45 -36
  26. package/dist/{options-B-yFI8LM.d.mts → options-BOz9P0yM.d.cts} +10 -4
  27. package/dist/{options-BFACoMQ2.d.cts → options-gL1Zt8jG.d.mts} +10 -4
  28. package/dist/{translation-data-ClcN-5hC.d.cts → translation-data-CwhMyqhx.d.cts} +1 -1
  29. package/dist/{translation-data-DoJjvbYg.d.mts → translation-data-D1e6vaTz.d.mts} +1 -1
  30. package/dist/types.d.cts +4 -4
  31. package/dist/types.d.mts +4 -4
  32. package/dist/{helpers-D0T1EpJa.cjs → versionId-OYIir6FW.cjs} +205 -130
  33. package/dist/versionId-OYIir6FW.cjs.map +1 -0
  34. package/dist/{helpers-DB3t35tn.mjs → versionId-ahkgeth1.mjs} +164 -125
  35. package/dist/versionId-ahkgeth1.mjs.map +1 -0
  36. package/package.json +1 -1
  37. package/dist/helpers-D0T1EpJa.cjs.map +0 -1
  38. package/dist/helpers-DB3t35tn.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # gt-i18n
2
2
 
3
+ ## 0.8.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1296](https://github.com/generaltranslation/gt/pull/1296) [`b8045ad`](https://github.com/generaltranslation/gt/commit/b8045ad0a6bf58ab39a0a1f632ed7250b670e401) Thanks [@bgub](https://github.com/bgub)! - Require explicit locales for I18nManager translation/cache operations, move current-locale lookup into higher-level helpers, and keep runtime condition storage in wrapper runtimes.
8
+
9
+ ## 0.8.10
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1301](https://github.com/generaltranslation/gt/pull/1301) [`a5a109c`](https://github.com/generaltranslation/gt/commit/a5a109ceab5790af1dd621578cae7b597cfd26f2) Thanks [@bgub](https://github.com/bgub)! - Fix source-locale interpolation for missing translations and resolve custom locale aliases consistently in browser and TanStack Start locale detection.
14
+
3
15
  ## 0.8.9
4
16
 
5
17
  ### Patch Changes
@@ -1,2 +1,2 @@
1
- import { n as gtFallback, t as mFallback } from "./index-Bdz9PAYJ.cjs";
1
+ import { n as gtFallback, t as mFallback } from "./index-DJVRTYiP.cjs";
2
2
  export { gtFallback, mFallback };
@@ -1,2 +1,2 @@
1
- import { n as gtFallback, t as mFallback } from "./index-DdPo_-bU.mjs";
1
+ import { n as gtFallback, t as mFallback } from "./index-YDEznmyZ.mjs";
2
2
  export { gtFallback, mFallback };
@@ -1,4 +1,4 @@
1
- import { a as InlineTranslationOptions, n as DictionaryTranslationOptions, o as JsxTranslationOptions } from "./options-B-yFI8LM.mjs";
1
+ import { a as InlineTranslationOptions, n as DictionaryTranslationOptions, o as JsxTranslationOptions } from "./options-gL1Zt8jG.mjs";
2
2
  import { JsxChildren } from "generaltranslation/types";
3
3
 
4
4
  //#region src/translation-functions/types/functions.d.ts
@@ -55,7 +55,7 @@ type TFunctionType = (id: string, options?: DictionaryTranslationOptions) => str
55
55
  * @param {JsxTranslationOptions} options - The options for the translation.
56
56
  * @returns {JsxChildren} The resolved translation.
57
57
  */
58
- type ResolveJsxTranslationFunction = (children: JsxChildren, options?: JsxTranslationOptions) => JsxChildren | undefined;
58
+ type ResolveJsxTranslationFunction = (locale: string, children: JsxChildren, options?: JsxTranslationOptions) => JsxChildren | undefined;
59
59
  //#endregion
60
60
  export { SyncResolutionFunctionWithFallback as a, SyncResolutionFunction as i, MFunctionType as n, TFunctionType as o, ResolveJsxTranslationFunction as r, GTFunctionType as t };
61
- //# sourceMappingURL=functions-CPODsB3C.d.mts.map
61
+ //# sourceMappingURL=functions-BdYU6e8M.d.mts.map
@@ -1,4 +1,4 @@
1
- import { a as InlineTranslationOptions, n as DictionaryTranslationOptions, o as JsxTranslationOptions } from "./options-BFACoMQ2.cjs";
1
+ import { a as InlineTranslationOptions, n as DictionaryTranslationOptions, o as JsxTranslationOptions } from "./options-BOz9P0yM.cjs";
2
2
  import { JsxChildren } from "generaltranslation/types";
3
3
 
4
4
  //#region src/translation-functions/types/functions.d.ts
@@ -55,7 +55,7 @@ type TFunctionType = (id: string, options?: DictionaryTranslationOptions) => str
55
55
  * @param {JsxTranslationOptions} options - The options for the translation.
56
56
  * @returns {JsxChildren} The resolved translation.
57
57
  */
58
- type ResolveJsxTranslationFunction = (children: JsxChildren, options?: JsxTranslationOptions) => JsxChildren | undefined;
58
+ type ResolveJsxTranslationFunction = (locale: string, children: JsxChildren, options?: JsxTranslationOptions) => JsxChildren | undefined;
59
59
  //#endregion
60
60
  export { SyncResolutionFunctionWithFallback as a, SyncResolutionFunction as i, MFunctionType as n, TFunctionType as o, ResolveJsxTranslationFunction as r, GTFunctionType as t };
61
- //# sourceMappingURL=functions-8ooUv8Yo.d.cts.map
61
+ //# sourceMappingURL=functions-BqtnSFF4.d.cts.map
@@ -1,4 +1,4 @@
1
- import { n as MFunctionType, t as GTFunctionType } from "./functions-8ooUv8Yo.cjs";
1
+ import { n as MFunctionType, t as GTFunctionType } from "./functions-BqtnSFF4.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-Bdz9PAYJ.d.cts.map
60
+ //# sourceMappingURL=index-DJVRTYiP.d.cts.map
@@ -0,0 +1,56 @@
1
+ import * as _$generaltranslation_types0 from "generaltranslation/types";
2
+
3
+ //#region src/helpers/locale.d.ts
4
+ /**
5
+ * Get the current locale
6
+ * @returns The current locale
7
+ *
8
+ * @example
9
+ * const locale = getLocale();
10
+ * console.log(locale); // 'en-US'
11
+ */
12
+ declare function getLocale(): string;
13
+ /**
14
+ * Get the configured locales
15
+ * @returns The configured locales
16
+ *
17
+ * @example
18
+ * const locales = getLocales();
19
+ * console.log(locales); // ['en-US', 'es-ES']
20
+ */
21
+ declare function getLocales(): string[];
22
+ /**
23
+ * Get the default locale
24
+ * @returns The default locale
25
+ *
26
+ * @example
27
+ * const defaultLocale = getDefaultLocale();
28
+ * console.log(defaultLocale); // 'en-US'
29
+ */
30
+ declare function getDefaultLocale(): string;
31
+ /**
32
+ * Get the locale properties
33
+ * @param {string} [locale] - The locale to get the properties for. When not provided, uses the current locale.
34
+ * @returns The locale properties
35
+ *
36
+ * @example
37
+ * const localeProperties = getLocaleProperties();
38
+ *
39
+ * @example
40
+ * const localeProperties = getLocaleProperties('en-US');
41
+ */
42
+ declare function getLocaleProperties(locale?: string): _$generaltranslation_types0.LocaleProperties;
43
+ //#endregion
44
+ //#region src/helpers/versionId.d.ts
45
+ /**
46
+ * Get the version ID for the current source
47
+ * @returns The version ID, if set
48
+ *
49
+ * @example
50
+ * const versionId = getVersionId();
51
+ * console.log(versionId); // 'abc123'
52
+ */
53
+ declare function getVersionId(): string | undefined;
54
+ //#endregion
55
+ export { getLocales as a, getLocaleProperties as i, getDefaultLocale as n, getLocale as r, getVersionId as t };
56
+ //# sourceMappingURL=index-DUcoQ9y0.d.mts.map
@@ -1,4 +1,4 @@
1
- import { n as MFunctionType, t as GTFunctionType } from "./functions-CPODsB3C.mjs";
1
+ import { n as MFunctionType, t as GTFunctionType } from "./functions-BdYU6e8M.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-DdPo_-bU.d.mts.map
60
+ //# sourceMappingURL=index-YDEznmyZ.d.mts.map
@@ -0,0 +1,56 @@
1
+ import * as _$generaltranslation_types0 from "generaltranslation/types";
2
+
3
+ //#region src/helpers/locale.d.ts
4
+ /**
5
+ * Get the current locale
6
+ * @returns The current locale
7
+ *
8
+ * @example
9
+ * const locale = getLocale();
10
+ * console.log(locale); // 'en-US'
11
+ */
12
+ declare function getLocale(): string;
13
+ /**
14
+ * Get the configured locales
15
+ * @returns The configured locales
16
+ *
17
+ * @example
18
+ * const locales = getLocales();
19
+ * console.log(locales); // ['en-US', 'es-ES']
20
+ */
21
+ declare function getLocales(): string[];
22
+ /**
23
+ * Get the default locale
24
+ * @returns The default locale
25
+ *
26
+ * @example
27
+ * const defaultLocale = getDefaultLocale();
28
+ * console.log(defaultLocale); // 'en-US'
29
+ */
30
+ declare function getDefaultLocale(): string;
31
+ /**
32
+ * Get the locale properties
33
+ * @param {string} [locale] - The locale to get the properties for. When not provided, uses the current locale.
34
+ * @returns The locale properties
35
+ *
36
+ * @example
37
+ * const localeProperties = getLocaleProperties();
38
+ *
39
+ * @example
40
+ * const localeProperties = getLocaleProperties('en-US');
41
+ */
42
+ declare function getLocaleProperties(locale?: string): _$generaltranslation_types0.LocaleProperties;
43
+ //#endregion
44
+ //#region src/helpers/versionId.d.ts
45
+ /**
46
+ * Get the version ID for the current source
47
+ * @returns The version ID, if set
48
+ *
49
+ * @example
50
+ * const versionId = getVersionId();
51
+ * console.log(versionId); // 'abc123'
52
+ */
53
+ declare function getVersionId(): string | undefined;
54
+ //#endregion
55
+ export { getLocales as a, getLocaleProperties as i, getDefaultLocale as n, getLocale as r, getVersionId as t };
56
+ //# sourceMappingURL=index-jpLs__jj.d.cts.map
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_isEncodedTranslationOptions = require("./isEncodedTranslationOptions-D7ltjc4f.cjs");
3
- const require_helpers = require("./helpers-D0T1EpJa.cjs");
3
+ const require_versionId = require("./versionId-OYIir6FW.cjs");
4
4
  const require_mFallback = require("./mFallback-CoPRtKyL.cjs");
5
5
  let generaltranslation_internal = require("generaltranslation/internal");
6
6
  let generaltranslation_core = require("generaltranslation/core");
@@ -8,15 +8,15 @@ let generaltranslation_core = require("generaltranslation/core");
8
8
  /**
9
9
  * Translate a message
10
10
  * @param {string} message - The message to translate.
11
- * @param {InlineTranslationOptions} options - The options for the translation.
11
+ * @param options - The options for the translation.
12
12
  * @returns The translated message.
13
13
  */
14
- const t = (message, options) => {
15
- return require_helpers.resolveStringContentWithFallback(message, {
14
+ function t(message, options = {}) {
15
+ return require_versionId.resolveStringContentWithFallback(options.$locale ?? require_versionId.getCurrentLocale(), message, {
16
16
  $format: "ICU",
17
17
  ...options
18
18
  });
19
- };
19
+ }
20
20
  //#endregion
21
21
  //#region src/translation-functions/msg/msg.ts
22
22
  function msg(message, options) {
@@ -43,7 +43,7 @@ function msg(message, options) {
43
43
  return message;
44
44
  }
45
45
  const $_source = message;
46
- const $_hash = options.$_hash || require_helpers.hashMessage(message, {
46
+ const $_hash = options.$_hash || require_versionId.hashMessage(message, {
47
47
  $format: "ICU",
48
48
  ...options
49
49
  });
@@ -56,68 +56,6 @@ function msg(message, options) {
56
56
  return `${interpolatedString}:${optionsEncoding}`;
57
57
  }
58
58
  //#endregion
59
- //#region src/helpers/locale.ts
60
- /**
61
- * Get the current locale
62
- * @returns The current locale
63
- *
64
- * @example
65
- * const locale = getLocale();
66
- * console.log(locale); // 'en-US'
67
- */
68
- function getLocale() {
69
- return require_helpers.getI18nManager().getLocale();
70
- }
71
- /**
72
- * Get the current locales
73
- * @returns The current locales
74
- *
75
- * @example
76
- * const locales = getLocales();
77
- * console.log(locales); // ['en-US', 'es-ES']
78
- */
79
- function getLocales() {
80
- return require_helpers.getI18nManager().getLocales();
81
- }
82
- /**
83
- * Get the default locale
84
- * @returns The default locale
85
- *
86
- * @example
87
- * const defaultLocale = getDefaultLocale();
88
- * console.log(defaultLocale); // 'en-US'
89
- */
90
- function getDefaultLocale() {
91
- return require_helpers.getI18nManager().getDefaultLocale();
92
- }
93
- /**
94
- * Get the locale properties
95
- * @param {string} [locale] - The locale to get the properties for. When not provided, uses the current locale.
96
- * @returns The locale properties
97
- *
98
- * @example
99
- * const localeProperties = getLocaleProperties();
100
- *
101
- * @example
102
- * const localeProperties = getLocaleProperties('en-US');
103
- */
104
- function getLocaleProperties(locale) {
105
- return require_helpers.getI18nManager().getGTClass().getLocaleProperties(locale);
106
- }
107
- //#endregion
108
- //#region src/helpers/versionId.ts
109
- /**
110
- * Get the version ID for the current source
111
- * @returns The version ID, if set
112
- *
113
- * @example
114
- * const versionId = getVersionId();
115
- * console.log(versionId); // 'abc123'
116
- */
117
- function getVersionId() {
118
- return require_helpers.getI18nManager().getVersionId();
119
- }
120
- //#endregion
121
59
  Object.defineProperty(exports, "declareStatic", {
122
60
  enumerable: true,
123
61
  get: function() {
@@ -144,11 +82,11 @@ Object.defineProperty(exports, "derive", {
144
82
  return generaltranslation_internal.derive;
145
83
  }
146
84
  });
147
- exports.getDefaultLocale = getDefaultLocale;
148
- exports.getLocale = getLocale;
149
- exports.getLocaleProperties = getLocaleProperties;
150
- exports.getLocales = getLocales;
151
- exports.getVersionId = getVersionId;
85
+ exports.getDefaultLocale = require_versionId.getDefaultLocale;
86
+ exports.getLocale = require_versionId.getLocale;
87
+ exports.getLocaleProperties = require_versionId.getLocaleProperties;
88
+ exports.getLocales = require_versionId.getLocales;
89
+ exports.getVersionId = require_versionId.getVersionId;
152
90
  exports.gtFallback = require_mFallback.gtFallback;
153
91
  exports.mFallback = require_mFallback.mFallback;
154
92
  exports.msg = msg;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["resolveStringContentWithFallback","extractVariables","libraryDefaultLocale","VAR_IDENTIFIER","createInterpolationFailureMessage","hashMessage","getI18nManager","getI18nManager"],"sources":["../src/translation-functions/t.ts","../src/translation-functions/msg/msg.ts","../src/helpers/locale.ts","../src/helpers/versionId.ts"],"sourcesContent":["import { resolveStringContentWithFallback } from './internal/helpers';\nimport { SyncResolutionFunctionWithFallback } from './types/functions';\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 The translated message.\n */\nexport const t: SyncResolutionFunctionWithFallback = (message, options) => {\n return resolveStringContentWithFallback(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","import { getI18nManager } from '../i18n-manager/singleton-operations';\n\n/**\n * Get the current locale\n * @returns The current locale\n *\n * @example\n * const locale = getLocale();\n * console.log(locale); // 'en-US'\n */\nexport function getLocale() {\n const i18nManager = getI18nManager();\n return i18nManager.getLocale();\n}\n\n/**\n * Get the current locales\n * @returns The current locales\n *\n * @example\n * const locales = getLocales();\n * console.log(locales); // ['en-US', 'es-ES']\n */\nexport function getLocales() {\n const i18nManager = getI18nManager();\n return i18nManager.getLocales();\n}\n\n/**\n * Get the default locale\n * @returns The default locale\n *\n * @example\n * const defaultLocale = getDefaultLocale();\n * console.log(defaultLocale); // 'en-US'\n */\nexport function getDefaultLocale() {\n const i18nManager = getI18nManager();\n return i18nManager.getDefaultLocale();\n}\n\n/**\n * Get the locale properties\n * @param {string} [locale] - The locale to get the properties for. When not provided, uses the current locale.\n * @returns The locale properties\n *\n * @example\n * const localeProperties = getLocaleProperties();\n *\n * @example\n * const localeProperties = getLocaleProperties('en-US');\n */\nexport function getLocaleProperties(locale?: string) {\n const i18nManager = getI18nManager();\n const gtInstance = i18nManager.getGTClass();\n return gtInstance.getLocaleProperties(locale);\n}\n","import { getI18nManager } from '../i18n-manager/singleton-operations';\n\n/**\n * Get the version ID for the current source\n * @returns The version ID, if set\n *\n * @example\n * const versionId = getVersionId();\n * console.log(versionId); // 'abc123'\n */\nexport function getVersionId() {\n const i18nManager = getI18nManager();\n return i18nManager.getVersionId();\n}\n"],"mappings":";;;;;;;;;;;;;AASA,MAAa,KAAyC,SAAS,YAAY;AACzE,QAAOA,gBAAAA,iCAAiC,SAAS;EAC/C,SAAS;EACT,GAAG;EACJ,CAAC;;;;AC0CJ,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,gBAAAA,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;;;;;;;;;;;;ACpGlC,SAAgB,YAAY;AAE1B,QADoBC,gBAAAA,gBACF,CAAC,WAAW;;;;;;;;;;AAWhC,SAAgB,aAAa;AAE3B,QADoBA,gBAAAA,gBACF,CAAC,YAAY;;;;;;;;;;AAWjC,SAAgB,mBAAmB;AAEjC,QADoBA,gBAAAA,gBACF,CAAC,kBAAkB;;;;;;;;;;;;;AAcvC,SAAgB,oBAAoB,QAAiB;AAGnD,QAFoBA,gBAAAA,gBACU,CAAC,YACd,CAAC,oBAAoB,OAAO;;;;;;;;;;;;AC7C/C,SAAgB,eAAe;AAE7B,QADoBC,gBAAAA,gBACF,CAAC,cAAc"}
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"}
package/dist/index.d.cts CHANGED
@@ -1,18 +1,17 @@
1
- import { a as InlineTranslationOptions } from "./options-BFACoMQ2.cjs";
2
- import { a as SyncResolutionFunctionWithFallback } from "./functions-8ooUv8Yo.cjs";
3
- import { n as gtFallback, t as mFallback } from "./index-Bdz9PAYJ.cjs";
1
+ import { a as InlineTranslationOptions } from "./options-BOz9P0yM.cjs";
2
+ import { n as gtFallback, t as mFallback } from "./index-DJVRTYiP.cjs";
4
3
  import { t as RegisterableMessages } from "./message-C62MTLwE.cjs";
5
- import * as _$generaltranslation_types0 from "generaltranslation/types";
4
+ import { a as getLocales, i as getLocaleProperties, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./index-jpLs__jj.cjs";
6
5
  import { declareStatic, declareVar, decodeVars, derive } from "generaltranslation/internal";
7
6
 
8
7
  //#region src/translation-functions/t.d.ts
9
8
  /**
10
9
  * Translate a message
11
10
  * @param {string} message - The message to translate.
12
- * @param {InlineTranslationOptions} options - The options for the translation.
11
+ * @param options - The options for the translation.
13
12
  * @returns The translated message.
14
13
  */
15
- declare const t: SyncResolutionFunctionWithFallback;
14
+ declare function t(message: string, options?: InlineTranslationOptions): string;
16
15
  //#endregion
17
16
  //#region src/translation-functions/msg/msg.d.ts
18
17
  /**
@@ -72,57 +71,5 @@ declare function decodeMsg<T extends string | null | undefined>(encodedMsg: T):
72
71
  */
73
72
  declare function decodeOptions(encodedMsg: string): InlineTranslationOptions | null;
74
73
  //#endregion
75
- //#region src/helpers/locale.d.ts
76
- /**
77
- * Get the current locale
78
- * @returns The current locale
79
- *
80
- * @example
81
- * const locale = getLocale();
82
- * console.log(locale); // 'en-US'
83
- */
84
- declare function getLocale(): string;
85
- /**
86
- * Get the current locales
87
- * @returns The current locales
88
- *
89
- * @example
90
- * const locales = getLocales();
91
- * console.log(locales); // ['en-US', 'es-ES']
92
- */
93
- declare function getLocales(): string[];
94
- /**
95
- * Get the default locale
96
- * @returns The default locale
97
- *
98
- * @example
99
- * const defaultLocale = getDefaultLocale();
100
- * console.log(defaultLocale); // 'en-US'
101
- */
102
- declare function getDefaultLocale(): string;
103
- /**
104
- * Get the locale properties
105
- * @param {string} [locale] - The locale to get the properties for. When not provided, uses the current locale.
106
- * @returns The locale properties
107
- *
108
- * @example
109
- * const localeProperties = getLocaleProperties();
110
- *
111
- * @example
112
- * const localeProperties = getLocaleProperties('en-US');
113
- */
114
- declare function getLocaleProperties(locale?: string): _$generaltranslation_types0.LocaleProperties;
115
- //#endregion
116
- //#region src/helpers/versionId.d.ts
117
- /**
118
- * Get the version ID for the current source
119
- * @returns The version ID, if set
120
- *
121
- * @example
122
- * const versionId = getVersionId();
123
- * console.log(versionId); // 'abc123'
124
- */
125
- declare function getVersionId(): string | undefined;
126
- //#endregion
127
74
  export { declareStatic, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getDefaultLocale, getLocale, getLocaleProperties, getLocales, getVersionId, gtFallback, mFallback, msg, t };
128
75
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -1,18 +1,17 @@
1
- import { a as InlineTranslationOptions } from "./options-B-yFI8LM.mjs";
2
- import { a as SyncResolutionFunctionWithFallback } from "./functions-CPODsB3C.mjs";
3
- import { n as gtFallback, t as mFallback } from "./index-DdPo_-bU.mjs";
1
+ import { a as InlineTranslationOptions } from "./options-gL1Zt8jG.mjs";
2
+ import { n as gtFallback, t as mFallback } from "./index-YDEznmyZ.mjs";
4
3
  import { t as RegisterableMessages } from "./message-BN4DirTg.mjs";
4
+ import { a as getLocales, i as getLocaleProperties, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./index-DUcoQ9y0.mjs";
5
5
  import { declareStatic, declareVar, decodeVars, derive } from "generaltranslation/internal";
6
- import * as _$generaltranslation_types0 from "generaltranslation/types";
7
6
 
8
7
  //#region src/translation-functions/t.d.ts
9
8
  /**
10
9
  * Translate a message
11
10
  * @param {string} message - The message to translate.
12
- * @param {InlineTranslationOptions} options - The options for the translation.
11
+ * @param options - The options for the translation.
13
12
  * @returns The translated message.
14
13
  */
15
- declare const t: SyncResolutionFunctionWithFallback;
14
+ declare function t(message: string, options?: InlineTranslationOptions): string;
16
15
  //#endregion
17
16
  //#region src/translation-functions/msg/msg.d.ts
18
17
  /**
@@ -72,57 +71,5 @@ declare function decodeMsg<T extends string | null | undefined>(encodedMsg: T):
72
71
  */
73
72
  declare function decodeOptions(encodedMsg: string): InlineTranslationOptions | null;
74
73
  //#endregion
75
- //#region src/helpers/locale.d.ts
76
- /**
77
- * Get the current locale
78
- * @returns The current locale
79
- *
80
- * @example
81
- * const locale = getLocale();
82
- * console.log(locale); // 'en-US'
83
- */
84
- declare function getLocale(): string;
85
- /**
86
- * Get the current locales
87
- * @returns The current locales
88
- *
89
- * @example
90
- * const locales = getLocales();
91
- * console.log(locales); // ['en-US', 'es-ES']
92
- */
93
- declare function getLocales(): string[];
94
- /**
95
- * Get the default locale
96
- * @returns The default locale
97
- *
98
- * @example
99
- * const defaultLocale = getDefaultLocale();
100
- * console.log(defaultLocale); // 'en-US'
101
- */
102
- declare function getDefaultLocale(): string;
103
- /**
104
- * Get the locale properties
105
- * @param {string} [locale] - The locale to get the properties for. When not provided, uses the current locale.
106
- * @returns The locale properties
107
- *
108
- * @example
109
- * const localeProperties = getLocaleProperties();
110
- *
111
- * @example
112
- * const localeProperties = getLocaleProperties('en-US');
113
- */
114
- declare function getLocaleProperties(locale?: string): _$generaltranslation_types0.LocaleProperties;
115
- //#endregion
116
- //#region src/helpers/versionId.d.ts
117
- /**
118
- * Get the version ID for the current source
119
- * @returns The version ID, if set
120
- *
121
- * @example
122
- * const versionId = getVersionId();
123
- * console.log(versionId); // 'abc123'
124
- */
125
- declare function getVersionId(): string | undefined;
126
- //#endregion
127
74
  export { declareStatic, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getDefaultLocale, getLocale, getLocaleProperties, getLocales, getVersionId, gtFallback, mFallback, msg, t };
128
75
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { a as extractVariables, i as createInterpolationFailureMessage, n as decodeOptions, o as logger_default } from "./isEncodedTranslationOptions-DdHEzDDM.mjs";
2
- import { a as resolveStringContentWithFallback, c as getI18nManager, d as hashMessage } from "./helpers-DB3t35tn.mjs";
2
+ import { a as getLocales, d as resolveStringContentWithFallback, i as getLocaleProperties, m as getCurrentLocale, n as getDefaultLocale, r as getLocale, t as getVersionId, y as hashMessage } from "./versionId-ahkgeth1.mjs";
3
3
  import { n as gtFallback, r as decodeMsg, t as mFallback } from "./mFallback-BQX_yiE-.mjs";
4
4
  import { VAR_IDENTIFIER, declareStatic, declareVar, decodeVars, derive, encode, libraryDefaultLocale } from "generaltranslation/internal";
5
5
  import { formatMessage } from "generaltranslation/core";
@@ -7,15 +7,15 @@ import { formatMessage } from "generaltranslation/core";
7
7
  /**
8
8
  * Translate a message
9
9
  * @param {string} message - The message to translate.
10
- * @param {InlineTranslationOptions} options - The options for the translation.
10
+ * @param options - The options for the translation.
11
11
  * @returns The translated message.
12
12
  */
13
- const t = (message, options) => {
14
- return resolveStringContentWithFallback(message, {
13
+ function t(message, options = {}) {
14
+ return resolveStringContentWithFallback(options.$locale ?? getCurrentLocale(), message, {
15
15
  $format: "ICU",
16
16
  ...options
17
17
  });
18
- };
18
+ }
19
19
  //#endregion
20
20
  //#region src/translation-functions/msg/msg.ts
21
21
  function msg(message, options) {
@@ -55,68 +55,6 @@ function msg(message, options) {
55
55
  return `${interpolatedString}:${optionsEncoding}`;
56
56
  }
57
57
  //#endregion
58
- //#region src/helpers/locale.ts
59
- /**
60
- * Get the current locale
61
- * @returns The current locale
62
- *
63
- * @example
64
- * const locale = getLocale();
65
- * console.log(locale); // 'en-US'
66
- */
67
- function getLocale() {
68
- return getI18nManager().getLocale();
69
- }
70
- /**
71
- * Get the current locales
72
- * @returns The current locales
73
- *
74
- * @example
75
- * const locales = getLocales();
76
- * console.log(locales); // ['en-US', 'es-ES']
77
- */
78
- function getLocales() {
79
- return getI18nManager().getLocales();
80
- }
81
- /**
82
- * Get the default locale
83
- * @returns The default locale
84
- *
85
- * @example
86
- * const defaultLocale = getDefaultLocale();
87
- * console.log(defaultLocale); // 'en-US'
88
- */
89
- function getDefaultLocale() {
90
- return getI18nManager().getDefaultLocale();
91
- }
92
- /**
93
- * Get the locale properties
94
- * @param {string} [locale] - The locale to get the properties for. When not provided, uses the current locale.
95
- * @returns The locale properties
96
- *
97
- * @example
98
- * const localeProperties = getLocaleProperties();
99
- *
100
- * @example
101
- * const localeProperties = getLocaleProperties('en-US');
102
- */
103
- function getLocaleProperties(locale) {
104
- return getI18nManager().getGTClass().getLocaleProperties(locale);
105
- }
106
- //#endregion
107
- //#region src/helpers/versionId.ts
108
- /**
109
- * Get the version ID for the current source
110
- * @returns The version ID, if set
111
- *
112
- * @example
113
- * const versionId = getVersionId();
114
- * console.log(versionId); // 'abc123'
115
- */
116
- function getVersionId() {
117
- return getI18nManager().getVersionId();
118
- }
119
- //#endregion
120
58
  export { declareStatic, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getDefaultLocale, getLocale, getLocaleProperties, getLocales, getVersionId, gtFallback, mFallback, msg, t };
121
59
 
122
60
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/translation-functions/t.ts","../src/translation-functions/msg/msg.ts","../src/helpers/locale.ts","../src/helpers/versionId.ts"],"sourcesContent":["import { resolveStringContentWithFallback } from './internal/helpers';\nimport { SyncResolutionFunctionWithFallback } from './types/functions';\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 The translated message.\n */\nexport const t: SyncResolutionFunctionWithFallback = (message, options) => {\n return resolveStringContentWithFallback(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","import { getI18nManager } from '../i18n-manager/singleton-operations';\n\n/**\n * Get the current locale\n * @returns The current locale\n *\n * @example\n * const locale = getLocale();\n * console.log(locale); // 'en-US'\n */\nexport function getLocale() {\n const i18nManager = getI18nManager();\n return i18nManager.getLocale();\n}\n\n/**\n * Get the current locales\n * @returns The current locales\n *\n * @example\n * const locales = getLocales();\n * console.log(locales); // ['en-US', 'es-ES']\n */\nexport function getLocales() {\n const i18nManager = getI18nManager();\n return i18nManager.getLocales();\n}\n\n/**\n * Get the default locale\n * @returns The default locale\n *\n * @example\n * const defaultLocale = getDefaultLocale();\n * console.log(defaultLocale); // 'en-US'\n */\nexport function getDefaultLocale() {\n const i18nManager = getI18nManager();\n return i18nManager.getDefaultLocale();\n}\n\n/**\n * Get the locale properties\n * @param {string} [locale] - The locale to get the properties for. When not provided, uses the current locale.\n * @returns The locale properties\n *\n * @example\n * const localeProperties = getLocaleProperties();\n *\n * @example\n * const localeProperties = getLocaleProperties('en-US');\n */\nexport function getLocaleProperties(locale?: string) {\n const i18nManager = getI18nManager();\n const gtInstance = i18nManager.getGTClass();\n return gtInstance.getLocaleProperties(locale);\n}\n","import { getI18nManager } from '../i18n-manager/singleton-operations';\n\n/**\n * Get the version ID for the current source\n * @returns The version ID, if set\n *\n * @example\n * const versionId = getVersionId();\n * console.log(versionId); // 'abc123'\n */\nexport function getVersionId() {\n const i18nManager = getI18nManager();\n return i18nManager.getVersionId();\n}\n"],"mappings":";;;;;;;;;;;;AASA,MAAa,KAAyC,SAAS,YAAY;AACzE,QAAO,iCAAiC,SAAS;EAC/C,SAAS;EACT,GAAG;EACJ,CAAC;;;;AC0CJ,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;;;;;;;;;;;;ACpGlC,SAAgB,YAAY;AAE1B,QADoB,gBACF,CAAC,WAAW;;;;;;;;;;AAWhC,SAAgB,aAAa;AAE3B,QADoB,gBACF,CAAC,YAAY;;;;;;;;;;AAWjC,SAAgB,mBAAmB;AAEjC,QADoB,gBACF,CAAC,kBAAkB;;;;;;;;;;;;;AAcvC,SAAgB,oBAAoB,QAAiB;AAGnD,QAFoB,gBACU,CAAC,YACd,CAAC,oBAAoB,OAAO;;;;;;;;;;;;AC7C/C,SAAgB,eAAe;AAE7B,QADoB,gBACF,CAAC,cAAc"}
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"}