gt-react 8.2.22 → 8.2.24
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.
- package/README.md +76 -9
- package/dist/branches/Branch.js +4 -4
- package/dist/branches/Branch.js.map +1 -1
- package/dist/branches/plurals/Plural.js +10 -10
- package/dist/branches/plurals/Plural.js.map +1 -1
- package/dist/branches/plurals/getPluralBranch.js +3 -3
- package/dist/branches/plurals/getPluralBranch.js.map +1 -1
- package/dist/client.cjs.min.cjs +19 -0
- package/dist/client.cjs.min.cjs.map +1 -0
- package/dist/client.d.ts +484 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.esm.min.mjs +19 -0
- package/dist/client.esm.min.mjs.map +1 -0
- package/dist/client.js +3 -3
- package/dist/client.js.map +1 -1
- package/dist/hooks/useBrowserLocale.d.ts.map +1 -1
- package/dist/hooks/useBrowserLocale.js +8 -10
- package/dist/hooks/useBrowserLocale.js.map +1 -1
- package/dist/hooks/useDefaultLocale.js +1 -1
- package/dist/hooks/useDefaultLocale.js.map +1 -1
- package/dist/hooks/useElement.js +11 -14
- package/dist/hooks/useElement.js.map +1 -1
- package/dist/hooks/useGT.js +9 -12
- package/dist/hooks/useGT.js.map +1 -1
- package/dist/hooks/useLocale.js +1 -1
- package/dist/hooks/useLocale.js.map +1 -1
- package/dist/index.cjs.min.cjs +19 -0
- package/dist/index.cjs.min.cjs.map +1 -0
- package/dist/index.esm.min.mjs +19 -0
- package/dist/index.esm.min.mjs.map +1 -0
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/inline/T.d.ts +1 -1
- package/dist/inline/T.d.ts.map +1 -1
- package/dist/inline/T.js +38 -51
- package/dist/inline/T.js.map +1 -1
- package/dist/internal/addGTIdentifier.js +18 -32
- package/dist/internal/addGTIdentifier.js.map +1 -1
- package/dist/internal/flattenDictionary.js +8 -11
- package/dist/internal/flattenDictionary.js.map +1 -1
- package/dist/internal/writeChildrenAsObjects.js +22 -35
- package/dist/internal/writeChildrenAsObjects.js.map +1 -1
- package/dist/internal.cjs.min.cjs +2 -0
- package/dist/internal.cjs.min.cjs.map +1 -0
- package/dist/internal.d.ts +16 -17
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.esm.min.mjs +2 -0
- package/dist/internal.esm.min.mjs.map +1 -0
- package/dist/internal.js +15 -15
- package/dist/internal.js.map +1 -1
- package/dist/messages/createMessages.js +16 -38
- package/dist/messages/createMessages.js.map +1 -1
- package/dist/provider/ClientProvider.d.ts +23 -0
- package/dist/provider/ClientProvider.d.ts.map +1 -0
- package/dist/provider/GTContext.d.ts +1 -1
- package/dist/provider/GTContext.d.ts.map +1 -1
- package/dist/provider/GTContext.js +3 -4
- package/dist/provider/GTContext.js.map +1 -1
- package/dist/provider/GTProvider.d.ts +2 -2
- package/dist/provider/GTProvider.d.ts.map +1 -1
- package/dist/provider/GTProvider.js +95 -146
- package/dist/provider/GTProvider.js.map +1 -1
- package/dist/provider/helpers/extractEntryMetadata.d.ts +3 -3
- package/dist/provider/helpers/extractEntryMetadata.d.ts.map +1 -1
- package/dist/provider/helpers/getDictionaryEntry.js +5 -6
- package/dist/provider/helpers/getDictionaryEntry.js.map +1 -1
- package/dist/provider/helpers/isVariableObject.js +2 -2
- package/dist/provider/helpers/isVariableObject.js.map +1 -1
- package/dist/provider/rendering/defaultRenderSettings.js +2 -13
- package/dist/provider/rendering/defaultRenderSettings.js.map +1 -1
- package/dist/provider/rendering/renderDefaultChildren.d.ts +2 -2
- package/dist/provider/rendering/renderDefaultChildren.js +32 -44
- package/dist/provider/rendering/renderDefaultChildren.js.map +1 -1
- package/dist/provider/rendering/renderTranslatedChildren.js +97 -110
- package/dist/provider/rendering/renderTranslatedChildren.js.map +1 -1
- package/dist/provider/rendering/renderVariable.js +6 -7
- package/dist/provider/rendering/renderVariable.js.map +1 -1
- package/dist/provider/runtime/useRuntimeTranslation.d.ts +1 -1
- package/dist/provider/runtime/useRuntimeTranslation.d.ts.map +1 -1
- package/dist/provider/runtime/useRuntimeTranslation.js +171 -239
- package/dist/provider/runtime/useRuntimeTranslation.js.map +1 -1
- package/dist/types/types.d.ts +22 -8
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils/utils.js +5 -5
- package/dist/utils/utils.js.map +1 -1
- package/dist/variables/Currency.js +11 -23
- package/dist/variables/Currency.js.map +1 -1
- package/dist/variables/DateTime.js +10 -11
- package/dist/variables/DateTime.js.map +1 -1
- package/dist/variables/Num.js +9 -10
- package/dist/variables/Num.js.map +1 -1
- package/dist/variables/Var.js +3 -4
- package/dist/variables/Var.js.map +1 -1
- package/dist/variables/_getVariableProps.js +7 -18
- package/dist/variables/_getVariableProps.js.map +1 -1
- package/dist/variables/getVariableName.js +5 -7
- package/dist/variables/getVariableName.js.map +1 -1
- package/package.json +31 -14
- package/rollup.base.config.js +33 -0
- package/rollup.config.js +111 -0
- package/tsconfig.json +3 -2
- package/dist/errors/createErrors.d.ts +0 -13
- package/dist/errors/createErrors.d.ts.map +0 -1
- package/dist/errors/createErrors.js +0 -28
- package/dist/errors/createErrors.js.map +0 -1
- package/dist/provider/dynamic/useDynamicTranslation.d.ts +0 -28
- package/dist/provider/dynamic/useDynamicTranslation.d.ts.map +0 -1
- package/dist/provider/dynamic/useDynamicTranslation.js +0 -194
- package/dist/provider/dynamic/useDynamicTranslation.js.map +0 -1
- package/dist/provider/dynamic/useRuntimeTranslation.d.ts +0 -28
- package/dist/provider/dynamic/useRuntimeTranslation.d.ts.map +0 -1
- package/dist/provider/dynamic/useRuntimeTranslation.js +0 -194
- package/dist/provider/dynamic/useRuntimeTranslation.js.map +0 -1
- package/dist/translate/translateDictionaryStrings.d.ts +0 -3
- package/dist/translate/translateDictionaryStrings.d.ts.map +0 -1
- package/dist/translate/translateDictionaryStrings.js +0 -97
- package/dist/translate/translateDictionaryStrings.js.map +0 -1
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,33 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
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);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
11
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
50
12
|
var t = {};
|
|
51
13
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -59,55 +21,50 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
59
21
|
};
|
|
60
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
23
|
exports.default = useRuntimeTranslation;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
24
|
+
const react_1 = require("react");
|
|
25
|
+
const createMessages_1 = require("../../messages/createMessages");
|
|
26
|
+
const defaultProps_1 = require("../config/defaultProps");
|
|
65
27
|
function useRuntimeTranslation(_a) {
|
|
66
|
-
var
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
var translationEnabled = !!(runtimeUrl && projectId);
|
|
28
|
+
var { targetLocale, projectId, devApiKey, runtimeUrl, defaultLocale, renderSettings, setTranslations } = _a, metadata = __rest(_a, ["targetLocale", "projectId", "devApiKey", "runtimeUrl", "defaultLocale", "renderSettings", "setTranslations"]);
|
|
29
|
+
metadata = Object.assign(Object.assign({}, metadata), { projectId, sourceLocale: defaultLocale });
|
|
30
|
+
const [inflightCount, setInflightCount] = (0, react_1.useState)(0);
|
|
31
|
+
const [conccurentRequestCount, setConcurrentRequestCount] = (0, react_1.useState)(0);
|
|
32
|
+
const [requestMap, setRequestMap] = (0, react_1.useState)(new Map());
|
|
33
|
+
const [activeRequests, setActiveRequests] = (0, react_1.useState)(0);
|
|
34
|
+
const translationEnabled = !!(runtimeUrl && projectId);
|
|
74
35
|
if (!translationEnabled)
|
|
75
36
|
return {
|
|
76
|
-
translationEnabled
|
|
77
|
-
translateContent:
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
translateChildren: function () {
|
|
81
|
-
return Promise.reject(new Error("translateChildren() failed because translation is disabled"));
|
|
82
|
-
},
|
|
37
|
+
translationEnabled,
|
|
38
|
+
translateContent: () => Promise.reject(new Error("translateContent() failed because translation is disabled")),
|
|
39
|
+
translateChildren: () => Promise.reject(new Error("translateChildren() failed because translation is disabled")),
|
|
83
40
|
};
|
|
84
41
|
// Requests waiting to be sent (not yet batched)
|
|
85
|
-
|
|
42
|
+
const requestQueueRef = (0, react_1.useRef)(new Map());
|
|
86
43
|
// Requests that have yet to be resolved
|
|
87
|
-
|
|
88
|
-
|
|
44
|
+
const pendingRequestQueueRef = (0, react_1.useRef)(new Map());
|
|
45
|
+
const translateContent = (0, react_1.useCallback)((params) => {
|
|
89
46
|
// get the key
|
|
90
|
-
|
|
91
|
-
|
|
47
|
+
const id = params.metadata.id ? `${params.metadata.id}-` : "";
|
|
48
|
+
const key = `${id}-${params.metadata.hash}-${params.targetLocale}`;
|
|
92
49
|
// return a promise to current request if it exists
|
|
93
|
-
|
|
50
|
+
const inflightRequest = pendingRequestQueueRef.current.get(key);
|
|
94
51
|
if (inflightRequest) {
|
|
95
52
|
return inflightRequest;
|
|
96
53
|
}
|
|
97
54
|
// promise for hooking into the translation request request to know when complete
|
|
98
|
-
|
|
55
|
+
const translationPromise = new Promise((resolve, reject) => {
|
|
99
56
|
requestQueueRef.current.set(key, {
|
|
100
57
|
type: "content",
|
|
101
58
|
source: params.source,
|
|
102
59
|
metadata: params.metadata,
|
|
103
|
-
resolve
|
|
104
|
-
reject
|
|
60
|
+
resolve,
|
|
61
|
+
reject,
|
|
105
62
|
});
|
|
106
63
|
})
|
|
107
|
-
.catch(
|
|
64
|
+
.catch((error) => {
|
|
108
65
|
throw error;
|
|
109
66
|
})
|
|
110
|
-
.finally(
|
|
67
|
+
.finally(() => {
|
|
111
68
|
pendingRequestQueueRef.current.delete(key);
|
|
112
69
|
});
|
|
113
70
|
return translationPromise;
|
|
@@ -116,207 +73,182 @@ function useRuntimeTranslation(_a) {
|
|
|
116
73
|
* Call this from <T> components to request a translation key.
|
|
117
74
|
* Keys are batched and fetched in the next effect cycle.
|
|
118
75
|
*/
|
|
119
|
-
|
|
76
|
+
const translateChildren = (0, react_1.useCallback)((params) => {
|
|
120
77
|
// get the key
|
|
121
|
-
|
|
122
|
-
|
|
78
|
+
const id = params.metadata.id ? `${params.metadata.id}-` : "";
|
|
79
|
+
const key = `${id}-${params.metadata.hash}-${params.targetLocale}`;
|
|
123
80
|
// return a promise to current request if it exists
|
|
124
|
-
|
|
81
|
+
const inflightRequest = pendingRequestQueueRef.current.get(key);
|
|
125
82
|
if (inflightRequest) {
|
|
126
83
|
return inflightRequest;
|
|
127
84
|
}
|
|
128
85
|
// promise for hooking into the translation request to know when complete
|
|
129
|
-
|
|
86
|
+
const translationPromise = new Promise((resolve, reject) => {
|
|
130
87
|
requestQueueRef.current.set(key, {
|
|
131
88
|
type: "jsx",
|
|
132
89
|
source: params.source,
|
|
133
90
|
metadata: params.metadata,
|
|
134
|
-
resolve
|
|
135
|
-
reject
|
|
91
|
+
resolve,
|
|
92
|
+
reject,
|
|
136
93
|
});
|
|
137
94
|
})
|
|
138
|
-
.catch(
|
|
95
|
+
.catch((error) => {
|
|
139
96
|
throw error;
|
|
140
97
|
})
|
|
141
|
-
.finally(
|
|
98
|
+
.finally(() => {
|
|
142
99
|
pendingRequestQueueRef.current.delete(key);
|
|
143
100
|
});
|
|
144
101
|
return translationPromise;
|
|
145
102
|
}, []);
|
|
146
|
-
|
|
103
|
+
const [count, setCount] = (0, react_1.useState)(0);
|
|
147
104
|
// Send a request to the runtime server
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
response = _b.sent();
|
|
213
|
-
if (!!response.ok) return [3 /*break*/, 4];
|
|
214
|
-
_a = Error.bind;
|
|
215
|
-
return [4 /*yield*/, response.text()];
|
|
216
|
-
case 3: throw new (_a.apply(Error, [void 0, _b.sent()]))();
|
|
217
|
-
case 4: return [4 /*yield*/, response.json()];
|
|
218
|
-
case 5:
|
|
219
|
-
results = (_b.sent());
|
|
220
|
-
// don't send another req if one is already in flight
|
|
221
|
-
// process each result
|
|
222
|
-
results.forEach(function (result, index) {
|
|
223
|
-
var _a, _b, _c;
|
|
224
|
-
var request = requests[index];
|
|
225
|
-
// translation received
|
|
226
|
-
if ("translation" in result && result.translation && result.reference) {
|
|
227
|
-
var translation = result.translation, _d = result.reference, id = _d.id, hash = _d.key;
|
|
228
|
-
// check for mismatching ids or hashes
|
|
229
|
-
if (id !== request.metadata.id || hash !== request.metadata.hash) {
|
|
230
|
-
if (!request.metadata.id) {
|
|
231
|
-
console.warn((0, createMessages_1.createMismatchingHashWarning)(request.metadata.hash, hash));
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
console.warn((0, createMessages_1.createMismatchingIdHashWarning)(request.metadata.id, request.metadata.hash, id, hash));
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
// set translation
|
|
238
|
-
newTranslations[request.metadata.id || request.metadata.hash] = (_a = {},
|
|
239
|
-
// id defaults to hash if none provided
|
|
240
|
-
_a[request.metadata.hash] = {
|
|
241
|
-
state: "success",
|
|
242
|
-
target: translation,
|
|
243
|
-
},
|
|
244
|
-
_a);
|
|
245
|
-
return;
|
|
105
|
+
const sendBatchRequest = (batchRequests) => __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
if (requestQueueRef.current.size === 0) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// increment active requests
|
|
110
|
+
setActiveRequests((prev) => prev + 1);
|
|
111
|
+
const requests = Array.from(batchRequests.values());
|
|
112
|
+
const newTranslations = {};
|
|
113
|
+
try {
|
|
114
|
+
// ----- TRANSLATION LOADING ----- //
|
|
115
|
+
const loadingTranslations = requests.reduce((acc, request) => {
|
|
116
|
+
// loading state for jsx, render loading behavior
|
|
117
|
+
const id = request.metadata.id || request.metadata.hash;
|
|
118
|
+
acc[id] = { [request.metadata.hash]: { state: "loading" } };
|
|
119
|
+
return acc;
|
|
120
|
+
}, {});
|
|
121
|
+
setTranslations((prev) => {
|
|
122
|
+
return Object.assign(Object.assign({}, (prev || {})), loadingTranslations);
|
|
123
|
+
});
|
|
124
|
+
// ----- RUNTIME TRANSLATION ----- //
|
|
125
|
+
const fetchWithAbort = (url, options, timeout) => __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
const controller = new AbortController();
|
|
127
|
+
const timeoutId = timeout === undefined
|
|
128
|
+
? undefined
|
|
129
|
+
: setTimeout(() => controller.abort(), timeout);
|
|
130
|
+
try {
|
|
131
|
+
return yield fetch(url, Object.assign(Object.assign({}, options), { signal: controller.signal }));
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error("timeout!");
|
|
135
|
+
if (error instanceof Error && error.name === "AbortError")
|
|
136
|
+
throw new Error("Request timed out"); // Handle the timeout case
|
|
137
|
+
throw error; // Re-throw other errors
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
if (timeoutId !== undefined)
|
|
141
|
+
clearTimeout(timeoutId); // Ensure timeout is cleared
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
const response = yield fetchWithAbort(`${runtimeUrl}/v1/runtime/${projectId}/client`, {
|
|
145
|
+
method: "POST",
|
|
146
|
+
headers: Object.assign({ "Content-Type": "application/json" }, (devApiKey && { "x-gt-dev-api-key": devApiKey })),
|
|
147
|
+
body: JSON.stringify({
|
|
148
|
+
requests,
|
|
149
|
+
targetLocale,
|
|
150
|
+
metadata,
|
|
151
|
+
}),
|
|
152
|
+
}, renderSettings.timeout);
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
throw new Error(yield response.text());
|
|
155
|
+
}
|
|
156
|
+
// ----- PARSE RESPONSE ----- //
|
|
157
|
+
const results = (yield response.json());
|
|
158
|
+
// don't send another req if one is already in flight
|
|
159
|
+
// process each result
|
|
160
|
+
results.forEach((result, index) => {
|
|
161
|
+
const request = requests[index];
|
|
162
|
+
// translation received
|
|
163
|
+
if ("translation" in result && result.translation && result.reference) {
|
|
164
|
+
const { translation, reference: { id, key: hash }, } = result;
|
|
165
|
+
// check for mismatching ids or hashes
|
|
166
|
+
if (id !== request.metadata.id || hash !== request.metadata.hash) {
|
|
167
|
+
if (!request.metadata.id) {
|
|
168
|
+
console.warn((0, createMessages_1.createMismatchingHashWarning)(request.metadata.hash, hash));
|
|
246
169
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
result.error !== null &&
|
|
250
|
-
result.code !== undefined &&
|
|
251
|
-
result.code !== null) {
|
|
252
|
-
// 0 and '' are falsey
|
|
253
|
-
// log error message
|
|
254
|
-
console.error((0, createMessages_1.createGenericRuntimeTranslationError)(request.metadata.id, request.metadata.hash), result.error);
|
|
255
|
-
// set error in translation object
|
|
256
|
-
newTranslations[request.metadata.id || request.metadata.hash] = (_b = {},
|
|
257
|
-
_b[request.metadata.hash] = {
|
|
258
|
-
state: "error",
|
|
259
|
-
error: result.error,
|
|
260
|
-
code: result.code,
|
|
261
|
-
},
|
|
262
|
-
_b);
|
|
263
|
-
return;
|
|
170
|
+
else {
|
|
171
|
+
console.warn((0, createMessages_1.createMismatchingIdHashWarning)(request.metadata.id, request.metadata.hash, id, hash));
|
|
264
172
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
_c[request.metadata.hash] = {
|
|
269
|
-
state: "error",
|
|
270
|
-
error: "An error occurred.",
|
|
271
|
-
code: 500,
|
|
272
|
-
},
|
|
273
|
-
_c);
|
|
274
|
-
});
|
|
275
|
-
return [3 /*break*/, 8];
|
|
276
|
-
case 6:
|
|
277
|
-
error_1 = _b.sent();
|
|
278
|
-
// log error
|
|
279
|
-
console.error(createMessages_1.dynamicTranslationError, error_1);
|
|
280
|
-
// add error message to all translations from this request
|
|
281
|
-
requests.forEach(function (request) {
|
|
282
|
-
var _a;
|
|
173
|
+
}
|
|
174
|
+
// set translation
|
|
175
|
+
newTranslations[request.metadata.id || request.metadata.hash] = {
|
|
283
176
|
// id defaults to hash if none provided
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
177
|
+
[request.metadata.hash]: {
|
|
178
|
+
state: "success",
|
|
179
|
+
target: translation,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
// translation failure
|
|
185
|
+
if (result.error !== undefined &&
|
|
186
|
+
result.error !== null &&
|
|
187
|
+
result.code !== undefined &&
|
|
188
|
+
result.code !== null) {
|
|
189
|
+
// 0 and '' are falsey
|
|
190
|
+
// log error message
|
|
191
|
+
console.error((0, createMessages_1.createGenericRuntimeTranslationError)(request.metadata.id, request.metadata.hash), result.error);
|
|
192
|
+
// set error in translation object
|
|
193
|
+
newTranslations[request.metadata.id || request.metadata.hash] = {
|
|
194
|
+
[request.metadata.hash]: {
|
|
195
|
+
state: "error",
|
|
196
|
+
error: result.error,
|
|
197
|
+
code: result.code,
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// unknown error
|
|
203
|
+
console.error((0, createMessages_1.createGenericRuntimeTranslationError)(request.metadata.id, request.metadata.hash), result);
|
|
204
|
+
newTranslations[request.metadata.id || request.metadata.hash] = {
|
|
205
|
+
[request.metadata.hash]: {
|
|
206
|
+
state: "error",
|
|
207
|
+
error: "An error occurred.",
|
|
208
|
+
code: 500,
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
// log error
|
|
215
|
+
console.error(createMessages_1.dynamicTranslationError, error);
|
|
216
|
+
// add error message to all translations from this request
|
|
217
|
+
requests.forEach((request) => {
|
|
218
|
+
// id defaults to hash if none provided
|
|
219
|
+
newTranslations[request.metadata.id || request.metadata.hash] = {
|
|
220
|
+
[request.metadata.hash]: {
|
|
221
|
+
state: "error",
|
|
222
|
+
error: "An error occurred.",
|
|
223
|
+
code: 500,
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
finally {
|
|
229
|
+
// update our translations
|
|
230
|
+
setTranslations((prev) => {
|
|
231
|
+
return Object.assign(Object.assign({}, (prev || {})), newTranslations);
|
|
232
|
+
});
|
|
233
|
+
// decrement active requests
|
|
234
|
+
setActiveRequests((prev) => prev - 1);
|
|
235
|
+
// resolve all promises
|
|
236
|
+
requests.forEach((request) => request.resolve());
|
|
237
|
+
}
|
|
238
|
+
});
|
|
307
239
|
// Try to send a batch request every `batchInterval` ms
|
|
308
|
-
|
|
309
|
-
setInterval(
|
|
240
|
+
const startBatching = () => {
|
|
241
|
+
setInterval(() => {
|
|
310
242
|
if (requestQueueRef.current.size > 0 &&
|
|
311
243
|
activeRequests < defaultProps_1.maxConcurrentRequests) {
|
|
312
|
-
|
|
313
|
-
|
|
244
|
+
const batchSize = Math.min(defaultProps_1.maxBatchSize, requestQueueRef.current.size);
|
|
245
|
+
const batchRequests = new Map(Array.from(requestQueueRef.current.entries()).slice(0, batchSize));
|
|
314
246
|
sendBatchRequest(batchRequests);
|
|
315
|
-
batchRequests.forEach(
|
|
247
|
+
batchRequests.forEach((_, key) => requestQueueRef.current.delete(key));
|
|
316
248
|
}
|
|
317
249
|
}, defaultProps_1.batchInterval);
|
|
318
250
|
};
|
|
319
251
|
startBatching();
|
|
320
|
-
return { translateContent
|
|
252
|
+
return { translateContent, translateChildren, translationEnabled };
|
|
321
253
|
}
|
|
322
254
|
//# sourceMappingURL=useRuntimeTranslation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRuntimeTranslation.js","sourceRoot":"","sources":["../../../src/provider/runtime/useRuntimeTranslation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRuntimeTranslation.js","sourceRoot":"","sources":["../../../src/provider/runtime/useRuntimeTranslation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgBA,wCA4VC;AA5WD,iCAAsE;AACtE,kEAKuC;AAQvC,yDAA4F;AAE5F,SAAwB,qBAAqB,CAAC,EAqB7C;QArB6C,EAC5C,YAAY,EACZ,SAAS,EACT,SAAS,EACT,UAAU,EACV,aAAa,EACb,cAAc,EACd,eAAe,OAchB,EAbI,QAAQ,cARiC,8GAS7C,CADY;IAkBX,QAAQ,mCAAQ,QAAQ,KAAE,SAAS,EAAE,YAAY,EAAE,aAAa,GAAE,CAAC;IAEnE,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAAA,gBAAQ,EAAC,CAAC,CAAC,CAAC;IACtD,MAAM,CAAC,sBAAsB,EAAE,yBAAyB,CAAC,GAAG,IAAA,gBAAQ,EAAC,CAAC,CAAC,CAAC;IACxE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAA,gBAAQ,EAAC,IAAI,GAAG,EAAe,CAAC,CAAC;IAErE,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,EAAC,CAAC,CAAC,CAAC;IAExD,MAAM,kBAAkB,GAAG,CAAC,CAAC,CAAC,UAAU,IAAI,SAAS,CAAC,CAAC;IACvD,IAAI,CAAC,kBAAkB;QACrB,OAAO;YACL,kBAAkB;YAClB,gBAAgB,EAAE,GAAG,EAAE,CACrB,OAAO,CAAC,MAAM,CACZ,IAAI,KAAK,CAAC,2DAA2D,CAAC,CACvE;YACH,iBAAiB,EAAE,GAAG,EAAE,CACtB,OAAO,CAAC,MAAM,CACZ,IAAI,KAAK,CACP,4DAA4D,CAC7D,CACF;S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AC;IACF,aAAa,EAAE,CAAC;IAEhB,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC;AACrE,CAAC"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { ReactElement } from
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
2
|
export type Child = React.ReactNode;
|
|
3
3
|
export type Children = Child[] | Child;
|
|
4
4
|
export type GTProp = {
|
|
@@ -9,9 +9,17 @@ export type GTProp = {
|
|
|
9
9
|
export type TaggedChild = React.ReactNode | TaggedElement;
|
|
10
10
|
export type TaggedChildren = TaggedChild[] | TaggedChild;
|
|
11
11
|
export type TaggedElementProps = Record<string, any> & {
|
|
12
|
-
|
|
12
|
+
'data-_gt': GTProp;
|
|
13
13
|
};
|
|
14
14
|
export type TaggedElement = React.ReactElement<TaggedElementProps>;
|
|
15
|
+
export type TaggedEntry = string | TaggedChildren;
|
|
16
|
+
export type TaggedDictionaryEntry = TaggedEntry | [TaggedEntry] | [TaggedEntry, Metadata];
|
|
17
|
+
export type TaggedDictionary = {
|
|
18
|
+
[key: string]: TaggedDictionary | TaggedDictionaryEntry;
|
|
19
|
+
};
|
|
20
|
+
export type FlattenedTaggedDictionary = {
|
|
21
|
+
[key: string]: TaggedDictionaryEntry;
|
|
22
|
+
};
|
|
15
23
|
export type Entry = string | ReactElement;
|
|
16
24
|
export type Metadata = {
|
|
17
25
|
singular?: Entry;
|
|
@@ -37,12 +45,12 @@ export type FlattenedDictionary = {
|
|
|
37
45
|
export type Variable = {
|
|
38
46
|
key: string;
|
|
39
47
|
id?: number;
|
|
40
|
-
variable?:
|
|
48
|
+
variable?: 'variable' | 'number' | 'datetime' | 'currency';
|
|
41
49
|
};
|
|
42
50
|
export type TranslatedElement = {
|
|
43
51
|
type: string;
|
|
44
52
|
props: {
|
|
45
|
-
|
|
53
|
+
'data-_gt': {
|
|
46
54
|
id: number;
|
|
47
55
|
[key: string]: any;
|
|
48
56
|
};
|
|
@@ -53,23 +61,23 @@ export type TranslatedChild = TranslatedElement | string | Variable;
|
|
|
53
61
|
export type TranslatedChildren = TranslatedChild | TranslatedChild[];
|
|
54
62
|
export type TranslatedContent = string | (string | Variable)[];
|
|
55
63
|
export type TranslationError = {
|
|
56
|
-
state:
|
|
64
|
+
state: 'error';
|
|
57
65
|
error: string;
|
|
58
66
|
code?: number;
|
|
59
67
|
};
|
|
60
68
|
export type TranslationSuccess = {
|
|
61
|
-
state:
|
|
69
|
+
state: 'success';
|
|
62
70
|
target: TranslatedChildren | TranslatedContent;
|
|
63
71
|
};
|
|
64
72
|
export type TranslationLoading = {
|
|
65
|
-
state:
|
|
73
|
+
state: 'loading';
|
|
66
74
|
};
|
|
67
75
|
export type TranslationsObject = {
|
|
68
76
|
[id: string]: {
|
|
69
77
|
[hash: string]: TranslationSuccess | TranslationLoading | TranslationError;
|
|
70
78
|
};
|
|
71
79
|
};
|
|
72
|
-
export type RenderMethod =
|
|
80
|
+
export type RenderMethod = 'skeleton' | 'replace' | 'default';
|
|
73
81
|
export type TranslateContentCallback = (params: {
|
|
74
82
|
source: any;
|
|
75
83
|
targetLocale: string;
|
|
@@ -102,4 +110,10 @@ export type GTContextType = {
|
|
|
102
110
|
projectId?: string;
|
|
103
111
|
translationEnabled?: boolean;
|
|
104
112
|
};
|
|
113
|
+
export declare class GTTranslationError extends Error {
|
|
114
|
+
error: string;
|
|
115
|
+
code: number;
|
|
116
|
+
constructor(error: string, code: number);
|
|
117
|
+
toTranslationError(): TranslationError;
|
|
118
|
+
}
|
|
105
119
|
//# sourceMappingURL=types.d.ts.map
|