gt-react 3.1.68 → 3.1.70

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 (81) hide show
  1. package/dist/cjs/client/client-only/GTClientProvider.js +1 -1
  2. package/dist/cjs/client/client-only/GTClientProvider.js.map +1 -1
  3. package/dist/cjs/client/hooks/useGT.d.ts.map +1 -1
  4. package/dist/cjs/client/hooks/useGT.js +2 -3
  5. package/dist/cjs/client/hooks/useGT.js.map +1 -1
  6. package/dist/cjs/dictionary/checkTFunctionOptions.js +2 -2
  7. package/dist/cjs/dictionary/checkTFunctionOptions.js.map +1 -1
  8. package/dist/cjs/dictionary/createTFunction.d.ts.map +1 -1
  9. package/dist/cjs/dictionary/createTFunction.js +7 -9
  10. package/dist/cjs/dictionary/createTFunction.js.map +1 -1
  11. package/dist/cjs/index.d.ts +5 -5
  12. package/dist/cjs/index.d.ts.map +1 -1
  13. package/dist/cjs/index.js +5 -5
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/primitives/calculateHash.d.ts +8 -0
  16. package/dist/cjs/primitives/calculateHash.d.ts.map +1 -0
  17. package/dist/cjs/primitives/calculateHash.js +55 -0
  18. package/dist/cjs/primitives/calculateHash.js.map +1 -0
  19. package/dist/cjs/primitives/dictionary/flattenDictionary.d.ts +9 -0
  20. package/dist/cjs/primitives/dictionary/flattenDictionary.d.ts.map +1 -0
  21. package/dist/cjs/primitives/dictionary/flattenDictionary.js +29 -0
  22. package/dist/cjs/primitives/dictionary/flattenDictionary.js.map +1 -0
  23. package/dist/cjs/primitives/translation/addGTIdentifier.d.ts +11 -0
  24. package/dist/cjs/primitives/translation/addGTIdentifier.d.ts.map +1 -0
  25. package/dist/cjs/primitives/translation/addGTIdentifier.js +150 -0
  26. package/dist/cjs/primitives/translation/addGTIdentifier.js.map +1 -0
  27. package/dist/cjs/primitives/translation/writeChildrenAsObjects.d.ts +11 -0
  28. package/dist/cjs/primitives/translation/writeChildrenAsObjects.d.ts.map +1 -0
  29. package/dist/cjs/primitives/translation/writeChildrenAsObjects.js +116 -0
  30. package/dist/cjs/primitives/translation/writeChildrenAsObjects.js.map +1 -0
  31. package/dist/cjs/scripts/i18n.d.ts +3 -0
  32. package/dist/cjs/scripts/i18n.d.ts.map +1 -0
  33. package/dist/cjs/scripts/i18n.js +189 -0
  34. package/dist/cjs/scripts/i18n.js.map +1 -0
  35. package/dist/cjs/server/inline/T.js +3 -3
  36. package/dist/cjs/server/inline/T.js.map +1 -1
  37. package/dist/cjs/server/intl/createIntlFunction.js +1 -1
  38. package/dist/cjs/server/intl/createIntlFunction.js.map +1 -1
  39. package/dist/cjs/server/provider/GTProvider.js +4 -4
  40. package/dist/cjs/server/provider/GTProvider.js.map +1 -1
  41. package/dist/mjs/client/client-only/GTClientProvider.js +1 -1
  42. package/dist/mjs/client/client-only/GTClientProvider.js.map +1 -1
  43. package/dist/mjs/client/hooks/useGT.d.ts.map +1 -1
  44. package/dist/mjs/client/hooks/useGT.js +2 -3
  45. package/dist/mjs/client/hooks/useGT.js.map +1 -1
  46. package/dist/mjs/dictionary/checkTFunctionOptions.js +2 -2
  47. package/dist/mjs/dictionary/checkTFunctionOptions.js.map +1 -1
  48. package/dist/mjs/dictionary/createTFunction.d.ts.map +1 -1
  49. package/dist/mjs/dictionary/createTFunction.js +7 -9
  50. package/dist/mjs/dictionary/createTFunction.js.map +1 -1
  51. package/dist/mjs/index.d.ts +5 -5
  52. package/dist/mjs/index.d.ts.map +1 -1
  53. package/dist/mjs/index.js +5 -5
  54. package/dist/mjs/index.js.map +1 -1
  55. package/dist/mjs/primitives/calculateHash.d.ts +8 -0
  56. package/dist/mjs/primitives/calculateHash.d.ts.map +1 -0
  57. package/dist/mjs/primitives/calculateHash.js +49 -0
  58. package/dist/mjs/primitives/calculateHash.js.map +1 -0
  59. package/dist/mjs/primitives/dictionary/flattenDictionary.d.ts +9 -0
  60. package/dist/mjs/primitives/dictionary/flattenDictionary.d.ts.map +1 -0
  61. package/dist/mjs/primitives/dictionary/flattenDictionary.js +23 -0
  62. package/dist/mjs/primitives/dictionary/flattenDictionary.js.map +1 -0
  63. package/dist/mjs/primitives/translation/addGTIdentifier.d.ts +11 -0
  64. package/dist/mjs/primitives/translation/addGTIdentifier.d.ts.map +1 -0
  65. package/dist/mjs/primitives/translation/addGTIdentifier.js +144 -0
  66. package/dist/mjs/primitives/translation/addGTIdentifier.js.map +1 -0
  67. package/dist/mjs/primitives/translation/writeChildrenAsObjects.d.ts +11 -0
  68. package/dist/mjs/primitives/translation/writeChildrenAsObjects.d.ts.map +1 -0
  69. package/dist/mjs/primitives/translation/writeChildrenAsObjects.js +110 -0
  70. package/dist/mjs/primitives/translation/writeChildrenAsObjects.js.map +1 -0
  71. package/dist/mjs/scripts/i18n.d.ts +3 -0
  72. package/dist/mjs/scripts/i18n.d.ts.map +1 -0
  73. package/dist/mjs/scripts/i18n.js +161 -0
  74. package/dist/mjs/scripts/i18n.js.map +1 -0
  75. package/dist/mjs/server/inline/T.js +3 -3
  76. package/dist/mjs/server/inline/T.js.map +1 -1
  77. package/dist/mjs/server/intl/createIntlFunction.js +1 -1
  78. package/dist/mjs/server/intl/createIntlFunction.js.map +1 -1
  79. package/dist/mjs/server/provider/GTProvider.js +4 -4
  80. package/dist/mjs/server/provider/GTProvider.js.map +1 -1
  81. package/package.json +28 -25
