gt-next 6.16.27 → 6.16.29

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 (181) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/_dictionary.js +8 -5
  3. package/dist/_dictionary.js.map +1 -1
  4. package/dist/_load-dictionary.js +8 -5
  5. package/dist/_load-dictionary.js.map +1 -1
  6. package/dist/_load-translations.js +8 -5
  7. package/dist/_load-translations.js.map +1 -1
  8. package/dist/_request.js +11 -8
  9. package/dist/_request.js.map +1 -1
  10. package/dist/_virtual/_rolldown/runtime.js +23 -0
  11. package/dist/branches/Branch.js +34 -49
  12. package/dist/branches/Branch.js.map +1 -1
  13. package/dist/branches/Plural.js +36 -47
  14. package/dist/branches/Plural.js.map +1 -1
  15. package/dist/client.js +32 -34
  16. package/dist/config-dir/DictionaryManager.js +49 -103
  17. package/dist/config-dir/DictionaryManager.js.map +1 -1
  18. package/dist/config-dir/I18NConfiguration.js +201 -339
  19. package/dist/config-dir/I18NConfiguration.js.map +1 -1
  20. package/dist/config-dir/getI18NConfig.js +42 -61
  21. package/dist/config-dir/getI18NConfig.js.map +1 -1
  22. package/dist/config-dir/loadTranslation.js +36 -113
  23. package/dist/config-dir/loadTranslation.js.map +1 -1
  24. package/dist/config-dir/props/defaultWithGTConfigProps.js +43 -78
  25. package/dist/config-dir/props/defaultWithGTConfigProps.js.map +1 -1
  26. package/dist/config-dir/props/withGTConfigProps.d.ts +8 -0
  27. package/dist/config-dir/props/withGTConfigProps.d.ts.map +1 -1
  28. package/dist/config-dir/props/withGTConfigProps.js +15 -18
  29. package/dist/config-dir/props/withGTConfigProps.js.map +1 -1
  30. package/dist/config-dir/utils/resolveConfigFilepath.js +27 -37
  31. package/dist/config-dir/utils/resolveConfigFilepath.js.map +1 -1
  32. package/dist/config-dir/utils/resolveRequestFunctionPaths.js +27 -39
  33. package/dist/config-dir/utils/resolveRequestFunctionPaths.js.map +1 -1
  34. package/dist/config-dir/utils/validateCompiler.js +27 -35
  35. package/dist/config-dir/utils/validateCompiler.js.map +1 -1
  36. package/dist/config.d.ts +2 -2
  37. package/dist/config.js +329 -520
  38. package/dist/config.js.map +1 -1
  39. package/dist/dictionary/getDictionary.js +46 -115
  40. package/dist/dictionary/getDictionary.js.map +1 -1
  41. package/dist/dictionary/setDictionary.js +7 -5
  42. package/dist/dictionary/setDictionary.js.map +1 -1
  43. package/dist/errors/cacheComponents.d.ts +7 -6
  44. package/dist/errors/cacheComponents.d.ts.map +1 -1
  45. package/dist/errors/cacheComponents.js +52 -13
  46. package/dist/errors/cacheComponents.js.map +1 -1
  47. package/dist/errors/createErrors.d.ts +12 -12
  48. package/dist/errors/createErrors.d.ts.map +1 -1
  49. package/dist/errors/createErrors.js +236 -165
  50. package/dist/errors/createErrors.js.map +1 -1
  51. package/dist/errors/diagnostics.d.ts +6 -0
  52. package/dist/errors/diagnostics.d.ts.map +1 -0
  53. package/dist/errors/diagnostics.js +22 -0
  54. package/dist/errors/diagnostics.js.map +1 -0
  55. package/dist/errors/ssg.d.ts +7 -7
  56. package/dist/errors/ssg.d.ts.map +1 -1
  57. package/dist/errors/ssg.js +60 -32
  58. package/dist/errors/ssg.js.map +1 -1
  59. package/dist/index.client.d.ts +3 -2
  60. package/dist/index.client.d.ts.map +1 -1
  61. package/dist/index.client.js +43 -43
  62. package/dist/index.client.js.map +1 -1
  63. package/dist/index.server.d.ts +3 -2
  64. package/dist/index.server.d.ts.map +1 -1
  65. package/dist/index.server.js +60 -58
  66. package/dist/index.server.js.map +1 -1
  67. package/dist/index.types.d.ts +2 -2
  68. package/dist/index.types.d.ts.map +1 -1
  69. package/dist/index.types.js +464 -462
  70. package/dist/index.types.js.map +1 -1
  71. package/dist/internal/_getDomain.js +11 -51
  72. package/dist/internal/_getDomain.js.map +1 -1
  73. package/dist/internal/_getLocale.js +11 -51
  74. package/dist/internal/_getLocale.js.map +1 -1
  75. package/dist/internal/_getRegion.js +11 -51
  76. package/dist/internal/_getRegion.js.map +1 -1
  77. package/dist/internal/static/_getDomain.js +11 -48
  78. package/dist/internal/static/_getDomain.js.map +1 -1
  79. package/dist/internal/static/_getLocale.js +11 -48
  80. package/dist/internal/static/_getLocale.js.map +1 -1
  81. package/dist/internal/static/_getRegion.js +11 -48
  82. package/dist/internal/static/_getRegion.js.map +1 -1
  83. package/dist/middleware-dir/createNextMiddleware.js +129 -233
  84. package/dist/middleware-dir/createNextMiddleware.js.map +1 -1
  85. package/dist/middleware-dir/utils.js +145 -244
  86. package/dist/middleware-dir/utils.js.map +1 -1
  87. package/dist/middleware.js +3 -6
  88. package/dist/plugin/checks/cacheComponentsChecks.d.ts.map +1 -1
  89. package/dist/plugin/checks/cacheComponentsChecks.js +20 -37
  90. package/dist/plugin/checks/cacheComponentsChecks.js.map +1 -1
  91. package/dist/plugin/checks/ssgChecks.js +10 -21
  92. package/dist/plugin/checks/ssgChecks.js.map +1 -1
  93. package/dist/plugin/constants.js +15 -10
  94. package/dist/plugin/constants.js.map +1 -1
  95. package/dist/plugin/getStableNextVersionInfo.d.ts.map +1 -1
  96. package/dist/plugin/getStableNextVersionInfo.js +60 -63
  97. package/dist/plugin/getStableNextVersionInfo.js.map +1 -1
  98. package/dist/provider/ClientProviderWrapper.js +65 -88
  99. package/dist/provider/ClientProviderWrapper.js.map +1 -1
  100. package/dist/provider/GTProvider.js +44 -132
  101. package/dist/provider/GTProvider.js.map +1 -1
  102. package/dist/request/getLocale.js +35 -94
  103. package/dist/request/getLocale.js.map +1 -1
  104. package/dist/request/getLocaleDirection.js +24 -30
  105. package/dist/request/getLocaleDirection.js.map +1 -1
  106. package/dist/request/getRegion.js +23 -74
  107. package/dist/request/getRegion.js.map +1 -1
  108. package/dist/request/headers/getNextDomain.js +17 -60
  109. package/dist/request/headers/getNextDomain.js.map +1 -1
  110. package/dist/request/headers/getNextLocale.js +34 -90
  111. package/dist/request/headers/getNextLocale.js.map +1 -1
  112. package/dist/request/headers/getNextRegion.js +10 -55
  113. package/dist/request/headers/getNextRegion.js.map +1 -1
  114. package/dist/request/localeStore.js +7 -5
  115. package/dist/request/localeStore.js.map +1 -1
  116. package/dist/request/registerLocale.js +15 -13
  117. package/dist/request/registerLocale.js.map +1 -1
  118. package/dist/request/types.js +16 -13
  119. package/dist/request/types.js.map +1 -1
  120. package/dist/request/utils/getRequestFunction.js +122 -214
  121. package/dist/request/utils/getRequestFunction.js.map +1 -1
  122. package/dist/request/utils/isSSR.js +21 -26
  123. package/dist/request/utils/isSSR.js.map +1 -1
  124. package/dist/request/utils/legacyGetLocaleFunction.js +17 -70
  125. package/dist/request/utils/legacyGetLocaleFunction.js.map +1 -1
  126. package/dist/request/utils/legacyGetRegionFunction.js +14 -65
  127. package/dist/request/utils/legacyGetRegionFunction.js.map +1 -1
  128. package/dist/request/utils/legacyGetRequestFunction.js +157 -250
  129. package/dist/request/utils/legacyGetRequestFunction.js.map +1 -1
  130. package/dist/resolvers/resolveDictionaryLoader.js +20 -74
  131. package/dist/resolvers/resolveDictionaryLoader.js.map +1 -1
  132. package/dist/resolvers/resolveTranslationLoader.js +20 -74
  133. package/dist/resolvers/resolveTranslationLoader.js.map +1 -1
  134. package/dist/server-dir/buildtime/T.js +122 -205
  135. package/dist/server-dir/buildtime/T.js.map +1 -1
  136. package/dist/server-dir/buildtime/getTranslationFunction.d.ts +1 -1
  137. package/dist/server-dir/buildtime/getTranslationFunction.d.ts.map +1 -1
  138. package/dist/server-dir/buildtime/getTranslationFunction.js +269 -406
  139. package/dist/server-dir/buildtime/getTranslationFunction.js.map +1 -1
  140. package/dist/server-dir/buildtime/getTranslations.d.ts +1 -1
  141. package/dist/server-dir/buildtime/getTranslations.d.ts.map +1 -1
  142. package/dist/server-dir/buildtime/getTranslations.js +235 -361
  143. package/dist/server-dir/buildtime/getTranslations.js.map +1 -1
  144. package/dist/server-dir/runtime/_Tx.js +105 -207
  145. package/dist/server-dir/runtime/_Tx.js.map +1 -1
  146. package/dist/server-dir/runtime/tx.js +103 -173
  147. package/dist/server-dir/runtime/tx.js.map +1 -1
  148. package/dist/server-dir/variables/renderVariable.js +40 -47
  149. package/dist/server-dir/variables/renderVariable.js.map +1 -1
  150. package/dist/server.js +80 -43
  151. package/dist/server.js.map +1 -1
  152. package/dist/types.d.ts +2 -2
  153. package/dist/types.d.ts.map +1 -1
  154. package/dist/types.js +1 -3
  155. package/dist/utils/constants.js +6 -4
  156. package/dist/utils/constants.js.map +1 -1
  157. package/dist/utils/cookies.js +16 -12
  158. package/dist/utils/cookies.js.map +1 -1
  159. package/dist/utils/errors.js +18 -35
  160. package/dist/utils/errors.js.map +1 -1
  161. package/dist/utils/headers.js +8 -6
  162. package/dist/utils/headers.js.map +1 -1
  163. package/dist/utils/types.js +1 -3
  164. package/dist/utils/use.js +8 -72
  165. package/dist/utils/use.js.map +1 -1
  166. package/dist/variables/Currency.js +36 -48
  167. package/dist/variables/Currency.js.map +1 -1
  168. package/dist/variables/DateTime.js +34 -49
  169. package/dist/variables/DateTime.js.map +1 -1
  170. package/dist/variables/Num.js +38 -50
  171. package/dist/variables/Num.js.map +1 -1
  172. package/dist/variables/RelativeTime.js +56 -68
  173. package/dist/variables/RelativeTime.js.map +1 -1
  174. package/dist/variables/Var.js +25 -21
  175. package/dist/variables/Var.js.map +1 -1
  176. package/package.json +10 -8
  177. package/dist/client.js.map +0 -1
  178. package/dist/gt_swc_plugin.wasm +0 -0
  179. package/dist/middleware.js.map +0 -1
  180. package/dist/types.js.map +0 -1
  181. package/dist/utils/types.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # gt-next
