gt-react 4.1.4 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/branches/Branch.d.ts +31 -0
  2. package/dist/branches/Branch.d.ts.map +1 -0
  3. package/dist/branches/Branch.js +44 -0
  4. package/dist/branches/Branch.js.map +1 -0
  5. package/dist/branches/plurals/Plural.d.ts +32 -0
  6. package/dist/branches/plurals/Plural.d.ts.map +1 -0
  7. package/dist/branches/plurals/Plural.js +56 -0
  8. package/dist/branches/plurals/Plural.js.map +1 -0
  9. package/dist/branches/plurals/getPluralBranch.d.ts +17 -0
  10. package/dist/branches/plurals/getPluralBranch.d.ts.map +1 -0
  11. package/dist/branches/plurals/getPluralBranch.js +79 -0
  12. package/dist/branches/plurals/getPluralBranch.js.map +1 -0
  13. package/dist/index.d.ts +3 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +5 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/inline/T.d.ts +2 -4
  18. package/dist/inline/T.d.ts.map +1 -1
  19. package/dist/inline/T.js +12 -46
  20. package/dist/inline/T.js.map +1 -1
  21. package/dist/internal/addGTIdentifier.d.ts +1 -1
  22. package/dist/internal/addGTIdentifier.d.ts.map +1 -1
  23. package/dist/internal/addGTIdentifier.js +40 -25
  24. package/dist/internal/addGTIdentifier.js.map +1 -1
  25. package/dist/internal.d.ts +1 -1
  26. package/dist/internal.d.ts.map +1 -1
  27. package/dist/internal.js +1 -1
  28. package/dist/internal.js.map +1 -1
  29. package/dist/plurals/Plural.d.ts +10 -0
  30. package/dist/plurals/Plural.d.ts.map +1 -0
  31. package/dist/plurals/Plural.js +32 -0
  32. package/dist/plurals/Plural.js.map +1 -0
  33. package/dist/provider/GTProvider.d.ts.map +1 -1
  34. package/dist/provider/GTProvider.js +9 -25
  35. package/dist/provider/GTProvider.js.map +1 -1
  36. package/dist/provider/rendering/renderDefaultChildren.d.ts.map +1 -1
  37. package/dist/provider/rendering/renderDefaultChildren.js +28 -0
  38. package/dist/provider/rendering/renderDefaultChildren.js.map +1 -1
  39. package/dist/provider/rendering/renderTranslatedChildren.d.ts +2 -1
  40. package/dist/provider/rendering/renderTranslatedChildren.d.ts.map +1 -1
  41. package/dist/provider/rendering/renderTranslatedChildren.js +47 -10
  42. package/dist/provider/rendering/renderTranslatedChildren.js.map +1 -1
  43. package/dist/variables/Currency.d.ts +3 -3
  44. package/dist/variables/Currency.d.ts.map +1 -1
  45. package/dist/variables/Currency.js +6 -6
  46. package/dist/variables/Currency.js.map +1 -1
  47. package/dist/variables/DateTime.d.ts +3 -3
  48. package/dist/variables/DateTime.d.ts.map +1 -1
  49. package/dist/variables/DateTime.js +3 -3
  50. package/dist/variables/DateTime.js.map +1 -1
  51. package/dist/variables/Num.d.ts +3 -3
  52. package/dist/variables/Num.d.ts.map +1 -1
  53. package/dist/variables/Num.js +6 -6
  54. package/dist/variables/Num.js.map +1 -1
  55. package/dist/variables/Var.d.ts +7 -7
  56. package/dist/variables/Var.d.ts.map +1 -1
  57. package/dist/variables/Var.js +7 -7
  58. package/dist/variables/Var.js.map +1 -1
  59. package/dist/variables/_getVariableProps.js +2 -2
  60. package/dist/variables/_getVariableProps.js.map +1 -1
  61. package/package.json +1 -1
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
3
+ * It allows for flexible content switching based on the `branch` prop and an object of possible branches (`...branches`).
4
+ * If the specified `branch` is present in the `branches` object, it renders the content of that branch.
5
+ * If the `branch` is not found, it renders the provided `children` as fallback content.
6
+ *
7
+ * @example
8
+ * ```jsx
9
+ * <Branch branch="summary" summary={<p>This is a summary</p>} details={<p>Details here</p>}>
10
+ * <p>Fallback content</p>
11
+ * </Branch>
12
+ * ```
13
+ * If the `branch` prop is set to `"summary"`, it will render `<p>This is a summary</p>`. If the `branch` is not set or does not match any keys in the branches object, it renders the fallback content `<p>Fallback content</p>`.
14
+ *
15
+ * @param {any} [children] - Fallback content to render if no matching branch is found.
16
+ * @param {string} [name="branch"] - Optional name for the component, used for metadata or tracking purposes.
17
+ * @param {string} [branch] - The name of the branch to render. The component looks for this key in the `...branches` object.
18
+ * @param {object} [branches] - An object containing possible branches as keys and their corresponding content as values.
19
+ * @returns {JSX.Element} The rendered branch or fallback content.
20
+ */
21
+ declare function Branch({ children, name, branch, ...props }: {
22
+ children?: any;
23
+ name?: string;
24
+ branch?: string;
25
+ [key: string]: any;
26
+ }): import("react/jsx-runtime").JSX.Element;
27
+ declare namespace Branch {
28
+ var gtTransformation: string;
29
+ }
30
+ export default Branch;
31
+ //# sourceMappingURL=Branch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Branch.d.ts","sourceRoot":"","sources":["../../src/branches/Branch.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,MAAM,CAAC,EACZ,QAAQ,EAAE,IAAe,EAAE,MAAM,EAAE,GAAG,KAAK,EAC9C,EAAE;IACC,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,2CAQA;kBAfQ,MAAM;;;AAkBf,eAAe,MAAM,CAAC"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ 'use client';
3
+ var __rest = (this && this.__rest) || function (s, e) {
4
+ var t = {};
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
6
+ t[p] = s[p];
7
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
8
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
9
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
10
+ t[p[i]] = s[p[i]];
11
+ }
12
+ return t;
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ /**
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 branch="summary" summary={<p>This is a summary</p>} details={<p>Details here</p>}>
25
+ * <p>Fallback content</p>
26
+ * </Branch>
27
+ * ```
28
+ * If the `branch` prop is set to `"summary"`, it will render `<p>This is a summary</p>`. If the `branch` is not set or does not match any keys in the branches object, it renders the fallback content `<p>Fallback content</p>`.
29
+ *
30
+ * @param {any} [children] - Fallback content to render if no matching branch is found.
31
+ * @param {string} [name="branch"] - Optional name for the component, used for metadata or tracking purposes.
32
+ * @param {string} [branch] - The name of the branch to render. The component looks for this key in the `...branches` object.
33
+ * @param {object} [branches] - An object containing possible branches as keys and their corresponding content as values.
34
+ * @returns {JSX.Element} The rendered branch or fallback content.
35
+ */
36
+ function Branch(_a) {
37
+ var children = _a.children, _b = _a.name, name = _b === void 0 ? "branch" : _b, branch = _a.branch, props = __rest(_a, ["children", "name", "branch"]);
38
+ var generaltranslation = props["data-generaltranslation"], branches = __rest(props, ['data-generaltranslation']);
39
+ var renderedBranch = (branch && typeof branches[branch] !== 'undefined') ? branches[branch] : children;
40
+ return ((0, jsx_runtime_1.jsx)("span", { "data-generaltranslation": generaltranslation, "data-gt-name": name || "branch", "data-gt-branch-name": branch, "data-gt-branches": branches, children: renderedBranch }));
41
+ }
42
+ Branch.gtTransformation = "branch";
43
+ exports.default = Branch;
44
+ //# sourceMappingURL=Branch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Branch.js","sourceRoot":"","sources":["../../src/branches/Branch.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;;;;;;;;;;AAEZ;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,MAAM,CAAC,EAOf;IANG,IAAA,QAAQ,cAAA,EAAE,YAAe,EAAf,IAAI,mBAAG,QAAQ,KAAA,EAAE,MAAM,YAAA,EAAK,KAAK,cAD/B,8BAEf,CAD8C;IAOnC,IAA2B,kBAAkB,GAAkB,KAAK,2BAAvB,EAAK,QAAQ,UAAK,KAAK,EAAtE,2BAA8D,CAAF,CAAW;IAC7E,IAAM,cAAc,GAAG,CAAC,MAAM,IAAI,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IACzG,OAAO,CACH,4DAA+B,kBAAkB,kBAAgB,IAAI,IAAI,QAAQ,yBAAuB,MAAM,sBAAoB,QAAQ,YACrI,cAAc,GACZ,CACV,CAAC;AACN,CAAC;AAED,MAAM,CAAC,gBAAgB,GAAG,QAAQ,CAAC;AACnC,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The `<Plural>` component dynamically renders content based on the plural form of the given number (`n`).
3
+ * It determines which content to display by matching the value of `n` to the appropriate pluralization branch,
4
+ * based on the current locale or a default locale. If no matching plural branch is found, the component renders
5
+ * the fallback `children` content.
6
+ *
7
+ * @example
8
+ * ```jsx
9
+ * <Plural n={1} one="There is 1 item">
10
+ * There are {n} items
11
+ * </Plural>
12
+ * ```
13
+ * In this example, if `n` is 1, it renders `"There is 1 item"`. If `n` is a different number, it renders
14
+ * `"There are {n} items"`.
15
+ *
16
+ * @param {any} [children] - Fallback content to render if no matching plural branch is found.
17
+ * @param {number} [n] - The number used to determine the plural form. This is required for pluralization to work.
18
+ * @param {object} [branches] - An object containing possible plural branches, typically including `one` for singular
19
+ * and `other` for plural forms, but it may vary depending on the locale.
20
+ * @returns {JSX.Element} The rendered content corresponding to the plural form of `n`, or the fallback content.
21
+ * @throws {Error} If `n` is not provided or not a valid number.
22
+ */
23
+ declare function Plural({ children, n, ...props }: {
24
+ children?: any;
25
+ n?: number;
26
+ [key: string]: any;
27
+ }): import("react/jsx-runtime").JSX.Element;
28
+ declare namespace Plural {
29
+ var gtTransformation: string;
30
+ }
31
+ export default Plural;
32
+ //# sourceMappingURL=Plural.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plural.d.ts","sourceRoot":"","sources":["../../../src/branches/plurals/Plural.tsx"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,iBAAS,MAAM,CAAC,EACZ,QAAQ,EAAE,CAAC,EAAE,GAAG,KAAK,EACxB,EAAE;IACC,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,2CAYA;kBAlBQ,MAAM;;;AAsBf,eAAe,MAAM,CAAC"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ 'use client';
3
+ var __rest = (this && this.__rest) || function (s, e) {
4
+ var t = {};
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
6
+ t[p] = s[p];
7
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
8
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
9
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
10
+ t[p[i]] = s[p[i]];
11
+ }
12
+ return t;
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ var jsx_runtime_1 = require("react/jsx-runtime");
19
+ var internal_1 = require("../../internal");
20
+ var useLocale_1 = __importDefault(require("../../hooks/useLocale"));
21
+ var useDefaultLocale_1 = __importDefault(require("../../hooks/useDefaultLocale"));
22
+ /**
23
+ * The `<Plural>` component dynamically renders content based on the plural form of the given number (`n`).
24
+ * It determines which content to display by matching the value of `n` to the appropriate pluralization branch,
25
+ * based on the current locale or a default locale. If no matching plural branch is found, the component renders
26
+ * the fallback `children` content.
27
+ *
28
+ * @example
29
+ * ```jsx
30
+ * <Plural n={1} one="There is 1 item">
31
+ * There are {n} items
32
+ * </Plural>
33
+ * ```
34
+ * In this example, if `n` is 1, it renders `"There is 1 item"`. If `n` is a different number, it renders
35
+ * `"There are {n} items"`.
36
+ *
37
+ * @param {any} [children] - Fallback content to render if no matching plural branch is found.
38
+ * @param {number} [n] - The number used to determine the plural form. This is required for pluralization to work.
39
+ * @param {object} [branches] - An object containing possible plural branches, typically including `one` for singular
40
+ * and `other` for plural forms, but it may vary depending on the locale.
41
+ * @returns {JSX.Element} The rendered content corresponding to the plural form of `n`, or the fallback content.
42
+ * @throws {Error} If `n` is not provided or not a valid number.
43
+ */
44
+ function Plural(_a) {
45
+ var children = _a.children, n = _a.n, props = __rest(_a, ["children", "n"]);
46
+ var generaltranslation = props["data-generaltranslation"], branches = __rest(props, ['data-generaltranslation']);
47
+ var locale = (0, useLocale_1.default)();
48
+ var defaultLocale = (0, useDefaultLocale_1.default)();
49
+ if (typeof n !== 'number')
50
+ throw new Error("Plural with children \"".concat(children, "\" requires \"n\" option."));
51
+ var branch = (0, internal_1.getPluralBranch)(n, [locale, defaultLocale], branches) || children;
52
+ return ((0, jsx_runtime_1.jsx)("span", { "data-generaltranslation": generaltranslation, "data-gt-n": n, "data-gt-branches": branches, children: branch }));
53
+ }
54
+ Plural.gtTransformation = "plural";
55
+ exports.default = Plural;
56
+ //# sourceMappingURL=Plural.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plural.js","sourceRoot":"","sources":["../../../src/branches/plurals/Plural.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;AAEZ,2CAAiD;AACjD,oEAA8C;AAC9C,kFAA4D;AAE5D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAS,MAAM,CAAC,EAMf;IALG,IAAA,QAAQ,cAAA,EAAE,CAAC,OAAA,EAAK,KAAK,cADT,iBAEf,CADwB;IAMb,IAA2B,kBAAkB,GAAkB,KAAK,2BAAvB,EAAK,QAAQ,UAAK,KAAK,EAAtE,2BAA8D,CAAF,CAAW;IAC7E,IAAM,MAAM,GAAG,IAAA,mBAAS,GAAE,CAAC;IAC3B,IAAM,aAAa,GAAG,IAAA,0BAAgB,GAAE,CAAC;IACzC,IAAI,OAAO,CAAC,KAAK,QAAQ;QACrB,MAAM,IAAI,KAAK,CAAC,iCAAyB,QAAQ,8BAAwB,CAAC,CAAC;IAC/E,IAAM,MAAM,GAAG,IAAA,0BAAe,EAAC,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,QAAQ,CAAC,IAAI,QAAQ,CAAC;IACjF,OAAO,CACH,4DAA+B,kBAAkB,eAAa,CAAC,sBAAoB,QAAQ,YACtF,MAAM,GACJ,CACV,CAAC;AACN,CAAC;AAED,MAAM,CAAC,gBAAgB,GAAG,QAAQ,CAAC;AAEnC,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Helper function to get the branch name from a number based on provided options.
3
+ *
4
+ * @param {number} n - The number to determine the branch name for.
5
+ * @param {Record<string, any>} options - The options containing possible branch names.
6
+ * @returns {string} The determined branch name.
7
+ */
8
+ export declare function getBranchNameFromNumber(n: number, locales: string[], options: Record<string, any>): string;
9
+ /**
10
+ * Main function to get the appropriate branch based on the provided number and branches.
11
+ *
12
+ * @param {number} n - The number to determine the branch for.
13
+ * @param {any} branches - The object containing possible branches.
14
+ * @returns {any} The determined branch.
15
+ */
16
+ export default function getPluralBranch(n: number, locales: string[], branches: Record<string, any>): any;
17
+ //# sourceMappingURL=getPluralBranch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPluralBranch.d.ts","sourceRoot":"","sources":["../../../src/branches/plurals/getPluralBranch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAkC1G;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,OAMlG"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBranchNameFromNumber = getBranchNameFromNumber;
4
+ exports.default = getPluralBranch;
5
+ /**
6
+ * Helper function to get the branch name from a number based on provided options.
7
+ *
8
+ * @param {number} n - The number to determine the branch name for.
9
+ * @param {Record<string, any>} options - The options containing possible branch names.
10
+ * @returns {string} The determined branch name.
11
+ */
12
+ function getBranchNameFromNumber(n, locales, options) {
13
+ var pluralRules = new Intl.PluralRules(locales);
14
+ var provisionalBranchName = pluralRules.select(n);
15
+ // aliases
16
+ var absN = Math.abs(n);
17
+ // 0
18
+ if (absN === 0 && options["zero"])
19
+ return "zero"; // override
20
+ // 1
21
+ if (absN === 1) {
22
+ if (options["singular"])
23
+ return "singular"; // override
24
+ if (options["one"])
25
+ return "one"; // override
26
+ }
27
+ if (provisionalBranchName === "one" && options["singular"])
28
+ return "singular";
29
+ // 2
30
+ if (absN === 2) {
31
+ if (options["dual"])
32
+ return "dual"; // override
33
+ if (options["two"])
34
+ return "two"; // override
35
+ }
36
+ if (provisionalBranchName === "two" && options["dual"])
37
+ return "dual";
38
+ // fallbacks
39
+ if (options[provisionalBranchName])
40
+ return provisionalBranchName;
41
+ // two
42
+ if (provisionalBranchName === "two" && options["dual"])
43
+ return "dual";
44
+ if (provisionalBranchName === "two" && options["plural"])
45
+ return "plural";
46
+ if (provisionalBranchName === "two" && options["other"])
47
+ return "other";
48
+ // few
49
+ if (provisionalBranchName === "few" && options["plural"])
50
+ return "plural";
51
+ if (provisionalBranchName === "few" && options["other"])
52
+ return "other";
53
+ // many
54
+ if (provisionalBranchName === "many" && options["plural"])
55
+ return "plural";
56
+ if (provisionalBranchName === "many" && options["other"])
57
+ return "other";
58
+ // other
59
+ if (provisionalBranchName === "other" && options["plural"])
60
+ return "plural";
61
+ return "";
62
+ }
63
+ /**
64
+ * Main function to get the appropriate branch based on the provided number and branches.
65
+ *
66
+ * @param {number} n - The number to determine the branch for.
67
+ * @param {any} branches - The object containing possible branches.
68
+ * @returns {any} The determined branch.
69
+ */
70
+ function getPluralBranch(n, locales, branches) {
71
+ var branchName = '';
72
+ var branch = null;
73
+ if (typeof n === 'number' && !branch && branches)
74
+ branchName = getBranchNameFromNumber(n, locales, branches);
75
+ if (branchName && !branch)
76
+ branch = branches[branchName];
77
+ return branch;
78
+ }
79
+ //# sourceMappingURL=getPluralBranch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPluralBranch.js","sourceRoot":"","sources":["../../../src/branches/plurals/getPluralBranch.ts"],"names":[],"mappings":";;AAOA,0DAkCC;AASD,kCAMC;AAxDD;;;;;;GAMG;AACH,SAAgB,uBAAuB,CAAC,CAAS,EAAE,OAAiB,EAAE,OAA4B;IAC9F,IAAM,WAAW,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAClD,IAAM,qBAAqB,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACpD,UAAU;IACV,IAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI;IACJ,IAAI,IAAI,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC,CAAC,WAAW;IAC7D,IAAI;IACJ,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QACb,IAAI,OAAO,CAAC,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AO,CAAC;IACzE,QAAQ;IACR,IAAI,qBAAqB,KAAK,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC5E,OAAO,EAAE,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,SAAwB,eAAe,CAAC,CAAS,EAAE,OAAiB,EAAE,QAA6B;IAC/F,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,IAAI,QAAQ;QAAE,UAAU,GAAG,uBAAuB,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7G,IAAI,UAAU,IAAI,CAAC,MAAM;QAAE,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC;AAClB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -7,5 +7,7 @@ import Var from "./variables/Var";
7
7
  import Num from "./variables/Num";