package/dist/mjs/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import determineLocale from "./index/determineLocale";
2
- import calculateHash from "./index/calculateHash";
3
- import flattenDictionary from "./index/flattenDictionary";
4
- import addGTIdentifier from "./index/addGTIdentifier";
5
- import writeChildrenAsObjects from "./index/writeChildrenAsObjects";
6
- export { determineLocale, calculateHash, flattenDictionary, writeChildrenAsObjects, addGTIdentifier };
2
+ import calculateHash from "./primitives/calculateHash";
3
+ import flattenDictionary from "./primitives/dictionary/flattenDictionary";
4
+ import addGTIdentifier from "./primitives/translation/addGTIdentifier";
5
+ import writeChildrenAsObjects from "./primitives/translation/writeChildrenAsObjects";
6
+ export { determineLocale, addGTIdentifier, writeChildrenAsObjects, flattenDictionary, calculateHash };
7
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,yBAAyB,CAAC;AACtD,OAAO,aAAa,MAAM,uBAAuB,CAAC;AAClD,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAC1D,OAAO,eAAe,MAAM,yBAAyB,CAAC;AACtD,OAAO,sBAAsB,MAAM,gCAAgC,CAAC;AACpE,OAAO,EACH,eAAe,EACf,aAAa,EAAE,iBAAiB,EAChC,sBAAsB,EAAE,eAAe,EAC1C,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,yBAAyB,CAAC;AACtD,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,iBAAiB,MAAM,2CAA2C,CAAC;AAC1E,OAAO,eAAe,MAAM,0CAA0C,CAAC;AACvE,OAAO,sBAAsB,MAAM,iDAAiD,CAAC;AACrF,OAAO,EACH,eAAe,EACf,eAAe,EAAE,sBAAsB,EACvC,iBAAiB,EACjB,aAAa,EAChB,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
3
+ *
4
+ * @param {any} childrenAsObjects - The children objects to be hashed.
5
+ * @returns {Promise<string>} - A promise that resolves to the unique ID.
6
+ */
7
+ export default function calculateHash(childrenAsObjects: any): Promise<string>;
8
+ //# sourceMappingURL=calculateHash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculateHash.d.ts","sourceRoot":"","sources":["../../../src/primitives/calculateHash.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,wBAA8B,aAAa,CAAC,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAMnF"}
@@ -0,0 +1,49 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import xxhash from "xxhash-wasm";
11
+ let hashFunctionPromise = xxhash().then(hasher => hasher.h64ToString);
12
+ let hashFunction = null;
13
+ hashFunctionPromise.then(fn => {
14
+ hashFunction = fn;
15
+ });
16
+ /**
17
+ * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
18
+ *
19
+ * @param {any} childrenAsObjects - The children objects to be hashed.
20
+ * @returns {Promise<string>} - A promise that resolves to the unique ID.
21
+ */
22
+ export default function calculateHash(childrenAsObjects) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ if (!hashFunction) {
25
+ hashFunction = yield hashFunctionPromise;
26
+ }
27
+ const unhashedKey = JSON.stringify(sanitizeChildrenAsObjects(childrenAsObjects));
28
+ return hashFunction(unhashedKey);
29
+ });
30
+ }
31
+ function sanitizeChildrenAsObjects(childrenAsObjects) {
32
+ const sanitizeChild = (child) => {
33
+ var _a;
34
+ if (typeof child === 'object' && child.type) {
35
+ if ((_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.children) {
36
+ return Object.assign(Object.assign({}, child), { props: Object.assign(Object.assign({}, child.props), { children: sanitizeChildren(child.props.children) }), type: '' });
37
+ }
38
+ else {
39
+ return Object.assign(Object.assign({}, child), { type: '' });
40
+ }
41
+ }
42
+ return child;
43
+ };
44
+ const sanitizeChildren = (children) => {
45
+ return (Array.isArray(children)) ? children.map(sanitizeChild) : sanitizeChild(children);
46
+ };
47
+ return sanitizeChildren(childrenAsObjects);
48
+ }
49
+ //# sourceMappingURL=calculateHash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculateHash.js","sourceRoot":"","sources":["../../../src/primitives/calculateHash.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,IAAI,mBAAmB,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACtE,IAAI,YAAY,GAAuC,IAAI,CAAC;AAE5D,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;IAC1B,YAAY,GAAG,EAAE,CAAC;AACtB,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAgB,aAAa,CAAC,iBAAsB;;QAC9D,IAAI,CAAC,YAAY,EAAE,CAAC;YAChB,YAAY,GAAG,MAAM,mBAAmB,CAAC;QAC7C,CAAC;QACD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,yBAAyB,CAAC,iBAAiB,CAAC,CAAC,CAAC;QACjF,OAAO,YAAY,CAAC,WAAW,CAAC,CAAC;IACrC,CAAC;CAAA;AAED,SAAS,yBAAyB,CAAC,iBAAsB;IACrD,MAAM,aAAa,GAAG,CAAC,KAAU,EAAO,EAAE;;QACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YAC1C,IAAI,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,0CAAE,QAAQ,EAAE,CAAC;gBACzB,uCACO,KAAK,KACR,KAAK,kCACE,KAAK,CAAC,KAAK,KACd,QAAQ,EAAE,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,KAEpD,IAAI,EAAE,EAAE,IACX;YACL,CAAC;iBAAM,CAAC;gBACJ,uCACO,KAAK,KACR,IAAI,EAAE,EAAE,IACX;YACL,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAA;IACD,MAAM,gBAAgB,GAAG,CAAC,QAAa,EAAO,EAAE;QAC5C,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;IAC5F,CAAC,CAAA;IACD,OAAO,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ /**
3
+ * Flattens a nested dictionary by concatenating nested keys.
4
+ * @param {Record<string, any>} dictionary - The dictionary to flatten.
5
+ * @param {string} [prefix=''] - The prefix for nested keys.
6
+ * @returns {Record<string, React.ReactNode>} The flattened dictionary object.
7
+ */
8
+ export default function flattenDictionary(dictionary: Record<string, any>, prefix?: string): Record<string, React.ReactNode>;
9
+ //# sourceMappingURL=flattenDictionary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flattenDictionary.d.ts","sourceRoot":"","sources":["../../../../src/primitives/dictionary/flattenDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAE,MAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAgB/H"}
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ /**
3
+ * Flattens a nested dictionary by concatenating nested keys.
4
+ * @param {Record<string, any>} dictionary - The dictionary to flatten.
5
+ * @param {string} [prefix=''] - The prefix for nested keys.
6
+ * @returns {Record<string, React.ReactNode>} The flattened dictionary object.
7
+ */
8
+ export default function flattenDictionary(dictionary, prefix = '') {
9
+ const flattened = {};
10
+ for (const key in dictionary) {
11
+ if (dictionary.hasOwnProperty(key)) {
12
+ const newKey = prefix ? `${prefix}.${key}` : key;
13
+ if (typeof dictionary[key] === 'object' && dictionary[key] !== null && !Array.isArray(dictionary[key]) && !(React.isValidElement(dictionary[key]))) {
14
+ Object.assign(flattened, flattenDictionary(dictionary[key], newKey));
15
+ }
16
+ else {
17
+ flattened[newKey] = dictionary[key];
18
+ }
19
+ }
20
+ }
21
+ return flattened;
22
+ }
23
+ //# sourceMappingURL=flattenDictionary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flattenDictionary.js","sourceRoot":"","sources":["../../../../src/primitives/dictionary/flattenDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,UAA+B,EAAE,SAAiB,EAAE;IAC1F,MAAM,SAAS,GAAoC,EAAE,CAAC;IAEtD,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC3B,IAAI,UAAU,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;YACjC,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;YAEjD,IAAI,OAAO,UAAU,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjJ,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,iBAAiB,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YACzE,CAAC;iBAAM,CAAC;gBACJ,SAAS,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;YACxC,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import React, { ReactNode } from 'react';
2
+ type Child = ReactNode;
3
+ type Children = Child[] | Child;
4
+ /**
5
+ * Add data-generaltranslation props, with identifiers, to React children
6
+ * @param children - The children elements to which GT identifiers will be added
7
+ * @returns - The children with added GT identifiers
8
+ */
9
+ export default function addGTIdentifier(children: Children): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined;
10
+ export {};
11
+ //# sourceMappingURL=addGTIdentifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addGTIdentifier.d.ts","sourceRoot":"","sources":["../../../../src/primitives/translation/addGTIdentifier.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAgB,MAAM,OAAO,CAAA;AAEtD,KAAK,KAAK,GAAG,SAAS,CAAC;AACvB,KAAK,QAAQ,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;AAuBhC;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,QAAQ,EAAE,QAAQ,iJAsIzD"}
@@ -0,0 +1,144 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React from 'react';
13
+ const acceptedPluralProps = {
14
+ "singular": true, "dual": true, "plural": true,
15
+ "zero": true, "one": true, "two": true, "few": true, "many": true, "other": true
16
+ };
17
+ /**
18
+ * Helper function to validate the properties of the component to prevent nested translations
19
+ * @param props - The properties of the current React element
20
+ */
21
+ const validateProps = (props) => {
22
+ if (props && props['data-generaltranslation'] && typeof props['data-generaltranslation'].id === 'number') {
23
+ throw new Error(`Nesting of <T>, <Plural>, <Value> components is not permitted. This prevents components from being translated twice!
24
+ Found nested component with id: ${props === null || props === void 0 ? void 0 : props.id}, content: ${props === null || props === void 0 ? void 0 : props.children}`);
25
+ }
26
+ };
27
+ /**
28
+ * Add data-generaltranslation props, with identifiers, to React children
29
+ * @param children - The children elements to which GT identifiers will be added
30
+ * @returns - The children with added GT identifiers
31
+ */
32
+ export default function addGTIdentifier(children) {
33
+ // Object to keep track of the current index for GT IDs
34
+ let indexObject = { index: 0 };
35
+ /**
36
+ * Function to create a GTProp object for a ReactElement
37
+ * @param child - The ReactElement for which the GTProp is created
38
+ * @returns - The GTProp object
39
+ */
40
+ const createGTProp = (child) => {
41
+ const { type, props } = child;
42
+ indexObject.index += 1;
43
+ let result = { id: indexObject.index };
44
+ const transformation = typeof type === 'function' ? (type.gtTransformation || '') : '';
45
+ if (transformation) {
46
+ const transformationParts = transformation.split('-');
47
+ if (transformationParts[0] === "variable") {
48
+ result.variableType = (transformationParts === null || transformationParts === void 0 ? void 0 : transformationParts[1]) || "variable";
49
+ }
50
+ result.transformation = transformationParts[0];
51
+ }
52
+ return result;
53
+ };
54
+ /**
55
+ * Function to handle valid React elements and add GT identifiers
56
+ * @param child - The ReactElement to handle
57
+ * @returns - The new ReactElement with added GT identifiers
58
+ */
59
+ const handleValidReactElement = (child) => {
60
+ // Destructure the props from the child element
61
+ const { props } = child;
62
+ // Validate the props to ensure there are no nested translations
63
+ validateProps(props);
64
+ // Create new props for the element, including the GT identifier and a key
65
+ let generaltranslation = createGTProp(child);
66
+ let newProps = Object.assign(Object.assign({}, props), { 'data-generaltranslation': generaltranslation, key: generaltranslation.id });
67
+ // If branches are needed for a number or value variable
68
+ const transformation = generaltranslation.transformation;
69
+ if (transformation === "plural") {
70
+ // Updates indices to keep a consistent identification system across branches
71
+ let frozenIndex = indexObject.index;
72
+ let championIndex = indexObject.index;
73
+ const updateIndices = () => {
74
+ if (indexObject.index > frozenIndex) {
75
+ if (indexObject.index > championIndex) {
76
+ championIndex = indexObject.index;
77
+ }
78
+ indexObject.index = frozenIndex;
79
+ }
80
+ };
81
+ // Adds ID to children
82
+ if (props.children) {
83
+ newProps.children = addIdentifierRecursively(props.children);
84
+ }
85
+ // define branches
86
+ let branches = {};
87
+ // add identifier to number branches (e.g. singular, plural, ranges)
88
+ if (transformation === "plural") {
89
+ const { n, children, locales } = props, options = __rest(props, ["n", "children", "locales"]);
90
+ let { ranges } = options, others = __rest(options, ["ranges"]);
91
+ if (ranges)
92
+ branches.ranges = options.ranges.map((range) => {
93
+ updateIndices();
94
+ return { min: range.min, max: range.max, children: addIdentifierRecursively(range.children) };
95
+ });
96
+ for (const option of Object.keys(others).filter(item => acceptedPluralProps[item] ? true : false)) {
97
+ if (others[option]) {
98
+ updateIndices();
99
+ branches[option] = addIdentifierRecursively(others[option]);
100
+ }
101
+ }
102
+ newProps = Object.assign(Object.assign({}, newProps), branches);
103
+ }
104
+ // modify newProps if necessary
105
+ if (Object.keys(branches).length > 0)
106
+ newProps['data-generaltranslation'].branches = branches;
107
+ if (newProps.children)
108
+ newProps['data-generaltranslation'].defaultChildren = newProps.children;
109
+ // reset index
110
+ indexObject.index = championIndex;
111
+ }
112
+ // if no transformation is required
113
+ if (transformation !== "plural") {
114
+ if (props.children) {
115
+ newProps.children = addIdentifierRecursively(props.children);
116
+ }
117
+ }
118
+ // return the element with new props
119
+ return React.cloneElement(child, newProps);
120
+ };
121
+ /**
122
+ * Function to handle a single child element and determine if it's a valid React element
123
+ * @param child - The child element to handle
124
+ * @returns - The handled child element
125
+ */
126
+ const handleSingleChild = (child) => {
127
+ if (React.isValidElement(child))
128
+ return handleValidReactElement(child);
129
+ return child;
130
+ };
131
+ /**
132
+ * Recursive function to add GT identifiers to all child elements
133
+ * @param children - The children elements to process
134
+ * @returns - The children elements with added GT identifiers
135
+ */
136
+ const addIdentifierRecursively = (children) => {
137
+ if (Array.isArray(children)) {
138
+ return children.map(child => handleSingleChild(child));
139
+ }
140
+ return handleSingleChild(children);
141
+ };
142
+ return addIdentifierRecursively(children);
143
+ }
144
+ //# sourceMappingURL=addGTIdentifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addGTIdentifier.js","sourceRoot":"","sources":["../../../../src/primitives/translation/addGTIdentifier.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAkC,MAAM,OAAO,CAAA;AAUtD,MAAM,mBAAmB,GAA4B;IACjD,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI;IAC9C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI;CACnF,CAAA;AAED;;;GAGG;AACH,MAAM,aAAa,GAAG,CAAC,KAA0B,EAAQ,EAAE;IACvD,IAAI,KAAK,IAAI,KAAK,CAAC,yBAAyB,CAAC,IAAI,OAAO,KAAK,CAAC,yBAAyB,CAAC,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QACvG,MAAM,IAAI,KAAK,CAAC;8CACsB,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,EAAE,cAAc,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,EAAE,CAAC,CAAC;IACpF,CAAC;AACL,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,QAAkB;IAEtD,uDAAuD;IACvD,IAAI,WAAW,GAAsB,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAElD;;;;OA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AC;IACjB,CAAC,CAAA;IAED;;;;OAIG;IACH,MAAM,wBAAwB,GAAG,CAAC,QAAmB,EAAE,EAAE;QACrD,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1B,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAA;QAC1D,CAAC;QACD,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC,CAAA;IAED,OAAO,wBAAwB,CAAC,QAAQ,CAAC,CAAC;AAE9C,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { ReactNode } from 'react';
2
+ type Child = ReactNode | Record<string, any>;
3
+ type Children = Child | Child[];
4
+ /**
5
+ * Transforms children elements into objects, processing each child recursively if needed.
6
+ * @param {Children} children - The children to process.
7
+ * @returns {object} The processed children as objects.
8
+ */
9
+ export default function writeChildrenAsObjects(children: Children): any;
10
+ export {};
11
+ //# sourceMappingURL=writeChildrenAsObjects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeChildrenAsObjects.d.ts","sourceRoot":"","sources":["../../../../src/primitives/translation/writeChildrenAsObjects.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAgB,MAAM,OAAO,CAAA;AAGtD,KAAK,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC7C,KAAK,QAAQ,GAAG,KAAK,GAAG,KAAK,EAAE,CAAC;AA8FhC;;;;EAIE;AACF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,GAAG,GAAG,CAKtE"}
@@ -0,0 +1,110 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React from 'react';
13
+ import defaultVariableNames from '../variables/defaultVariableNames';
14
+ /**
15
+ * Gets the tag name of a React element.
16
+ * @param {ReactElement} child - The React element.
17
+ * @returns {string} - The tag name of the React element.
18
+ */
19
+ const getTagName = (child) => {
20
+ var _a;
21
+ if (!child)
22
+ return '';
23
+ const { type, props } = child;
24
+ if (type && typeof type === 'function') {
25
+ if ('displayName' in type && typeof type.displayName === 'string' && type.displayName)
26
+ return type.displayName;
27
+ if ('name' in type && typeof type.name === 'string' && type.name)
28
+ return type.name;
29
+ }
30
+ if (type && typeof type === 'string')
31
+ return type;
32
+ if (props.href)
33
+ return 'a';
34
+ if ((_a = props['data-generaltranslation']) === null || _a === void 0 ? void 0 : _a.id)
35
+ return `C${props['data-generaltranslation'].id}`;
36
+ return 'function';
37
+ };
38
+ /**
39
+ * Handles processing of a valid React element, transforming its properties and children as needed.
40
+ * @param {ReactElement} child - The React element to process.
41
+ * @returns {object} - The processed element with its type and transformed props.
42
+ */
43
+ const handleValidReactElement = (child) => {
44
+ const { type, props } = child;
45
+ let newProps = {};
46
+ // Transform children if they exist and are not private
47
+ if (props.children) {
48
+ newProps.children = writeChildrenAsObjects(props.children);
49
+ }
50
+ // Write the branches of 'data-generaltranslation' as objects
51
+ if (props['data-generaltranslation']) {
52
+ const generaltranslation = props['data-generaltranslation'];
53
+ let result = Object.assign({}, generaltranslation);
54
+ if (generaltranslation.transformation && generaltranslation.transformation === "variable") {
55
+ const variableName = props.name || defaultVariableNames[generaltranslation.variableType] || "value";
56
+ return { variable: generaltranslation.variableType || "variable", key: variableName };
57
+ }
58
+ // Write all the branches as objects
59
+ if (generaltranslation.transformation && generaltranslation.branches) {
60
+ const transformation = generaltranslation.transformation;
61
+ // Write the branches of a number variable transformation
62
+ if (transformation === "plural") {
63
+ const _a = generaltranslation.branches, { ranges } = _a, others = __rest(_a, ["ranges"]);
64
+ if (ranges) {
65
+ result.branches.ranges = ranges.map((range) => {
66
+ return { min: range.min, max: range.max, children: writeChildrenAsObjects(range.children) };
67
+ });
68
+ }
69
+ for (const option of Object.keys(others)) {
70
+ result.branches[option] = writeChildrenAsObjects(others[option]);
71
+ }
72
+ }
73
+ }
74
+ // Write defaultChildren
75
+ if (generaltranslation.defaultChildren) {
76
+ result.defaultChildren = writeChildrenAsObjects(generaltranslation.defaultChildren);
77
+ }
78
+ newProps['data-generaltranslation'] = result;
79
+ }
80
+ return {
81
+ type: getTagName(child),
82
+ props: newProps
83
+ };
84
+ };
85
+ /**
86
+ * Handles processing of a single child, determining if it is a valid React element or an object.
87
+ * @param {any} child - The child to process.
88
+ * @returns {object} - The processed child or the original child if no transformation is needed.
89
+ */
90
+ const handleSingleChild = (child) => {
91
+ if (React.isValidElement(child))
92
+ return handleValidReactElement(child);
93
+ else if (child && typeof child === 'object') {
94
+ return { variable: true, keys: Object.keys(child) };
95
+ }
96
+ else
97
+ return child;
98
+ };
99
+ /**
100
+ * Transforms children elements into objects, processing each child recursively if needed.
101
+ * @param {Children} children - The children to process.
102
+ * @returns {object} The processed children as objects.
103
+ */
104
+ export default function writeChildrenAsObjects(children) {
105
+ if (Array.isArray(children)) {
106
+ return children.map(child => handleSingleChild(child));
107
+ }
108
+ return handleSingleChild(children);
109
+ }
110
+ //# sourceMappingURL=writeChildrenAsObjects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeChildrenAsObjects.js","sourceRoot":"","sources":["../../../../src/primitives/translation/writeChildrenAsObjects.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAkC,MAAM,OAAO,CAAA;AACtD,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AAKrE;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAC,KAAmB,EAAU,EAA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C,eAAe,GAAG,sBAAsB,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAA;QACvF,CAAC;QAED,QAAQ,CAAC,yBAAyB,CAAC,GAAG,MAAM,CAAC;IAEjD,CAAC;IAED,OAAO;QACH,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC;QACvB,KAAK,EAAE,QAAQ;KAClB,CAAA;AACL,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAU,EAAU,EAAE;IAC7C,IAAI,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC;QAAE,OAAO,uBAAuB,CAAC,KAAK,CAAC,CAAC;SAClE,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAA;IACvD,CAAC;;QACI,OAAO,KAAK,CAAC;AACtB,CAAC,CAAA;AAED;;;;EAIE;AACF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,QAAkB;IAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAA;IAC1D,CAAC;IACD,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAA;AACtC,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import 'dotenv/config';
3
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../../src/scripts/i18n.ts"],"names":[],"mappings":";AAEA,OAAO,eAAe,CAAC"}
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env node
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 __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ import 'dotenv/config';
23
+ import path from 'path';
24
+ import React from 'react';
25
+ import { program } from 'commander';
26
+ import { default as GT, getLanguageName, isValidLanguageCode, getLanguageCode } from 'generaltranslation';
27
+ import fs from 'fs';
28
+ import flattenDictionary from '../primitives/dictionary/flattenDictionary';
29
+ import writeChildrenAsObjects from '../primitives/translation/writeChildrenAsObjects';
30
+ import addGTIdentifier from '../primitives/translation/addGTIdentifier';
31
+ require('@babel/register')({
32
+ presets: [
33
+ ['@babel/preset-react', { runtime: 'automatic' }],
34
+ '@babel/preset-env'
35
+ ],
36
+ extensions: ['.js', '.jsx', '.ts', '.tsx'],
37
+ ignore: [/(node_modules)/],
38
+ });
39
+ function processDictionaryFile(dictionaryFilePath, options) {
40
+ const absoluteDictionaryFilePath = path.resolve(dictionaryFilePath);
41
+ let dictionary;
42
+ try {
43
+ dictionary = require(absoluteDictionaryFilePath).default || require(absoluteDictionaryFilePath);
44
+ }
45
+ catch (error) {
46
+ console.error('Failed to load the dictionary file:', error);
47
+ process.exit(1);
48
+ }
49
+ dictionary = flattenDictionary(dictionary);
50
+ const apiKey = options.apiKey || process.env.GT_API_KEY;
51
+ const projectID = options.projectID || process.env.GT_PROJECT_ID;
52
+ const dictionaryName = options.dictionaryName;
53
+ const defaultLanguage = options.defaultLanguage;
54
+ const languages = (options.languages || [])
55
+ .map(language => isValidLanguageCode(language) ? language : getLanguageCode(language))
56
+ .filter(language => language ? true : false);
57
+ const override = options.override ? true : false;
58
+ if (!(apiKey && projectID)) {
59
+ throw new Error('GT_API_KEY and GT_PROJECT_ID environment variables or provided arguments are required.');
60
+ }
61
+ let templateUpdates = [];
62
+ for (const key in dictionary) {
63
+ let entry = dictionary[key];
64
+ let metadata = { id: key, dictionaryName };
65
+ if (defaultLanguage) {
66
+ metadata.defaultLanguage = defaultLanguage;
67
+ }
68
+ let props = {};
69
+ if (Array.isArray(entry)) {
70
+ if (typeof entry[1] === 'object') {
71
+ props = entry[1];
72
+ }
73
+ entry = entry[0];
74
+ }
75
+ if (React.isValidElement(entry)) {
76
+ let wrappedEntry;
77
+ const { singular, plural, dual, zero, one, two, few, many, other, ranges } = props, tMetadata = __rest(props, ["singular", "plural", "dual", "zero", "one", "two", "few", "many", "other", "ranges"]);
78
+ const pluralProps = Object.fromEntries(Object.entries({ singular, plural, dual, zero, one, two, few, many, other, ranges }).filter(([_, value]) => value !== undefined));
79
+ if (Object.keys(pluralProps).length) {
80
+ const Plural = (pluralProps) => React.createElement(React.Fragment, pluralProps, entry);
81
+ Plural.gtTransformation = 'plural';
82
+ wrappedEntry = React.createElement(Plural, pluralProps, entry);
83
+ }
84
+ else {
85
+ wrappedEntry = React.createElement(React.Fragment, null, entry);
86
+ }
87
+ ;
88
+ const entryAsObjects = writeChildrenAsObjects(addGTIdentifier(wrappedEntry)); // simulate gt-react's t() function
89
+ templateUpdates.push({
90
+ type: "react",
91
+ data: {
92
+ children: entryAsObjects,
93
+ metadata: Object.assign(Object.assign({}, metadata), tMetadata)
94
+ }
95
+ });
96
+ }
97
+ else if (typeof entry === 'string') {
98
+ templateUpdates.push({
99
+ type: "intl",
100
+ data: {
101
+ content: entry,
102
+ metadata: Object.assign(Object.assign({}, metadata), props)
103
+ }
104
+ });
105
+ }
106
+ }
107
+ if (templateUpdates.length) {
108
+ const gt = new GT({ apiKey, projectID });
109
+ const sendUpdates = () => __awaiter(this, void 0, void 0, function* () {
110
+ const resultLanguages = yield gt.updateRemoteDictionary(templateUpdates, languages, projectID, override);
111
+ if (resultLanguages) {
112
+ console.log(`Remote dictionary updated: ${resultLanguages.length ? true : false}.`, (`Languages: ${resultLanguages.length ? `[${resultLanguages.map(language => `"${getLanguageName(language)}"`).join(', ')}]` + '.' : 'None.'}`), resultLanguages.length ? 'Translations are usually live within a minute.' : '');
113
+ }
114
+ else {
115
+ throw new Error('500: Internal Server Error.');
116
+ }
117
+ process.exit(0);
118
+ });
119
+ sendUpdates();
120
+ }
121
+ setTimeout(() => {
122
+ process.exit(0);
123
+ }, 4000);
124
+ }
125
+ function resolveFilePath(filePath, defaultPaths) {
126
+ if (filePath) {
127
+ return filePath;
128
+ }
129
+ for (const possiblePath of defaultPaths) {
130
+ if (fs.existsSync(possiblePath)) {
131
+ return possiblePath;
132
+ }
133
+ }
134
+ throw new Error('File not found in default locations.');
135
+ }
136
+ program
137
+ .name('update')
138
+ .description('Process React dictionary files and send translations to General Translation services')
139
+ .version('1.0.0')
140
+ .argument('[dictionaryFilePath]', 'Path to the dictionary file')
141
+ .option('--apiKey <apiKey>', 'Specify your GT API key')
142
+ .option('--projectID <projectID>', 'Specify your GT project ID')
143
+ .option('--dictionaryName <name>', 'Optionally specify a dictionary name for metadata purposes')
144
+ .option('--languages <languages...>', 'List of target languages for translation')
145
+ .option('--override', 'Override existing translations')
146
+ .option('--defaultLanguage <defaultLanguage>', 'Specify a default language code or name for metadata purposes')
147
+ .action((dictionaryFilePath, options) => {
148
+ const resolvedDictionaryFilePath = resolveFilePath(dictionaryFilePath, [
149
+ './dictionary.js',
150
+ './dictionary.jsx',
151
+ './dictionary.ts',
152
+ './dictionary.tsx',
153
+ './src/dictionary.js',
154
+ './src/dictionary.jsx',
155
+ './src/dictionary.ts',
156
+ './src/dictionary.tsx'
157
+ ]);
158
+ processDictionaryFile(resolvedDictionaryFilePath, options);
159
+ });
160
+ program.parse(process.argv);
161
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../../src/scripts/i18n.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,eAAe,CAAC;AACvB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,eAAe,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1G,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,iBAAiB,MAAM,4CAA4C,CAAC;AAC3E,OAAO,sBAAsB,MAAM,kDAAkD,CAAC;AACtF,OAAO,eAAe,MAAM,2CAA2C,CAAC;AAExE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACvB,OAAO,EAAE;QACL,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;QACjD,mBAAmB;KACtB;IACD,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;IAC1C,MAAM,EAAE,CAAC,gBAAgB,CAAC;CAC7B,CAAC,CAAC;AAWH,SAAS,qBAAqB,CAAC,kBAA0B,EAAE,OAAqC;IAC5F,MAAM,0BAA0B,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEpE,IAAI,UAA+B,CAAC;IACpC,IAAI,CAAC;QACD,UAAU,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC,OAAO,IAAI,OA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F,MAAM,CAAC,4BAA4B,EAAE,0CAA0C,CAAC;KAChF,MAAM,CAAC,YAAY,EAAE,gCAAgC,CAAC;KACtD,MAAM,CAAC,qCAAqC,EAAE,+DAA+D,CAAC;KAC9G,MAAM,CAAC,CAAC,kBAA0B,EAAE,OAAqC,EAAE,EAAE;IAC1E,MAAM,0BAA0B,GAAG,eAAe,CAAC,kBAAkB,EAAE;QACnE,iBAAiB;QACjB,kBAAkB;QAClB,iBAAiB;QACjB,kBAAkB;QAClB,qBAAqB;QACrB,sBAAsB;QACtB,qBAAqB;QACrB,sBAAsB;KACzB,CAAC,CAAC;IACH,qBAAqB,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -20,11 +20,11 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  };
21
21
  import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
22
22
  import { Suspense } from 'react';
23
- import addGTIdentifier from '../../index/addGTIdentifier';
24
- import writeChildrenAsObjects from '../../index/writeChildrenAsObjects';
23
+ import addGTIdentifier from '../../primitives/translation/addGTIdentifier';
24
+ import writeChildrenAsObjects from '../../primitives/translation/writeChildrenAsObjects';
25
25
  import renderChildren from './renderChildren';
26
26
  import Resolver from './Resolver';
27
- import calculateHash from '../../index/calculateHash';
27
+ import calculateHash from '../../primitives/calculateHash';
28
28
  const ServerT = (_a) => __awaiter(void 0, void 0, void 0, function* () {
29
29
  var { I18NConfig, children, locale } = _a, props = __rest(_a, ["I18NConfig", "children", "locale"]);
30
30
  // Handle case where translation is not required, for example if the user's browser is in the default locale