2
2
 
3
+ ## 6.16.29
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1437](https://github.com/generaltranslation/gt/pull/1437) [`fd61c44`](https://github.com/generaltranslation/gt/commit/fd61c4487a790e0802021478986b8c5b3dc0fb2b) Thanks [@bgub](https://github.com/bgub)! - Deprecate `experimentalLocaleResolution` and update cache components warnings to recommend explicit custom `getLocale.ts` and `getRegion.ts` request functions instead of automatic root parameter detection.
8
+
9
+ - Updated dependencies [[`cc4edc1`](https://github.com/generaltranslation/gt/commit/cc4edc1e40d9977125bf6d053fb7f8cdbdd40b05)]:
10
+ - @generaltranslation/supported-locales@2.1.0
11
+ - gt-i18n@0.9.4
12
+ - gt-react@10.19.18
13
+
14
+ ## 6.16.28
15
+
16
+ ### Patch Changes
17
+
18
+ - [#1419](https://github.com/generaltranslation/gt/pull/1419) [`a877a2a`](https://github.com/generaltranslation/gt/commit/a877a2a5bd5ca47b199c6caf53a6d60d96e3a300) Thanks [@bgub](https://github.com/bgub)! - Improve diagnostic messages and package-local diagnostic formatting.
19
+
20
+ - Updated dependencies [[`bb3624e`](https://github.com/generaltranslation/gt/commit/bb3624e58546c334c04370a1f5a262238bd040fa), [`a877a2a`](https://github.com/generaltranslation/gt/commit/a877a2a5bd5ca47b199c6caf53a6d60d96e3a300)]:
21
+ - @generaltranslation/format@0.1.1
22
+ - generaltranslation@8.2.15
23
+ - gt-i18n@0.9.3
24
+ - gt-react@10.19.17
25
+ - @generaltranslation/compiler@1.3.23
26
+ - @generaltranslation/supported-locales@2.0.73
27
+
3
28
  ## 6.16.27
4
29
 
5
30
  ### Patch Changes
@@ -1,6 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // hidden internal route
4
- exports.default = {};
5
- throw new Error("Something has gone seriously wrong if you're seeing this error message. Check docs.generaltranslation.com for the latest documentation and make sure you've got the library configured properly.");
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ //#region src/_dictionary.ts
6
+ var _dictionary_default = {};
7
+ throw new Error(`Something has gone seriously wrong if you're seeing this error message. Check docs.generaltranslation.com for the latest documentation and make sure you've got the library configured properly.`);
8
+
6
9
  //# sourceMappingURL=_dictionary.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_dictionary.js","sourceRoot":"","sources":["../src/_dictionary.ts"],"names":[],"mappings":";;AAAA,wBAAwB;AACxB,kBAAe,EAAE,CAAC;AAClB,MAAM,IAAI,KAAK,CACb,kMAAkM,CACnM,CAAC"}
1
+ {"version":3,"file":"_dictionary.js","names":[],"sources":["../src/_dictionary.ts"],"sourcesContent":["// hidden internal route\nexport default {};\nthrow new Error(\n `Something has gone seriously wrong if you're seeing this error message. Check docs.generaltranslation.com for the latest documentation and make sure you've got the library configured properly.`\n);\n"],"mappings":";;;;;AACA,IAAA,sBAAe,EAAE;AACjB,MAAM,IAAI,MACR,mMACD"}
@@ -1,6 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // hidden internal route
4
- exports.default = {};
5
- throw new Error("Something has gone seriously wrong if you're seeing this error message. Check docs.generaltranslation.com for the latest documentation and make sure you've got the library configured properly.");
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ //#region src/_load-dictionary.ts
6
+ var _load_dictionary_default = {};
7
+ throw new Error(`Something has gone seriously wrong if you're seeing this error message. Check docs.generaltranslation.com for the latest documentation and make sure you've got the library configured properly.`);
8
+
6
9
  //# sourceMappingURL=_load-dictionary.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_load-dictionary.js","sourceRoot":"","sources":["../src/_load-dictionary.ts"],"names":[],"mappings":";;AAAA,wBAAwB;AACxB,kBAAe,EAAE,CAAC;AAClB,MAAM,IAAI,KAAK,CACb,kMAAkM,CACnM,CAAC"}
1
+ {"version":3,"file":"_load-dictionary.js","names":[],"sources":["../src/_load-dictionary.ts"],"sourcesContent":["// hidden internal route\nexport default {};\nthrow new Error(\n `Something has gone seriously wrong if you're seeing this error message. Check docs.generaltranslation.com for the latest documentation and make sure you've got the library configured properly.`\n);\n"],"mappings":";;;;;AACA,IAAA,2BAAe,EAAE;AACjB,MAAM,IAAI,MACR,mMACD"}
@@ -1,6 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // hidden internal route
4
- exports.default = {};
5
- throw new Error("Something has gone seriously wrong if you're seeing this error message. Check docs.generaltranslation.com for the latest documentation and make sure you've got the library configured properly.");
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ //#region src/_load-translations.ts
6
+ var _load_translations_default = {};
7
+ throw new Error(`Something has gone seriously wrong if you're seeing this error message. Check docs.generaltranslation.com for the latest documentation and make sure you've got the library configured properly.`);
8
+
6
9
  //# sourceMappingURL=_load-translations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_load-translations.js","sourceRoot":"","sources":["../src/_load-translations.ts"],"names":[],"mappings":";;AAAA,wBAAwB;AACxB,kBAAe,EAAE,CAAC;AAClB,MAAM,IAAI,KAAK,CACb,kMAAkM,CACnM,CAAC"}
1
+ {"version":3,"file":"_load-translations.js","names":[],"sources":["../src/_load-translations.ts"],"sourcesContent":["// hidden internal route\nexport default {};\nthrow new Error(\n `Something has gone seriously wrong if you're seeing this error message. Check docs.generaltranslation.com for the latest documentation and make sure you've got the library configured properly.`\n);\n"],"mappings":";;;;;AACA,IAAA,6BAAe,EAAE;AACjB,MAAM,IAAI,MACR,mMACD"}
package/dist/_request.js CHANGED
@@ -1,9 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // hidden internal route
4
- exports.default = {
5
- getLocale: function () {
6
- throw new Error("Unable to import custom getLocale(). Check docs.generaltranslation.com for the latest documentation.");
7
- },
8
- };
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ //#region src/_request.ts
6
+ var _request_default = { getLocale: () => {
7
+ throw new Error(`Unable to import custom getLocale(). Check docs.generaltranslation.com for the latest documentation.`);
8
+ } };
9
+ //#endregion
10
+ exports.default = _request_default;
11
+
9
12
  //# sourceMappingURL=_request.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_request.js","sourceRoot":"","sources":["../src/_request.ts"],"names":[],"mappings":";;AAAA,wBAAwB;AACxB,kBAAe;IACb,SAAS,EAAE;QACT,MAAM,IAAI,KAAK,CACb,sGAAsG,CACvG,CAAC;IACJ,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"_request.js","names":[],"sources":["../src/_request.ts"],"sourcesContent":["// hidden internal route\nexport default {\n getLocale: () => {\n throw new Error(\n `Unable to import custom getLocale(). Check docs.generaltranslation.com for the latest documentation.`\n );\n },\n};\n"],"mappings":";;;;;AACA,IAAA,mBAAe,EACb,iBAAiB;AACf,OAAM,IAAI,MACR,uGACD;GAEJ"}
@@ -0,0 +1,23 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ exports.__toESM = __toESM;
@@ -1,53 +1,38 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.Branch = Branch;
15
- var jsx_runtime_1 = require("react/jsx-runtime");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../_virtual/_rolldown/runtime.js");
3
+ let react_jsx_runtime = require("react/jsx-runtime");
4
+ //#region src/branches/Branch.tsx
16
5
  /**
17
- * The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
18
- * It allows for flexible content switching based on the `branch` prop and an object of possible branches (`...branches`).
19
- * If the specified `branch` is present in the `branches` object, it renders the content of that branch.
20
- * If the `branch` is not found, it renders the provided `children` as fallback content.
21
- *
22
- * @example
23
- * ```jsx
24
- * <Branch
25
- * branch={user.gender}
26
- * female={<p>She is happy.</p>}
27
- * male={<p>He is happy.</p>}
28
- * >
29
- * <p>They are happy.</p>
30
- * </Branch>
31
- * ```
32
- * If the `branch` prop is set to `"male"`, it will render `<p>He is happy.</p>`. If the `branch` is set to "female" it will render `<p>She is happy.</p>`. If the gender is not set or does not match any props, it renders the fallback content `<p>Fallback content</p>`.
33
- *
34
- * @param {any} [children] - Fallback content to render if no matching branch is found.
35
- * @param {any} [branch] - The name of the branch to render. The component looks for this key in the `...branches` object.
36
- * @param {...branches} [branches] - A spread object containing possible branches as keys and their corresponding content as values.
37
- * @returns {React.JSX.Element} The rendered branch or fallback content.
38
- */
39
- function Branch(_a) {
40
- var children = _a.children, branch = _a.branch, branches = __rest(_a, ["children", "branch"]);
41
- branch = branch === null || branch === void 0 ? void 0 : branch.toString();
42
- // ignore data-* attributes
43
- if (typeof branch === 'string' && branch.startsWith('data-')) {
44
- branch = undefined;
45
- }
46
- var renderedBranch = branch && typeof branches[branch] !== 'undefined'
47
- ? branches[branch]
48
- : children;
49
- return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: renderedBranch });
6
+ * The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
7
+ * It allows for flexible content switching based on the `branch` prop and an object of possible branches (`...branches`).
8
+ * If the specified `branch` is present in the `branches` object, it renders the content of that branch.
9
+ * If the `branch` is not found, it renders the provided `children` as fallback content.
10
+ *
11
+ * @example
12
+ * ```jsx
13
+ * <Branch
14
+ * branch={user.gender}
15
+ * female={<p>She is happy.</p>}
16
+ * male={<p>He is happy.</p>}
17
+ * >
18
+ * <p>They are happy.</p>
19
+ * </Branch>
20
+ * ```
21
+ * If the `branch` prop is set to `"male"`, it will render `<p>He is happy.</p>`. If the `branch` is set to "female" it will render `<p>She is happy.</p>`. If the gender is not set or does not match any props, it renders the fallback content `<p>Fallback content</p>`.
22
+ *
23
+ * @param {any} [children] - Fallback content to render if no matching branch is found.
24
+ * @param {any} [branch] - The name of the branch to render. The component looks for this key in the `...branches` object.
25
+ * @param {...branches} [branches] - A spread object containing possible branches as keys and their corresponding content as values.
26
+ * @returns {React.JSX.Element} The rendered branch or fallback content.
27
+ */
28
+ function Branch({ children, branch, ...branches }) {
29
+ branch = branch?.toString();
30
+ if (typeof branch === "string" && branch.startsWith("data-")) branch = void 0;
31
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: branch && typeof branches[branch] !== "undefined" ? branches[branch] : children });
50
32
  }
51
33
  /** @internal _gtt - The GT transformation for the component. */
52
- Branch._gtt = 'branch';
34
+ Branch._gtt = "branch";
35
+ //#endregion
36
+ exports.Branch = Branch;
37
+
53
38
  //# sourceMappingURL=Branch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Branch.js","sourceRoot":"","sources":["../../src/branches/Branch.tsx"],"names":[],"mappings":";;;;;;;;;;;;;AAyBA,wBAmBC;;AA1CD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,MAAM,CAAC,EAQtB;IAPC,IAAA,QAAQ,cAAA,EACR,MAAM,YAAA,EACH,QAAQ,cAHU,sBAItB,CADY;IAMX,MAAM,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,EAAE,CAAC;IAC5B,2BAA2B;IAC3B,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7D,MAAM,GAAG,SAAS,CAAC;IACrB,CAAC;IACD,IAAM,cAAc,GAClB,MAAM,IAAI,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,WAAW;QAC/C,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;QAClB,CAAC,CAAC,QAAQ,CAAC;IACf,OAAO,2DAAG,cAAc,GAAI,CAAC;AAC/B,CAAC;AACD,gEAAgE;AAChE,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC"}
1
+ {"version":3,"file":"Branch.js","names":[],"sources":["../../src/branches/Branch.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\n/**\n * The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.\n * It allows for flexible content switching based on the `branch` prop and an object of possible branches (`...branches`).\n * If the specified `branch` is present in the `branches` object, it renders the content of that branch.\n * If the `branch` is not found, it renders the provided `children` as fallback content.\n *\n * @example\n * ```jsx\n * <Branch\n * branch={user.gender}\n * female={<p>She is happy.</p>}\n * male={<p>He is happy.</p>}\n * >\n * <p>They are happy.</p>\n * </Branch>\n * ```\n * If the `branch` prop is set to `\"male\"`, it will render `<p>He is happy.</p>`. If the `branch` is set to \"female\" it will render `<p>She is happy.</p>`. If the gender is not set or does not match any props, it renders the fallback content `<p>Fallback content</p>`.\n *\n * @param {any} [children] - Fallback content to render if no matching branch is found.\n * @param {any} [branch] - The name of the branch to render. The component looks for this key in the `...branches` object.\n * @param {...branches} [branches] - A spread object containing possible branches as keys and their corresponding content as values.\n * @returns {React.JSX.Element} The rendered branch or fallback content.\n */\nexport function Branch({\n children,\n branch,\n ...branches\n}: {\n children?: ReactNode;\n branch?: string | number | boolean;\n [key: string]: ReactNode;\n}): React.JSX.Element {\n branch = branch?.toString();\n // ignore data-* attributes\n if (typeof branch === 'string' && branch.startsWith('data-')) {\n branch = undefined;\n }\n const renderedBranch =\n branch && typeof branches[branch] !== 'undefined'\n ? branches[branch]\n : children;\n return <>{renderedBranch}</>;\n}\n/** @internal _gtt - The GT transformation for the component. */\nBranch._gtt = 'branch';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,OAAO,EACrB,UACA,QACA,GAAG,YAKiB;AACpB,UAAS,QAAQ,UAAU;AAE3B,KAAI,OAAO,WAAW,YAAY,OAAO,WAAW,QAAQ,CAC1D,UAAS,KAAA;AAMX,QAAO,iBAAA,GAAA,kBAAA,KAAA,kBAAA,UAAA,EAAA,UAHL,UAAU,OAAO,SAAS,YAAY,cAClC,SAAS,UACT,UACsB,CAAA;;;AAG9B,OAAO,OAAO"}
@@ -1,51 +1,40 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.Plural = Plural;
15
- var jsx_runtime_1 = require("react/jsx-runtime");
16
- var internal_1 = require("gt-react/internal");
17
- var getI18NConfig_1 = require("../config-dir/getI18NConfig");
18
- var getLocale_1 = require("../request/getLocale");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../_virtual/_rolldown/runtime.js");
3
+ const require_config_dir_getI18NConfig = require("../config-dir/getI18NConfig.js");
4
+ const require_request_getLocale = require("../request/getLocale.js");
5
+ let gt_react_internal = require("gt-react/internal");
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+ //#region src/branches/Plural.tsx
19
8
  /**
20
- * The `<Plural>` component dynamically renders content based on the plural form of the given number (`n`).
21
- * It determines which content to display by matching the value of `n` to the appropriate pluralization branch,
22
- * based on the current locale or a default locale. If no matching plural branch is found, the component renders
23
- * the fallback `children` content.
24
- *
25
- * @example
26
- * ```jsx
27
- * <Plural
28
- * n={n}
29
- * one={<>There is <Num children={n}/> item.</>}
30
- * other={<>There are <Num children={n}/> items.</>}
31
- * />
32
- * ```
33
- * In this ex ample, if `n` is 1, it renders `"There is 1 item"`. If `n` is a different number, it renders
34
- * `"There are {n} items"`.
35
- *
36
- * @param {any} [children] - Fallback content to render if no matching plural branch is found.
37
- * @param {number} [n] - The number used to determine the plural form. This is required for pluralization to work.
38
- * @param {...branches} [branches] - A spread object containing possible plural branches, typically including `one` for singular
39
- * and `other` for plural forms, but it may vary depending on the locale.
40
- * @returns {React.JSX.Element} The rendered content corresponding to the plural form of `n`, or the fallback content.
41
- * @throws {Error} If `n` is not provided or not a valid number.
42
- */
43
- function Plural(_a) {
44
- var children = _a.children, n = _a.n, _b = _a.locales, locales = _b === void 0 ? [(0, getLocale_1.useLocale)(), (0, getI18NConfig_1.getI18NConfig)().getDefaultLocale()] : _b, branches = __rest(_a, ["children", "n", "locales"]);
45
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (typeof n === 'number'
46
- ? (0, internal_1.getPluralBranch)(n, locales, branches)
47
- : children) || children }));
9
+ * The `<Plural>` component dynamically renders content based on the plural form of the given number (`n`).
10
+ * It determines which content to display by matching the value of `n` to the appropriate pluralization branch,
11
+ * based on the current locale or a default locale. If no matching plural branch is found, the component renders
12
+ * the fallback `children` content.
13
+ *
14
+ * @example
15
+ * ```jsx
16
+ * <Plural
17
+ * n={n}
18
+ * one={<>There is <Num children={n}/> item.</>}
19
+ * other={<>There are <Num children={n}/> items.</>}
20
+ * />
21
+ * ```
22
+ * In this ex ample, if `n` is 1, it renders `"There is 1 item"`. If `n` is a different number, it renders
23
+ * `"There are {n} items"`.
24
+ *
25
+ * @param {any} [children] - Fallback content to render if no matching plural branch is found.
26
+ * @param {number} [n] - The number used to determine the plural form. This is required for pluralization to work.
27
+ * @param {...branches} [branches] - A spread object containing possible plural branches, typically including `one` for singular
28
+ * and `other` for plural forms, but it may vary depending on the locale.
29
+ * @returns {React.JSX.Element} The rendered content corresponding to the plural form of `n`, or the fallback content.
30
+ * @throws {Error} If `n` is not provided or not a valid number.
31
+ */
32
+ function Plural({ children, n, locales = [require_request_getLocale.useLocale(), require_config_dir_getI18NConfig.getI18NConfig().getDefaultLocale()], ...branches }) {
33
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: (typeof n === "number" ? (0, gt_react_internal.getPluralBranch)(n, locales, branches) : children) || children });
48
34
  }