8
8
  import Currency from "./variables/Currency";
9
9
  import DateTime from "./variables/DateTime";
10
- export { Var, Num, Currency, DateTime, T, GTProvider, useGT, useDefaultLocale, useLocale };
10
+ import Plural from "./branches/plurals/Plural";
11
+ import Branch from "./branches/Branch";
12
+ export { Var, Num, Currency, DateTime, T, GTProvider, Plural, Branch, useGT, useDefaultLocale, useLocale };
11
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,YAAY,CAAC;AAC3B,OAAO,KAAK,MAAM,eAAe,CAAC;AAClC,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AACxD,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAC5C,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EACH,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAC5B,CAAC,EAAE,UAAU,EACb,KAAK,EAAE,gBAAgB,EAAE,SAAS,EACrC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,YAAY,CAAC;AAC3B,OAAO,KAAK,MAAM,eAAe,CAAC;AAClC,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AACxD,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAC5C,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAC5C,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACH,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAC5B,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAC7B,KAAK,EAAE,gBAAgB,EAAE,SAAS,EACrC,CAAA"}
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useLocale = exports.useDefaultLocale = exports.useGT = exports.GTProvider = exports.T = exports.DateTime = exports.Currency = exports.Num = exports.Var = void 0;
6
+ exports.useLocale = exports.useDefaultLocale = exports.useGT = exports.Branch = exports.Plural = exports.GTProvider = exports.T = exports.DateTime = exports.Currency = exports.Num = exports.Var = void 0;
7
7
  var T_1 = __importDefault(require("./inline/T"));