49
35
  /** @internal _gtt - The GT transformation for the component. */
50
- Plural._gtt = 'plural';
36
+ Plural._gtt = "plural";
37
+ //#endregion
38
+ exports.Plural = Plural;
39
+
51
40
  //# sourceMappingURL=Plural.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Plural.js","sourceRoot":"","sources":["../../src/branches/Plural.tsx"],"names":[],"mappings":";;;;;;;;;;;;;AA6BA,wBAkBC;;AA/CD,8CAAoD;AAEpD,6DAA4D;AAC5D,kDAAiD;AAEjD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,MAAM,CAAC,EAUtB;IATC,IAAA,QAAQ,cAAA,EACR,CAAC,OAAA,EACD,eAA2D,EAA3D,OAAO,mBAAG,CAAC,IAAA,qBAAS,GAAE,EAAE,IAAA,6BAAa,GAAE,CAAC,gBAAgB,EAAE,CAAC,KAAA,EACxD,QAAQ,cAJU,4BAKtB,CADY;IAOX,OAAO,CACL,2DACG,CAAC,OAAO,CAAC,KAAK,QAAQ;YACrB,CAAC,CAAC,IAAA,0BAAe,EAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC;YACvC,CAAC,CAAC,QAAQ,CAAC,IAAI,QAAQ,GACxB,CACJ,CAAC;AACJ,CAAC;AACD,gEAAgE;AAChE,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC"}
1
+ {"version":3,"file":"Plural.js","names":["useLocale","getI18NConfig"],"sources":["../../src/branches/Plural.tsx"],"sourcesContent":["import { getPluralBranch } from 'gt-react/internal';\nimport type { ReactNode } from 'react';\nimport { getI18NConfig } from '../config-dir/getI18NConfig';\nimport { useLocale } from '../request/getLocale';\n\n/**\n * The `<Plural>` component dynamically renders content based on the plural form of the given number (`n`).\n * It determines which content to display by matching the value of `n` to the appropriate pluralization branch,\n * based on the current locale or a default locale. If no matching plural branch is found, the component renders\n * the fallback `children` content.\n *\n * @example\n * ```jsx\n * <Plural\n * n={n}\n * one={<>There is <Num children={n}/> item.</>}\n * other={<>There are <Num children={n}/> items.</>}\n * />\n * ```\n * In this ex ample, if `n` is 1, it renders `\"There is 1 item\"`. If `n` is a different number, it renders\n * `\"There are {n} items\"`.\n *\n * @param {any} [children] - Fallback content to render if no matching plural branch is found.\n * @param {number} [n] - The number used to determine the plural form. This is required for pluralization to work.\n * @param {...branches} [branches] - A spread object containing possible plural branches, typically including `one` for singular\n * and `other` for plural forms, but it may vary depending on the locale.\n * @returns {React.JSX.Element} The rendered content corresponding to the plural form of `n`, or the fallback content.\n * @throws {Error} If `n` is not provided or not a valid number.\n */\nexport function Plural({\n children,\n n,\n locales = [useLocale(), getI18NConfig().getDefaultLocale()],\n ...branches\n}: {\n children?: ReactNode;\n n?: number;\n locales?: string[];\n [key: string]: ReactNode;\n}) {\n return (\n <>\n {(typeof n === 'number'\n ? getPluralBranch(n, locales, branches)\n : children) || children}\n </>\n );\n}\n/** @internal _gtt - The GT transformation for the component. */\nPlural._gtt = 'plural';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,OAAO,EACrB,UACA,GACA,UAAU,CAACA,0BAAAA,WAAW,EAAEC,iCAAAA,eAAe,CAAC,kBAAkB,CAAC,EAC3D,GAAG,YAMF;AACD,QACE,iBAAA,GAAA,kBAAA,KAAA,kBAAA,UAAA,EAAA,WACI,OAAO,MAAM,YAAA,GAAA,kBAAA,iBACK,GAAG,SAAS,SAAS,GACrC,aAAa,UAChB,CAAA;;;AAIP,OAAO,OAAO"}
package/dist/client.js CHANGED
@@ -1,34 +1,32 @@
1
- "use strict";
2
- 'use client';
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.RegionSelector = exports.LocaleSelector = exports.Branch = exports.Plural = exports.Num = exports.RelativeTime = exports.DateTime = exports.Currency = exports.Var = exports.T = exports.GTClientProvider = exports.useMessages = exports.decodeOptions = exports.decodeMsg = exports.msg = exports.useVersionId = exports.useLocaleDirection = exports.useLocaleProperties = exports.useGTClass = exports.useRegionSelector = exports.useRegion = exports.useLocaleSelector = exports.useDefaultLocale = exports.useSetLocale = exports.useLocales = exports.useLocale = exports.useTranslations = exports.useGT = void 0;
5
- var client_1 = require("gt-react/client");
6
- Object.defineProperty(exports, "T", { enumerable: true, get: function () { return client_1.T; } });
7
- Object.defineProperty(exports, "useGT", { enumerable: true, get: function () { return client_1.useGT; } });
8
- Object.defineProperty(exports, "useLocale", { enumerable: true, get: function () { return client_1.useLocale; } });
9
- Object.defineProperty(exports, "useDefaultLocale", { enumerable: true, get: function () { return client_1.useDefaultLocale; } });
10
- Object.defineProperty(exports, "LocaleSelector", { enumerable: true, get: function () { return client_1.LocaleSelector; } });
11
- Object.defineProperty(exports, "RegionSelector", { enumerable: true, get: function () { return client_1.RegionSelector; } });
12
- Object.defineProperty(exports, "GTClientProvider", { enumerable: true, get: function () { return client_1.GTProvider; } });
13
- Object.defineProperty(exports, "useLocales", { enumerable: true, get: function () { return client_1.useLocales; } });
14
- Object.defineProperty(exports, "useSetLocale", { enumerable: true, get: function () { return client_1.useSetLocale; } });
15
- Object.defineProperty(exports, "useLocaleSelector", { enumerable: true, get: function () { return client_1.useLocaleSelector; } });
16
- Object.defineProperty(exports, "Var", { enumerable: true, get: function () { return client_1.Var; } });
17
- Object.defineProperty(exports, "Currency", { enumerable: true, get: function () { return client_1.Currency; } });
18
- Object.defineProperty(exports, "DateTime", { enumerable: true, get: function () { return client_1.DateTime; } });
19
- Object.defineProperty(exports, "RelativeTime", { enumerable: true, get: function () { return client_1.RelativeTime; } });
20
- Object.defineProperty(exports, "Num", { enumerable: true, get: function () { return client_1.Num; } });
21
- Object.defineProperty(exports, "Plural", { enumerable: true, get: function () { return client_1.Plural; } });
22
- Object.defineProperty(exports, "Branch", { enumerable: true, get: function () { return client_1.Branch; } });
23
- Object.defineProperty(exports, "useLocaleProperties", { enumerable: true, get: function () { return client_1.useLocaleProperties; } });
24
- Object.defineProperty(exports, "useGTClass", { enumerable: true, get: function () { return client_1.useGTClass; } });
25
- Object.defineProperty(exports, "useTranslations", { enumerable: true, get: function () { return client_1.useTranslations; } });
26
- Object.defineProperty(exports, "useRegion", { enumerable: true, get: function () { return client_1.useRegion; } });
27
- Object.defineProperty(exports, "useRegionSelector", { enumerable: true, get: function () { return client_1.useRegionSelector; } });
28
- Object.defineProperty(exports, "useLocaleDirection", { enumerable: true, get: function () { return client_1.useLocaleDirection; } });
29
- Object.defineProperty(exports, "useVersionId", { enumerable: true, get: function () { return client_1.useVersionId; } });
30
- Object.defineProperty(exports, "msg", { enumerable: true, get: function () { return client_1.msg; } });
31
- Object.defineProperty(exports, "decodeMsg", { enumerable: true, get: function () { return client_1.decodeMsg; } });
32
- Object.defineProperty(exports, "decodeOptions", { enumerable: true, get: function () { return client_1.decodeOptions; } });
33
- Object.defineProperty(exports, "useMessages", { enumerable: true, get: function () { return client_1.useMessages; } });
34
- //# sourceMappingURL=client.js.map
1
+ "use client";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ require("./_virtual/_rolldown/runtime.js");
4
+ let gt_react_client = require("gt-react/client");
5
+ exports.Branch = gt_react_client.Branch;
6
+ exports.Currency = gt_react_client.Currency;
7
+ exports.DateTime = gt_react_client.DateTime;
8
+ exports.GTClientProvider = gt_react_client.GTProvider;
9
+ exports.LocaleSelector = gt_react_client.LocaleSelector;
10
+ exports.Num = gt_react_client.Num;
11
+ exports.Plural = gt_react_client.Plural;
12
+ exports.RegionSelector = gt_react_client.RegionSelector;
13
+ exports.RelativeTime = gt_react_client.RelativeTime;
14
+ exports.T = gt_react_client.T;
15
+ exports.Var = gt_react_client.Var;
16
+ exports.decodeMsg = gt_react_client.decodeMsg;
17
+ exports.decodeOptions = gt_react_client.decodeOptions;
18
+ exports.msg = gt_react_client.msg;
19
+ exports.useDefaultLocale = gt_react_client.useDefaultLocale;
20
+ exports.useGT = gt_react_client.useGT;
21
+ exports.useGTClass = gt_react_client.useGTClass;
22
+ exports.useLocale = gt_react_client.useLocale;
23
+ exports.useLocaleDirection = gt_react_client.useLocaleDirection;
24
+ exports.useLocaleProperties = gt_react_client.useLocaleProperties;
25
+ exports.useLocaleSelector = gt_react_client.useLocaleSelector;
26
+ exports.useLocales = gt_react_client.useLocales;
27
+ exports.useMessages = gt_react_client.useMessages;
28
+ exports.useRegion = gt_react_client.useRegion;
29
+ exports.useRegionSelector = gt_react_client.useRegionSelector;
30
+ exports.useSetLocale = gt_react_client.useSetLocale;
31
+ exports.useTranslations = gt_react_client.useTranslations;
32
+ exports.useVersionId = gt_react_client.useVersionId;
@@ -1,106 +1,52 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.dictionaryManager = exports.DictionaryManager = void 0;
40
- var format_1 = require("@generaltranslation/format");
41
- var resolveDictionaryLoader_1 = require("../resolvers/resolveDictionaryLoader");
42
- var createErrors_1 = require("../errors/createErrors");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../_virtual/_rolldown/runtime.js");
3
+ const require_errors_createErrors = require("../errors/createErrors.js");
4
+ const require_resolvers_resolveDictionaryLoader = require("../resolvers/resolveDictionaryLoader.js");
5
+ let _generaltranslation_format = require("@generaltranslation/format");
6
+ //#region src/config-dir/DictionaryManager.ts
43
7
  /**
44
- * Manages Dictionary
45
- */
46
- var DictionaryManager = /** @class */ (function () {
47
- /**
48
- * Creates an instance of TranslationManager.
49
- * @constructor
50
- */
51
- function DictionaryManager() {
52
- this.dictionaryMap = new Map();
53
- }
54
- /**
55
- * Retrieves dictionary for a given locale from bundle.
56
- * @param {string} locale - The locale code.
57
- * @returns {Promise<Dictionary | undefined>} The dictionary data or undefined if not found.
58
- */
59
- DictionaryManager.prototype.getDictionary = function (locale) {
60
- return __awaiter(this, void 0, void 0, function () {
61
- var reference, result, customLoadDictionary, error_1;
62
- return __generator(this, function (_a) {
63
- switch (_a.label) {
64
- case 0:
65
- reference = process.env._GENERALTRANSLATION_GT_SERVICES_ENABLED === 'true'
66
- ? (0, format_1.standardizeLocale)(locale)
67
- : locale;
68
- result = this.dictionaryMap.get(reference);
69
- if (result)
70
- return [2 /*return*/, result];
71
- customLoadDictionary = (0, resolveDictionaryLoader_1.resolveDictionaryLoader)();
72
- if (!customLoadDictionary) return [3 /*break*/, 4];
73
- _a.label = 1;
74
- case 1:
75
- _a.trys.push([1, 3, , 4]);
76
- return [4 /*yield*/, customLoadDictionary(reference)];
77
- case 2:
78
- result = (_a.sent());
79
- if (!result)
80
- return [2 /*return*/, undefined];
81
- this.dictionaryMap.set(reference, result);
82
- return [3 /*break*/, 4];
83
- case 3:
84
- error_1 = _a.sent();
85
- if (process.env.NODE_ENV === 'development') {
86
- console.warn((0, createErrors_1.customLoadDictionaryWarning)(reference), error_1);
87
- }
88
- return [2 /*return*/, undefined];
89
- case 4: return [2 /*return*/, result];
90
- }
91
- });
92
- });
93
- };
94
- /**
95
- * @description Sets the dictionary for a given locale
96
- * @param {string} locale - The locale code.
97
- * @param {Dictionary} dictionary - The dictionary data.
98
- */
99
- DictionaryManager.prototype.setDictionary = function (locale, dictionary) {
100
- this.dictionaryMap.set(locale, dictionary);
101
- };
102
- return DictionaryManager;
103
- }());
8
+ * Manages Dictionary
9
+ */
10
+ var DictionaryManager = class {
11
+ /**
12
+ * Creates an instance of TranslationManager.
13
+ * @constructor
14
+ */
15
+ constructor() {
16
+ this.dictionaryMap = /* @__PURE__ */ new Map();
17
+ }
18
+ /**
19
+ * Retrieves dictionary for a given locale from bundle.
20
+ * @param {string} locale - The locale code.
21
+ * @returns {Promise<Dictionary | undefined>} The dictionary data or undefined if not found.
22
+ */
23
+ async getDictionary(locale) {
24
+ const reference = process.env._GENERALTRANSLATION_GT_SERVICES_ENABLED === "true" ? (0, _generaltranslation_format.standardizeLocale)(locale) : locale;
25
+ let result = this.dictionaryMap.get(reference);
26
+ if (result) return result;
27
+ const customLoadDictionary = require_resolvers_resolveDictionaryLoader.resolveDictionaryLoader();
28
+ if (customLoadDictionary) try {
29
+ result = await customLoadDictionary(reference);
30
+ if (!result) return void 0;
31
+ this.dictionaryMap.set(reference, result);
32
+ } catch (error) {
33
+ if (process.env.NODE_ENV === "development") console.warn(require_errors_createErrors.customLoadDictionaryWarning(reference), error);
34
+ return;
35
+ }
36
+ return result;
37
+ }
38
+ /**
39
+ * @description Sets the dictionary for a given locale
40
+ * @param {string} locale - The locale code.
41
+ * @param {Dictionary} dictionary - The dictionary data.
42
+ */
43
+ setDictionary(locale, dictionary) {
44
+ this.dictionaryMap.set(locale, dictionary);
45
+ }
46
+ };
47
+ const dictionaryManager = new DictionaryManager();
48
+ //#endregion
104
49
  exports.DictionaryManager = DictionaryManager;
105
- exports.dictionaryManager = new DictionaryManager();
50
+ exports.dictionaryManager = dictionaryManager;
51
+
106
52
  //# sourceMappingURL=DictionaryManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DictionaryManager.js","sourceRoot":"","sources":["../../src/config-dir/DictionaryManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA+D;AAE/D,gFAA+E;AAC/E,uDAAqE;AAErE;;GAEG;AACH;IAGE;;;OAGG;IACH;QACE,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACG,yCAAa,GAAnB,UAAoB,MAAc;;;;;;wBAC1B,SAAS,GACb,OAAO,CAAC,GAAG,CAAC,uCAAuC,KAAK,MAAM;4BAC5D,CAAC,CAAC,IAAA,0BAAiB,EAAC,MAAM,CAAC;4BAC3B,CAAC,CAAC,MAAM,CAAC;wBAGT,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;wBAC/C,IAAI,MAAM;4BAAE,sBAAO,MAAM,EAAC;wBAGpB,oBAAoB,GAAG,IAAA,iDAAuB,GAAE,CAAC;6BACnD,oBAAoB,EAApB,wBAAoB;;;;wBAEV,qBAAM,oBAAoB,CAAC,SAAS,CAAC,EAAA;;wBAA/C,MAAM,GAAG,CAAC,SAAqC,CAElC,CAAC;wBACd,IAAI,CAAC,MAAM;4BAAE,sBAAO,SAAS,EAAC;wBAC9B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;;;;wBAE1C,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;4BAC3C,OAAO,CAAC,IAAI,CAAC,IAAA,0CAA2B,EAAC,SAAS,CAAC,EAAE,OAAK,CAAC,CAAC;wBAC9D,CAAC;wBACD,sBAAO,SAAS,EAAC;4BAIrB,sBAAO,MAAM,EAAC;;;;KACf;IAED;;;;OAIG;IACH,yCAAa,GAAb,UAAc,MAAc,EAAE,UAAsB;QAClD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC7C,CAAC;IACH,wBAAC;AAAD,CAAC,AAtDD,IAsDC;AAtDY,8CAAiB;AAwDjB,QAAA,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"DictionaryManager.js","names":["resolveDictionaryLoader","customLoadDictionaryWarning"],"sources":["../../src/config-dir/DictionaryManager.ts"],"sourcesContent":["import { standardizeLocale } from '@generaltranslation/format';\nimport { Dictionary } from 'gt-react/internal';\nimport { resolveDictionaryLoader } from '../resolvers/resolveDictionaryLoader';\nimport { customLoadDictionaryWarning } from '../errors/createErrors';\n\n/**\n * Manages Dictionary\n */\nexport class DictionaryManager {\n private dictionaryMap: Map<string, Dictionary>;\n\n /**\n * Creates an instance of TranslationManager.\n * @constructor\n */\n constructor() {\n this.dictionaryMap = new Map();\n }\n\n /**\n * Retrieves dictionary for a given locale from bundle.\n * @param {string} locale - The locale code.\n * @returns {Promise<Dictionary | undefined>} The dictionary data or undefined if not found.\n */\n async getDictionary(locale: string): Promise<Dictionary | undefined> {\n const reference =\n process.env._GENERALTRANSLATION_GT_SERVICES_ENABLED === 'true'\n ? standardizeLocale(locale)\n : locale;\n\n // Check internal cache\n let result = this.dictionaryMap.get(reference);\n if (result) return result;\n\n // Load dictionary\n const customLoadDictionary = resolveDictionaryLoader();\n if (customLoadDictionary) {\n try {\n result = (await customLoadDictionary(reference)) as\n | Dictionary\n | undefined;\n if (!result) return undefined;\n this.dictionaryMap.set(reference, result);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(customLoadDictionaryWarning(reference), error);\n }\n return undefined;\n }\n }\n\n return result;\n }\n\n /**\n * @description Sets the dictionary for a given locale\n * @param {string} locale - The locale code.\n * @param {Dictionary} dictionary - The dictionary data.\n */\n setDictionary(locale: string, dictionary: Dictionary) {\n this.dictionaryMap.set(locale, dictionary);\n }\n}\n\nexport const dictionaryManager = new DictionaryManager();\n"],"mappings":";;;;;;;;;AAQA,IAAa,oBAAb,MAA+B;;;;;CAO7B,cAAc;AACZ,OAAK,gCAAgB,IAAI,KAAK;;;;;;;CAQhC,MAAM,cAAc,QAAiD;EACnE,MAAM,YACJ,QAAQ,IAAI,4CAA4C,UAAA,GAAA,2BAAA,mBAClC,OAAO,GACzB;EAGN,IAAI,SAAS,KAAK,cAAc,IAAI,UAAU;AAC9C,MAAI,OAAQ,QAAO;EAGnB,MAAM,uBAAuBA,0CAAAA,yBAAyB;AACtD,MAAI,qBACF,KAAI;AACF,YAAU,MAAM,qBAAqB,UAAU;AAG/C,OAAI,CAAC,OAAQ,QAAO,KAAA;AACpB,QAAK,cAAc,IAAI,WAAW,OAAO;WAClC,OAAO;AACd,OAAI,QAAQ,IAAI,aAAa,cAC3B,SAAQ,KAAKC,4BAAAA,4BAA4B,UAAU,EAAE,MAAM;AAE7D;;AAIJ,SAAO;;;;;;;CAQT,cAAc,QAAgB,YAAwB;AACpD,OAAK,cAAc,IAAI,QAAQ,WAAW;;;AAI9C,MAAa,oBAAoB,IAAI,mBAAmB"}