8
8
  exports.T = T_1.default;
9
9
  var useGT_1 = __importDefault(require("./hooks/useGT"));
@@ -22,4 +22,8 @@ var Currency_1 = __importDefault(require("./variables/Currency"));
22
22
  exports.Currency = Currency_1.default;
23
23
  var DateTime_1 = __importDefault(require("./variables/DateTime"));
24
24
  exports.DateTime = DateTime_1.default;
25
+ var Plural_1 = __importDefault(require("./branches/plurals/Plural"));
26
+ exports.Plural = Plural_1.default;
27
+ var Branch_1 = __importDefault(require("./branches/Branch"));
28
+ exports.Branch = Branch_1.default;
25
29
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,iDAA2B;AAYvB,YAZG,WAAC,CAYH;AAXL,wDAAkC;AAY9B,gBAZG,eAAK,CAYH;AAXT,8EAAwD;AAW7C,2BAXJ,0BAAgB,CAWI;AAV3B,gEAA0C;AAUb,oBAVtB,mBAAS,CAUsB;AATtC,qEAA+C;AAQxC,qBARA,oBAAU,CAQA;AAPjB,wDAAkC;AAM9B,cANG,aAAG,CAMH;AALP,wDAAkC;AAKzB,cALF,aAAG,CAKE;AAJZ,kEAA4C;AAI9B,mBAJP,kBAAQ,CAIO;AAHtB,kEAA4C;AAGpB,mBAHjB,kBAAQ,CAGiB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,iDAA2B;AAcvB,YAdG,WAAC,CAcH;AAbL,wDAAkC;AAc9B,gBAdG,eAAK,CAcH;AAbT,8EAAwD;AAa7C,2BAbJ,0BAAgB,CAaI;AAZ3B,gEAA0C;AAYb,oBAZtB,mBAAS,CAYsB;AAXtC,qEAA+C;AAUxC,qBAVA,oBAAU,CAUA;AATjB,wDAAkC;AAQ9B,cARG,aAAG,CAQH;AAPP,wDAAkC;AAOzB,cAPF,aAAG,CAOE;AANZ,kEAA4C;AAM9B,mBANP,kBAAQ,CAMO;AALtB,kEAA4C;AAKpB,mBALjB,kBAAQ,CAKiB;AAJhC,qEAA+C;AAK5B,iBALZ,gBAAM,CAKY;AAJzB,6DAAuC;AAIZ,iBAJpB,gBAAM,CAIoB"}
@@ -4,7 +4,6 @@
4
4
  *
5
5
  * @param {string} [id] - Required identifier for the translation string.
6
6
  * @param {React.ReactNode} children - The content to be translated or displayed.
7
- * @param {number} [n] - Optional number to determine plural forms.
8
7
  * @param {Object} [variables] - Variables for interpolation in the translation string.
9
8
  * @param {Object} [variablesOptions] - Optional formatting options for numeric or date variables.
10
9
  * @param {any} [context] - Additional context for translation key generation.
@@ -30,15 +29,14 @@
30
29
  * ```
31
30
  *
32
31
  */
33
- export default function T({ children, id, variables, n, variablesOptions, context, ...props }: {
32
+ export default function T({ children, id, variables, variablesOptions, context }: {
34
33
  children?: any;
35
34
  id: string;
36
- n?: number;
37
35
  variables?: Record<string, any>;
38
36
  variablesOptions?: {
39
37
  [key: string]: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions;
40
38
  };
41
39
  context?: string;
42
40
  [key: string]: any;
43
- }): import("react").ReactNode;
41
+ }): JSX.Element;
44
42
  //# sourceMappingURL=T.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"T.d.ts","sourceRoot":"","sources":["../../src/inline/T.tsx"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC,EACtB,QAAQ,EAAE,EAAE,EACZ,SAAS,EAAE,CAAC,EACZ,gBAAgB,EAAE,OAAO,EACzB,GAAG,KAAK,EACX,EAAE;IACC,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,EAAE,EAAE,MAAM,CAAA;IACV,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,gBAAgB,CAAC,EAAE;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,qBAAqB,CAAA;KACtE,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACrB,6BA+EA"}
1
+ {"version":3,"file":"T.d.ts","sourceRoot":"","sources":["../../src/inline/T.tsx"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC,EACtB,QAAQ,EAAE,EAAE,EACZ,SAAS,EACT,gBAAgB,EAAE,OAAO,EAC5B,EAAE;IACC,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,gBAAgB,CAAC,EAAE;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,qBAAqB,CAAA;KACtE,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACrB,GAAG,GAAG,CAAC,OAAO,CA4Cd"}
package/dist/inline/T.js CHANGED
@@ -10,39 +10,28 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
- var __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
25
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
15
  };
27
16
  Object.defineProperty(exports, "__esModule", { value: true });
28
17
  exports.default = T;
18
+ var jsx_runtime_1 = require("react/jsx-runtime");
19
+ var react_1 = __importDefault(require("react"));
29
20
  var generaltranslation_1 = require("generaltranslation");
30
21
  var useDefaultLocale_1 = __importDefault(require("../hooks/useDefaultLocale"));
31
22
  var useLocale_1 = __importDefault(require("../hooks/useLocale"));
32
23
  var renderDefaultChildren_1 = __importDefault(require("../provider/rendering/renderDefaultChildren"));
33
24
  var internal_1 = require("../internal");
34
- var primitives_1 = require("../primitives/primitives");
35
25
  var GTContext_1 = __importDefault(require("../provider/GTContext"));
36
26
  var renderTranslatedChildren_1 = __importDefault(require("../provider/rendering/renderTranslatedChildren"));
37
27
  var useGT_1 = __importDefault(require("../hooks/useGT"));
38
- var react_1 = require("react");
28
+ var react_2 = require("react");
39
29
  /**
40
30
  * Translation component that handles rendering translated content, including plural forms.
41
31
  * Used with the required `id` parameter instead of `const t = useGT()`.
42
32
  *
43
33
  * @param {string} [id] - Required identifier for the translation string.
44
34
  * @param {React.ReactNode} children - The content to be translated or displayed.
45
- * @param {number} [n] - Optional number to determine plural forms.
46
35
  * @param {Object} [variables] - Variables for interpolation in the translation string.
47
36
  * @param {Object} [variablesOptions] - Optional formatting options for numeric or date variables.
48
37
  * @param {any} [context] - Additional context for translation key generation.
@@ -69,37 +58,18 @@ var react_1 = require("react");
69
58
  *
70
59
  */
71
60
  function T(_a) {
72
- var _b, _c, _d;
73
- var children = _a.children, id = _a.id, variables = _a.variables, n = _a.n, variablesOptions = _a.variablesOptions, context = _a.context, props = __rest(_a, ["children", "id", "variables", "n", "variablesOptions", "context"]);
61
+ var children = _a.children, id = _a.id, variables = _a.variables, variablesOptions = _a.variablesOptions, context = _a.context;
74
62
  if (!id) {
75
63
  throw new Error("Client-side <T> with no provided 'id' prop. Children: ".concat(children));
76
64
  }
77
- var translations = (0, GTContext_1.default)("<T id=\"".concat(id, "\"> with children ").concat(children, " used on the client-side outside of <GTProvider>")).translations;
65
+ var translations = (0, GTContext_1.default)("<T id=\"".concat(id, "\"> used on the client-side outside of <GTProvider>")).translations;
78
66
  var t = (0, useGT_1.default)();
79
67
  if (!children) {
80
- return t(id, __assign({ variables: variables }, (variablesOptions && { variablesOptions: variablesOptions })));
68
+ return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: t(id, __assign({ variables: variables }, (variablesOptions && { variablesOptions: variablesOptions }))) }, id);
81
69
  }
82
- variables = __assign(__assign({}, variables), (typeof n === 'number' && { n: n }));
83
70
  var locale = (0, useLocale_1.default)();
84
71
  var defaultLocale = (0, useDefaultLocale_1.default)();
85
- var taggedChildren = (0, react_1.useMemo)(function () { return (0, internal_1.addGTIdentifier)(children, props); }, [children, props]);
86
- var source;
87
- // Get a plural if appropriate (check type, if type, get branch, entry =)
88
- var isPlural = props && primitives_1.pluralBranchNames.some(function (branchName) { return branchName in props; });
89
- if (isPlural) {
90
- if (typeof n === 'number')
91
- (variables || (variables = {})).n = n;
92
- if (typeof (variables === null || variables === void 0 ? void 0 : variables.n) !== 'number') {
93
- throw new Error(id ?
94
- "ID \"".concat(id, "\": Plural requires \"n\" option.") :
95
- "<T> with props ".concat(JSON.stringify(props), ": Plural requires \"n\" option."));
96
- }
97
- source = (0, internal_1.getPluralBranch)(variables.n, [locale, defaultLocale], // not redundant, as locale could be a different dialect of the same language
98
- taggedChildren.props['data-generaltranslation'].branches) || taggedChildren.props.children;
99
- }
100
- else {
101
- source = taggedChildren;
102
- }
72
+ var taggedChildren = (0, react_2.useMemo)(function () { return (0, internal_1.addGTIdentifier)(children); }, [children]);
103
73
  var translationRequired = (function () {
104
74
  if (!locale)
105
75
  return false;
@@ -109,7 +79,7 @@ function T(_a) {
109
79
  })();
110
80
  if (!translationRequired) {
111
81
  return (0, renderDefaultChildren_1.default)({
112
- entry: source,
82
+ entry: taggedChildren,
113
83
  variables: variables,
114
84
  variablesOptions: variablesOptions
115
85
  });
@@ -117,17 +87,13 @@ function T(_a) {
117
87
  // Do translation
118
88
  var translation = translations[id];
119
89
  if (!translation || !translation.t) {
120
- throw new Error("<T id=\"".concat(id, "\"> with children \"").concat(children, "\" is used in a client component without a corresponding translation."));
121
- }
122
- var target = translation.t;
123
- if (isPlural) {
124
- target = (0, internal_1.getPluralBranch)(variables === null || variables === void 0 ? void 0 : variables.n, [locale, defaultLocale], (_c = (_b = target.props) === null || _b === void 0 ? void 0 : _b['data-generaltranslation']) === null || _c === void 0 ? void 0 : _c.branches) || ((_d = target === null || target === void 0 ? void 0 : target.props) === null || _d === void 0 ? void 0 : _d.children);
90
+ throw new Error("<T id=\"".concat(id, "\"> is used in a client component without a corresponding translation."));
125
91
  }
126
92
  return (0, renderTranslatedChildren_1.default)({
127
- source: source,
128
- target: target,
93
+ source: taggedChildren, target: translation.t,
129
94
  variables: variables,
130
- variablesOptions: variablesOptions
95
+ variablesOptions: variablesOptions,
96
+ locales: [locale, defaultLocale]
131
97
  });
132
98
  }
133
99
  //# sourceMappingURL=T.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"T.js","sourceRoot":"","sources":["../../src/inline/T.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,oBA8FC;AAzID,yDAAoD;AACpD,+EAAyD;AACzD,iEAA2C;AAC3C,sGAAgF;AAChF,wCAA+D;AAC/D,uDAA6D;AAC7D,oEAAiD;AACjD,4GAAsF;AACtF,yDAAmC;AACnC,+BAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,SAAwB,CAAC,CAAC,EAezB;;IAdG,IAAA,QAAQ,cAAA,EAAE,EAAE,QAAA,EACZ,SAAS,eAAA,EAAE,CAAC,OAAA,EACZ,gBAAgB,sBAAA,EAAE,OAAO,aAAA,EACtB,KAAK,cAJc,mEAKzB,CADW;IAaR,IAAI,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A,mBAAS,GAAE,CAAC;IAC3B,IAAM,aAAa,GAAG,IAAA,0BAAgB,GAAE,CAAC;IAEzC,IAAM,cAAc,GAAG,IAAA,eAAO,EAAC,cAAM,OAAA,IAAA,0BAAe,EAAC,QAAQ,CAAC,EAAzB,CAAyB,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAE3E,IAAM,mBAAmB,GAAY,CAAC;QAClC,IAAI,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAC1B,IAAI,IAAA,mCAAc,EAAC,MAAM,EAAE,aAAa,CAAC;YAAE,OAAO,KAAK,CAAC;QACxD,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,EAAE,CAAC;IAEL,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACvB,OAAO,IAAA,+BAAqB,EAAC;YACzB,KAAK,EAAE,cAAc;YACrB,SAAS,WAAA;YAAE,gBAAgB,kBAAA;SAC9B,CAAgB,CAAC;IACtB,CAAC;IAED,iBAAiB;IACjB,IAAM,WAAW,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;IACrC,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,kBAAU,EAAE,2EAAuE,CAAC,CAAA;IACxG,CAAC;IAED,OAAO,IAAA,kCAAwB,EAAC;QAC5B,MAAM,EAAE,cAAc,EAAE,MAAM,EAAG,WAAW,CAAC,CAAC;QAC9C,SAAS,WAAA;QAAE,gBAAgB,kBAAA;QAAE,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC;KAChE,CAAgB,CAAC;AACtB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  type Child = ReactNode;
3
3
  type Children = Child[] | Child;
4
- export default function addGTIdentifier(children: Children, branches?: Record<string, any>, dictionaryID?: string | undefined): any;
4
+ export default function addGTIdentifier(children: Children, outerID?: string | undefined, startingIndex?: number): any;
5
5
  export {};
6
6
  //# sourceMappingURL=addGTIdentifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"addGTIdentifier.d.ts","sourceRoot":"","sources":["../../src/internal/addGTIdentifier.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAgC,MAAM,OAAO,CAAA;AAEtE,KAAK,KAAK,GAAG,SAAS,CAAC;AACvB,KAAK,QAAQ,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;AAuEhC,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,GAAG,CAoBlI"}
1
+ {"version":3,"file":"addGTIdentifier.d.ts","sourceRoot":"","sources":["../../src/internal/addGTIdentifier.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAgC,MAAM,OAAO,CAAA;AAEtE,KAAK,KAAK,GAAG,SAAS,CAAC;AACvB,KAAK,QAAQ,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;AAYhC,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,aAAa,GAAE,MAAU,GAAG,GAAG,CA0ExH"}
@@ -33,6 +33,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
33
33
  __setModuleDefault(result, mod);
34
34
  return result;
35
35
  };
36
+ var __rest = (this && this.__rest) || function (s, e) {
37
+ var t = {};
38
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
39
+ t[p] = s[p];
40
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
41
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
42
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
43
+ t[p[i]] = s[p[i]];
44
+ }
45
+ return t;
46
+ };
36
47
  Object.defineProperty(exports, "__esModule", { value: true });
37
48
  exports.default = addGTIdentifier;
38
49
  var react_1 = __importStar(require("react"));
@@ -40,16 +51,17 @@ var acceptedPluralProps = {
40
51
  "singular": true, "dual": true, "plural": true,
41
52
  "zero": true, "one": true, "two": true, "few": true, "many": true, "other": true
42
53
  };
43
- function addIdentifierRecursively(children, dictionaryID) {
54
+ function addGTIdentifier(children, outerID, startingIndex) {
55
+ if (startingIndex === void 0) { startingIndex = 0; }
44
56
  // Object to keep track of the current index for GT IDs
45
- var indexObject = { index: 0 };
57
+ var indexObject = { index: startingIndex };
46
58
  /**
47
59
  * Function to create a GTProp object for a ReactElement
48
60
  * @param child - The ReactElement for which the GTProp is created
49
61
  * @returns - The GTProp object
50
62
  */
51
63
  var createGTProp = function (child) {
52
- var type = child.type;
64
+ var type = child.type, props = child.props;
53
65
  indexObject.index += 1;
54
66
  var result = { id: indexObject.index };
55
67
  var transformation = typeof type === 'function' ? (type.gtTransformation || '') : '';
@@ -58,6 +70,27 @@ function addIdentifierRecursively(children, dictionaryID) {
58
70
  if (transformationParts[0] === "variable") {
59
71
  result.variableType = (transformationParts === null || transformationParts === void 0 ? void 0 : transformationParts[1]) || "variable";
60
72
  }
73
+ if (transformationParts[0] === "plural") {
74
+ var pluralBranches = Object.entries(props).reduce(function (acc, _a) {
75
+ var branchName = _a[0], branch = _a[1];
76
+ if (acceptedPluralProps[branchName]) {
77
+ acc[branchName] = addGTIdentifier(branch, undefined, indexObject.index);
78
+ }
79
+ return acc;
80
+ }, {});
81
+ if (Object.keys(pluralBranches).length)
82
+ result.branches = pluralBranches;
83
+ }
84
+ if (transformationParts[0] === "branch") {
85
+ var children_1 = props.children, branch = props.branch, branches = __rest(props, ["children", "branch"]);
86
+ var resultBranches = Object.entries(branches).reduce(function (acc, _a) {
87
+ var branchName = _a[0], branch = _a[1];
88
+ acc[branchName] = addGTIdentifier(branch, undefined, indexObject.index);
89
+ return acc;
90
+ }, {});
91
+ if (Object.keys(resultBranches).length)
92
+ result.branches = resultBranches;
93
+ }
61
94
  result.transformation = transformationParts[0];
62
95
  }
63
96
  return result;
@@ -68,9 +101,9 @@ function addIdentifierRecursively(children, dictionaryID) {
68
101
  // Create new props for the element, including the GT identifier and a key
69
102
  var generaltranslation = createGTProp(child);
70
103
  var newProps = __assign(__assign({}, props), { 'data-generaltranslation': generaltranslation });
71
- if (dictionaryID) {
72
- newProps.key = dictionaryID;
73
- dictionaryID = undefined;
104
+ if (outerID) {
105
+ newProps.key = outerID;
106
+ outerID = undefined;
74
107
  }
75
108
  // Recursively add IDs to children
76
109
  if (props.children) {
@@ -82,7 +115,7 @@ function addIdentifierRecursively(children, dictionaryID) {
82
115
  }
83
116
  function handleChildren(children) {
84
117
  if (Array.isArray(children)) {
85
- dictionaryID = undefined;
118
+ outerID = undefined;
86
119
  return react_1.default.Children.map(children, handleSingleChild);
87
120
  }
88
121
  else {
@@ -91,22 +124,4 @@ function addIdentifierRecursively(children, dictionaryID) {
91
124
  }
92
125
  return handleChildren(children);
93
126
  }
94
- function addGTIdentifier(children, branches, dictionaryID) {
95
- var taggedChildren = addIdentifierRecursively(children, dictionaryID);
96
- if (typeof branches === 'undefined') {
97
- return taggedChildren;
98
- }
99
- var pluralBranches = Object.entries(branches).reduce(function (acc, _a) {
100
- var key = _a[0], value = _a[1];
101
- if (acceptedPluralProps[key]) {
102
- acc[key] = addIdentifierRecursively(value, dictionaryID); // process!
103
- }
104
- return acc;
105
- }, {});
106
- // check that work has actually been done, if not just return the default children
107
- if (!Object.keys(pluralBranches).length)
108
- return taggedChildren;
109
- return react_1.default.createElement('span', { 'data-generaltranslation': { id: 0, branches: pluralBranches, transformation: 'plural' }, children: taggedChildren });
110
- ;
111
- }
112
127
  //# sourceMappingURL=addGTIdentifier.js.map