gt-react 8.2.19 → 8.2.21
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/dist/branches/Branch.d.ts.map +1 -1
- package/dist/branches/Branch.js.map +1 -1
- package/dist/branches/plurals/getPluralBranch.d.ts.map +1 -1
- package/dist/branches/plurals/getPluralBranch.js +2 -2
- package/dist/branches/plurals/getPluralBranch.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/hooks/useBrowserLocale.d.ts.map +1 -1
- package/dist/hooks/useBrowserLocale.js +2 -2
- package/dist/hooks/useBrowserLocale.js.map +1 -1
- package/dist/hooks/useDefaultLocale.js.map +1 -1
- package/dist/hooks/useGT.d.ts.map +1 -1
- package/dist/hooks/useGT.js.map +1 -1
- package/dist/hooks/useLocale.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/inline/T.d.ts.map +1 -1
- package/dist/inline/T.js +2 -10
- package/dist/inline/T.js.map +1 -1
- package/dist/internal/addGTIdentifier.d.ts +1 -1
- package/dist/internal/addGTIdentifier.d.ts.map +1 -1
- package/dist/internal/addGTIdentifier.js +7 -7
- package/dist/internal/addGTIdentifier.js.map +1 -1
- package/dist/internal/flattenDictionary.d.ts.map +1 -1
- package/dist/internal/flattenDictionary.js +8 -6
- package/dist/internal/flattenDictionary.js.map +1 -1
- package/dist/internal/writeChildrenAsObjects.d.ts +3 -3
- package/dist/internal/writeChildrenAsObjects.d.ts.map +1 -1
- package/dist/internal/writeChildrenAsObjects.js +23 -20
- package/dist/internal/writeChildrenAsObjects.js.map +1 -1
- package/dist/internal.d.ts +3 -3
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/messages/createMessages.d.ts.map +1 -1
- package/dist/messages/createMessages.js +36 -14
- package/dist/messages/createMessages.js.map +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.map +1 -1
- package/dist/provider/GTProvider.js +30 -15
- package/dist/provider/GTProvider.js.map +1 -1
- package/dist/provider/config/defaultProps.d.ts +4 -0
- package/dist/provider/config/defaultProps.d.ts.map +1 -0
- package/dist/provider/config/defaultProps.js +7 -0
- package/dist/provider/config/defaultProps.js.map +1 -0
- package/dist/provider/helpers/extractEntryMetadata.d.ts.map +1 -1
- package/dist/provider/helpers/extractEntryMetadata.js.map +1 -1
- package/dist/provider/helpers/getDictionaryEntry.d.ts.map +1 -1
- package/dist/provider/helpers/getDictionaryEntry.js +3 -1
- package/dist/provider/helpers/getDictionaryEntry.js.map +1 -1
- package/dist/provider/helpers/getGTProp.d.ts.map +1 -1
- package/dist/provider/helpers/getGTProp.js +2 -2
- package/dist/provider/helpers/getGTProp.js.map +1 -1
- package/dist/provider/helpers/isValidDictionaryEntry.d.ts.map +1 -1
- package/dist/provider/helpers/isVariableObject.d.ts.map +1 -1
- package/dist/provider/helpers/isVariableObject.js +7 -5
- package/dist/provider/helpers/isVariableObject.js.map +1 -1
- package/dist/provider/rendering/defaultRenderSettings.js +2 -2
- package/dist/provider/rendering/defaultRenderSettings.js.map +1 -1
- package/dist/provider/rendering/renderDefaultChildren.d.ts +2 -2
- package/dist/provider/rendering/renderDefaultChildren.d.ts.map +1 -1
- package/dist/provider/rendering/renderDefaultChildren.js +20 -15
- package/dist/provider/rendering/renderDefaultChildren.js.map +1 -1
- package/dist/provider/rendering/renderSkeleton.d.ts +4 -19
- package/dist/provider/rendering/renderSkeleton.d.ts.map +1 -1
- package/dist/provider/rendering/renderSkeleton.js +4 -90
- package/dist/provider/rendering/renderSkeleton.js.map +1 -1
- package/dist/provider/rendering/renderTranslatedChildren.d.ts +2 -2
- package/dist/provider/rendering/renderTranslatedChildren.d.ts.map +1 -1
- package/dist/provider/rendering/renderTranslatedChildren.js +71 -42
- package/dist/provider/rendering/renderTranslatedChildren.js.map +1 -1
- package/dist/provider/rendering/renderVariable.d.ts +1 -1
- package/dist/provider/rendering/renderVariable.d.ts.map +1 -1
- package/dist/provider/rendering/renderVariable.js +1 -1
- package/dist/provider/rendering/renderVariable.js.map +1 -1
- package/dist/provider/runtime/useRuntimeTranslation.d.ts.map +1 -1
- package/dist/provider/runtime/useRuntimeTranslation.js +226 -159
- package/dist/provider/runtime/useRuntimeTranslation.js.map +1 -1
- package/dist/types/types.d.ts +6 -6
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +5 -5
- package/dist/utils/utils.js.map +1 -1
- package/dist/variables/Currency.d.ts +1 -1
- package/dist/variables/Currency.d.ts.map +1 -1
- package/dist/variables/Currency.js +15 -6
- package/dist/variables/Currency.js.map +1 -1
- package/dist/variables/DateTime.d.ts +1 -1
- package/dist/variables/DateTime.d.ts.map +1 -1
- package/dist/variables/DateTime.js +8 -7
- package/dist/variables/DateTime.js.map +1 -1
- package/dist/variables/Num.d.ts +1 -1
- package/dist/variables/Num.d.ts.map +1 -1
- package/dist/variables/Num.js +7 -5
- package/dist/variables/Num.js.map +1 -1
- package/dist/variables/Var.d.ts +1 -1
- package/dist/variables/Var.d.ts.map +1 -1
- package/dist/variables/Var.js +2 -3
- package/dist/variables/Var.js.map +1 -1
- package/dist/variables/_getVariableProps.d.ts +1 -1
- package/dist/variables/_getVariableProps.d.ts.map +1 -1
- package/dist/variables/_getVariableProps.js +9 -9
- package/dist/variables/_getVariableProps.js.map +1 -1
- package/dist/variables/getVariableName.d.ts.map +1 -1
- package/dist/variables/getVariableName.js +7 -7
- package/dist/variables/getVariableName.js.map +1 -1
- package/package.json +1 -1
|
@@ -61,195 +61,262 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
61
61
|
exports.default = useRuntimeTranslation;
|
|
62
62
|
var react_1 = require("react");
|
|
63
63
|
var createMessages_1 = require("../../messages/createMessages");
|
|
64
|
+
var defaultProps_1 = require("../config/defaultProps");
|
|
64
65
|
function useRuntimeTranslation(_a) {
|
|
65
66
|
var _this = this;
|
|
66
67
|
var targetLocale = _a.targetLocale, projectId = _a.projectId, devApiKey = _a.devApiKey, runtimeUrl = _a.runtimeUrl, defaultLocale = _a.defaultLocale, renderSettings = _a.renderSettings, setTranslations = _a.setTranslations, metadata = __rest(_a, ["targetLocale", "projectId", "devApiKey", "runtimeUrl", "defaultLocale", "renderSettings", "setTranslations"]);
|
|
67
68
|
metadata = __assign(__assign({}, metadata), { projectId: projectId, sourceLocale: defaultLocale });
|
|
69
|
+
var _b = (0, react_1.useState)(0), inflightCount = _b[0], setInflightCount = _b[1];
|
|
70
|
+
var _c = (0, react_1.useState)(0), conccurentRequestCount = _c[0], setConcurrentRequestCount = _c[1];
|
|
71
|
+
var _d = (0, react_1.useState)(new Map()), requestMap = _d[0], setRequestMap = _d[1];
|
|
72
|
+
var _e = (0, react_1.useState)(0), activeRequests = _e[0], setActiveRequests = _e[1];
|
|
68
73
|
var translationEnabled = !!(runtimeUrl && projectId);
|
|
69
74
|
if (!translationEnabled)
|
|
70
75
|
return {
|
|
71
76
|
translationEnabled: translationEnabled,
|
|
72
|
-
translateContent: function () {
|
|
73
|
-
|
|
77
|
+
translateContent: function () {
|
|
78
|
+
return Promise.reject(new Error("translateContent() failed because translation is disabled"));
|
|
79
|
+
},
|
|
80
|
+
translateChildren: function () {
|
|
81
|
+
return Promise.reject(new Error("translateChildren() failed because translation is disabled"));
|
|
82
|
+
},
|
|
74
83
|
};
|
|
84
|
+
// Requests waiting to be sent (not yet batched)
|
|
75
85
|
var requestQueueRef = (0, react_1.useRef)(new Map());
|
|
76
|
-
//
|
|
77
|
-
var
|
|
86
|
+
// Requests that have yet to be resolved
|
|
87
|
+
var pendingRequestQueueRef = (0, react_1.useRef)(new Map());
|
|
78
88
|
var translateContent = (0, react_1.useCallback)(function (params) {
|
|
79
|
-
|
|
89
|
+
// get the key
|
|
90
|
+
var id = params.metadata.id ? "".concat(params.metadata.id, "-") : "";
|
|
80
91
|
var key = "".concat(id, "-").concat(params.metadata.hash, "-").concat(params.targetLocale);
|
|
81
|
-
|
|
92
|
+
// return a promise to current request if it exists
|
|
93
|
+
var inflightRequest = pendingRequestQueueRef.current.get(key);
|
|
94
|
+
if (inflightRequest) {
|
|
95
|
+
return inflightRequest;
|
|
96
|
+
}
|
|
82
97
|
// promise for hooking into the translation request request to know when complete
|
|
83
|
-
|
|
84
|
-
requestQueueRef.current.set(key, {
|
|
98
|
+
var translationPromise = new Promise(function (resolve, reject) {
|
|
99
|
+
requestQueueRef.current.set(key, {
|
|
100
|
+
type: "content",
|
|
101
|
+
source: params.source,
|
|
102
|
+
metadata: params.metadata,
|
|
103
|
+
resolve: resolve,
|
|
104
|
+
reject: reject,
|
|
105
|
+
});
|
|
106
|
+
})
|
|
107
|
+
.catch(function (error) {
|
|
108
|
+
throw error;
|
|
109
|
+
})
|
|
110
|
+
.finally(function () {
|
|
111
|
+
pendingRequestQueueRef.current.delete(key);
|
|
85
112
|
});
|
|
113
|
+
return translationPromise;
|
|
86
114
|
}, []);
|
|
87
115
|
/**
|
|
88
116
|
* Call this from <T> components to request a translation key.
|
|
89
117
|
* Keys are batched and fetched in the next effect cycle.
|
|
90
118
|
*/
|
|
91
119
|
var translateChildren = (0, react_1.useCallback)(function (params) {
|
|
92
|
-
|
|
120
|
+
// get the key
|
|
121
|
+
var id = params.metadata.id ? "".concat(params.metadata.id, "-") : "";
|
|
93
122
|
var key = "".concat(id, "-").concat(params.metadata.hash, "-").concat(params.targetLocale);
|
|
94
|
-
|
|
123
|
+
// return a promise to current request if it exists
|
|
124
|
+
var inflightRequest = pendingRequestQueueRef.current.get(key);
|
|
125
|
+
if (inflightRequest) {
|
|
126
|
+
return inflightRequest;
|
|
127
|
+
}
|
|
95
128
|
// promise for hooking into the translation request to know when complete
|
|
96
|
-
|
|
97
|
-
requestQueueRef.current.set(key, {
|
|
129
|
+
var translationPromise = new Promise(function (resolve, reject) {
|
|
130
|
+
requestQueueRef.current.set(key, {
|
|
131
|
+
type: "jsx",
|
|
132
|
+
source: params.source,
|
|
133
|
+
metadata: params.metadata,
|
|
134
|
+
resolve: resolve,
|
|
135
|
+
reject: reject,
|
|
136
|
+
});
|
|
137
|
+
})
|
|
138
|
+
.catch(function (error) {
|
|
139
|
+
throw error;
|
|
140
|
+
})
|
|
141
|
+
.finally(function () {
|
|
142
|
+
pendingRequestQueueRef.current.delete(key);
|
|
98
143
|
});
|
|
144
|
+
return translationPromise;
|
|
99
145
|
}, []);
|
|
100
|
-
(0, react_1.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
var
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}, {});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
newTranslations[request.metadata.id || request.metadata.hash] = (_a = {},
|
|
187
|
-
_a[request.metadata.hash] = {
|
|
188
|
-
state: 'success',
|
|
189
|
-
target: translation
|
|
190
|
-
},
|
|
191
|
-
_a);
|
|
192
|
-
return;
|
|
146
|
+
var _f = (0, react_1.useState)(0), count = _f[0], setCount = _f[1];
|
|
147
|
+
// Send a request to the runtime server
|
|
148
|
+
var sendBatchRequest = function (batchRequests) { return __awaiter(_this, void 0, void 0, function () {
|
|
149
|
+
var requests, newTranslations, loadingTranslations_1, fetchWithAbort, response, _a, results, error_1;
|
|
150
|
+
var _this = this;
|
|
151
|
+
return __generator(this, function (_b) {
|
|
152
|
+
switch (_b.label) {
|
|
153
|
+
case 0:
|
|
154
|
+
if (requestQueueRef.current.size === 0) {
|
|
155
|
+
return [2 /*return*/];
|
|
156
|
+
}
|
|
157
|
+
// increment active requests
|
|
158
|
+
setActiveRequests(function (prev) { return prev + 1; });
|
|
159
|
+
requests = Array.from(batchRequests.values());
|
|
160
|
+
newTranslations = {};
|
|
161
|
+
_b.label = 1;
|
|
162
|
+
case 1:
|
|
163
|
+
_b.trys.push([1, 6, 7, 8]);
|
|
164
|
+
loadingTranslations_1 = requests.reduce(function (acc, request) {
|
|
165
|
+
var _a;
|
|
166
|
+
// loading state for jsx, render loading behavior
|
|
167
|
+
var id = request.metadata.id || request.metadata.hash;
|
|
168
|
+
acc[id] = (_a = {}, _a[request.metadata.hash] = { state: "loading" }, _a);
|
|
169
|
+
return acc;
|
|
170
|
+
}, {});
|
|
171
|
+
setTranslations(function (prev) {
|
|
172
|
+
return __assign(__assign({}, (prev || {})), loadingTranslations_1);
|
|
173
|
+
});
|
|
174
|
+
fetchWithAbort = function (url, options, timeout) { return __awaiter(_this, void 0, void 0, function () {
|
|
175
|
+
var controller, timeoutId, error_2;
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
switch (_a.label) {
|
|
178
|
+
case 0:
|
|
179
|
+
controller = new AbortController();
|
|
180
|
+
timeoutId = timeout === undefined
|
|
181
|
+
? undefined
|
|
182
|
+
: setTimeout(function () { return controller.abort(); }, timeout);
|
|
183
|
+
_a.label = 1;
|
|
184
|
+
case 1:
|
|
185
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
186
|
+
return [4 /*yield*/, fetch(url, __assign(__assign({}, options), { signal: controller.signal }))];
|
|
187
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
188
|
+
case 3:
|
|
189
|
+
error_2 = _a.sent();
|
|
190
|
+
console.error("timeout!");
|
|
191
|
+
if (error_2 instanceof Error && error_2.name === "AbortError")
|
|
192
|
+
throw new Error("Request timed out"); // Handle the timeout case
|
|
193
|
+
throw error_2; // Re-throw other errors
|
|
194
|
+
case 4:
|
|
195
|
+
if (timeoutId !== undefined)
|
|
196
|
+
clearTimeout(timeoutId); // Ensure timeout is cleared
|
|
197
|
+
return [7 /*endfinally*/];
|
|
198
|
+
case 5: return [2 /*return*/];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}); };
|
|
202
|
+
return [4 /*yield*/, fetchWithAbort("".concat(runtimeUrl, "/v1/runtime/").concat(projectId, "/client"), {
|
|
203
|
+
method: "POST",
|
|
204
|
+
headers: __assign({ "Content-Type": "application/json" }, (devApiKey && { "x-gt-dev-api-key": devApiKey })),
|
|
205
|
+
body: JSON.stringify({
|
|
206
|
+
requests: requests,
|
|
207
|
+
targetLocale: targetLocale,
|
|
208
|
+
metadata: metadata,
|
|
209
|
+
}),
|
|
210
|
+
}, renderSettings.timeout)];
|
|
211
|
+
case 2:
|
|
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));
|
|
193
232
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
// log error message
|
|
197
|
-
console.error((0, createMessages_1.createGenericRuntimeTranslationError)(request.metadata.id, request.metadata.hash), result.error);
|
|
198
|
-
// set error in translation object
|
|
199
|
-
newTranslations[request.metadata.id || request.metadata.hash] = (_b = {},
|
|
200
|
-
_b[request.metadata.hash] = {
|
|
201
|
-
state: 'error',
|
|
202
|
-
error: result.error,
|
|
203
|
-
code: result.code
|
|
204
|
-
},
|
|
205
|
-
_b);
|
|
206
|
-
return;
|
|
233
|
+
else {
|
|
234
|
+
console.warn((0, createMessages_1.createMismatchingIdHashWarning)(request.metadata.id, request.metadata.hash, id, hash));
|
|
207
235
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
newTranslations[request.metadata.id || request.metadata.hash] = (_c = {},
|
|
211
|
-
_c[request.metadata.hash] = {
|
|
212
|
-
state: 'error',
|
|
213
|
-
error: "An error occurred.",
|
|
214
|
-
code: 500
|
|
215
|
-
},
|
|
216
|
-
_c);
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
return [3 /*break*/, 8];
|
|
220
|
-
case 6:
|
|
221
|
-
error_1 = _b.sent();
|
|
222
|
-
// log error
|
|
223
|
-
console.error(createMessages_1.dynamicTranslationError, error_1);
|
|
224
|
-
// add error message to all translations from this request
|
|
225
|
-
requests.forEach(function (request) {
|
|
226
|
-
var _a;
|
|
227
|
-
// id defaults to hash if none provided
|
|
236
|
+
}
|
|
237
|
+
// set translation
|
|
228
238
|
newTranslations[request.metadata.id || request.metadata.hash] = (_a = {},
|
|
239
|
+
// id defaults to hash if none provided
|
|
229
240
|
_a[request.metadata.hash] = {
|
|
230
|
-
state:
|
|
231
|
-
|
|
232
|
-
code: 500
|
|
241
|
+
state: "success",
|
|
242
|
+
target: translation,
|
|
233
243
|
},
|
|
234
244
|
_a);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
// translation failure
|
|
248
|
+
if (result.error !== undefined &&
|
|
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;
|
|
264
|
+
}
|
|
265
|
+
// unknown error
|
|
266
|
+
console.error((0, createMessages_1.createGenericRuntimeTranslationError)(request.metadata.id, request.metadata.hash), result);
|
|
267
|
+
newTranslations[request.metadata.id || request.metadata.hash] = (_c = {},
|
|
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;
|
|
283
|
+
// id defaults to hash if none provided
|
|
284
|
+
newTranslations[request.metadata.id || request.metadata.hash] = (_a = {},
|
|
285
|
+
_a[request.metadata.hash] = {
|
|
286
|
+
state: "error",
|
|
287
|
+
error: "An error occurred.",
|
|
288
|
+
code: 500,
|
|
289
|
+
},
|
|
290
|
+
_a);
|
|
291
|
+
});
|
|
292
|
+
return [3 /*break*/, 8];
|
|
293
|
+
case 7:
|
|
294
|
+
// update our translations
|
|
295
|
+
setTranslations(function (prev) {
|
|
296
|
+
return __assign(__assign({}, (prev || {})), newTranslations);
|
|
297
|
+
});
|
|
298
|
+
// decrement active requests
|
|
299
|
+
setActiveRequests(function (prev) { return prev - 1; });
|
|
300
|
+
// resolve all promises
|
|
301
|
+
requests.forEach(function (request) { return request.resolve(); });
|
|
302
|
+
return [7 /*endfinally*/];
|
|
303
|
+
case 8: return [2 /*return*/];
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}); };
|
|
307
|
+
// Try to send a batch request every `batchInterval` ms
|
|
308
|
+
var startBatching = function () {
|
|
309
|
+
setInterval(function () {
|
|
310
|
+
if (requestQueueRef.current.size > 0 &&
|
|
311
|
+
activeRequests < defaultProps_1.maxConcurrentRequests) {
|
|
312
|
+
var batchSize = Math.min(defaultProps_1.maxBatchSize, requestQueueRef.current.size);
|
|
313
|
+
var batchRequests = new Map(Array.from(requestQueueRef.current.entries()).slice(0, batchSize));
|
|
314
|
+
sendBatchRequest(batchRequests);
|
|
315
|
+
batchRequests.forEach(function (_, key) { return requestQueueRef.current.delete(key); });
|
|
316
|
+
}
|
|
317
|
+
}, defaultProps_1.batchInterval);
|
|
318
|
+
};
|
|
319
|
+
startBatching();
|
|
253
320
|
return { translateContent: translateContent, translateChildren: translateChildren, translationEnabled: translationEnabled };
|
|
254
321
|
}
|
|
255
322
|
//# 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,+BAAsE;AACtE,gEAKuC;AAQvC,uDAA4F;AAE5F,SAAwB,qBAAqB,CAAC,EAqB7C;IArBD,iBA4VC;IA3VC,IAAA,YAAY,kBAAA,EACZ,SAAS,eAAA,EACT,SAAS,eAAA,EACT,UAAU,gBAAA,EACV,aAAa,mBAAA,EACb,cAAc,oBAAA,EACd,eAAe,qBAAA,EACZ,QAAQ,cARiC,8GAS7C,CADY;IAkBX,QAAQ,yBAAQ,QAAQ,KAAE,SAAS,WAAA,EAAE,YAAY,EAAE,aAAa,GAAE,CAAC;IAE7D,IAAA,KAAoC,IAAA,gBAAQ,EAAC,CAAC,CAAC,EAA9C,aAAa,QAAA,EAAE,gBAAgB,QAAe,CAAC;IAChD,I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AO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAClE,CAAC;gBACF,gBAAgB,CAAC,aAAa,CAAC,CAAC;gBAChC,aAAa,CAAC,OAAO,CAAC,UAAC,CAAC,EAAE,GAAG,IAAK,OAAA,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAnC,CAAmC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC,EAAE,4BAAa,CAAC,CAAC;IACpB,CAAC,CAAC;IACF,aAAa,EAAE,CAAC;IAEhB,OAAO,EAAE,gBAAgB,kBAAA,EAAE,iBAAiB,mBAAA,EAAE,kBAAkB,oBAAA,EAAE,CAAC;AACrE,CAAC"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ 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
15
|
export type Entry = string | ReactElement;
|
|
@@ -42,7 +42,7 @@ export type Variable = {
|
|
|
42
42
|
export type TranslatedElement = {
|
|
43
43
|
type: string;
|
|
44
44
|
props: {
|
|
45
|
-
|
|
45
|
+
"data-_gt": {
|
|
46
46
|
id: number;
|
|
47
47
|
[key: string]: any;
|
|
48
48
|
};
|
|
@@ -53,23 +53,23 @@ export type TranslatedChild = TranslatedElement | string | Variable;
|
|
|
53
53
|
export type TranslatedChildren = TranslatedChild | TranslatedChild[];
|
|
54
54
|
export type TranslatedContent = string | (string | Variable)[];
|
|
55
55
|
export type TranslationError = {
|
|
56
|
-
state:
|
|
56
|
+
state: "error";
|
|
57
57
|
error: string;
|
|
58
58
|
code?: number;
|
|
59
59
|
};
|
|
60
60
|
export type TranslationSuccess = {
|
|
61
|
-
state:
|
|
61
|
+
state: "success";
|
|
62
62
|
target: TranslatedChildren | TranslatedContent;
|
|
63
63
|
};
|
|
64
64
|
export type TranslationLoading = {
|
|
65
|
-
state:
|
|
65
|
+
state: "loading";
|
|
66
66
|
};
|
|
67
67
|
export type TranslationsObject = {
|
|
68
68
|
[id: string]: {
|
|
69
69
|
[hash: string]: TranslationSuccess | TranslationLoading | TranslationError;
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
|
-
export type RenderMethod =
|
|
72
|
+
export type RenderMethod = "skeleton" | "replace" | "default";
|
|
73
73
|
export type TranslateContentCallback = (params: {
|
|
74
74
|
source: any;
|
|
75
75
|
targetLocale: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,YAAY,EAAE,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC;AACpC,MAAM,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;AACvC,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAExB,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,GAAG,aAAa,CAAC;AAC1D,MAAM,MAAM,cAAc,GAAG,WAAW,EAAE,GAAG,WAAW,CAAC;AACzD,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,UAAU,E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AK,OAAO,CAAC,IAAI,CAAC,CAAC;AACpB,MAAM,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE;IAC/C,MAAM,EAAE,GAAG,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEpB,MAAM,MAAM,aAAa,GAAG;IAC1B,wBAAwB,EAAE,CACxB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC1B,KAAK,CAAC,SAAS,CAAC;IACrB,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,iBAAiB,EAAE,yBAAyB,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,0BAA0B,EAAE,OAAO,CAAC;IACpC,cAAc,EAAE;QAAE,MAAM,EAAE,YAAY,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,aAAa,EAEb,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAExB,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,iBAAiB,CAuB7B;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,aAAa,CAE7E;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,KAAK,CAAC,YAAY,CAM9B"}
|
package/dist/utils/utils.js
CHANGED
|
@@ -8,19 +8,19 @@ exports.isValidTaggedElement = isValidTaggedElement;
|
|
|
8
8
|
exports.isEmptyReactFragment = isEmptyReactFragment;
|
|
9
9
|
var react_1 = __importDefault(require("react"));
|
|
10
10
|
function isTranslatedContent(target) {
|
|
11
|
-
if (typeof target ===
|
|
11
|
+
if (typeof target === "string") {
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
14
14
|
if (!Array.isArray(target)) {
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
17
|
return target.every(function (item) {
|
|
18
|
-
if (typeof item ===
|
|
18
|
+
if (typeof item === "string") {
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
|
-
if (typeof item ===
|
|
22
|
-
var hasKey =
|
|
23
|
-
var hasValidVariable = item.variable === undefined || typeof item.variable ===
|
|
21
|
+
if (typeof item === "object" && item !== null) {
|
|
22
|
+
var hasKey = "key" in item && typeof item.key === "string";
|
|
23
|
+
var hasValidVariable = item.variable === undefined || typeof item.variable === "string";
|
|
24
24
|
return hasKey && hasValidVariable;
|
|
25
25
|
}
|
|
26
26
|
return false;
|
package/dist/utils/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.tsx"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.tsx"],"names":[],"mappings":";;;;;AAOA,kDAyBC;AAED,oDAEC;AAED,oDAQC;AA9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 @@ import React from "react";
|
|
|
20
20
|
* @param {Intl.NumberFormatOptions} [options] - Optional formatting options to customize how the currency is displayed.
|
|
21
21
|
* @returns {JSX.Element} The formatted currency component.
|
|
22
22
|
*/
|
|
23
|
-
declare function Currency({ children, value, name, currency, locales, options }: {
|
|
23
|
+
declare function Currency({ children, value, name, currency, locales, options, }: {
|
|
24
24
|
children?: any;
|
|
25
25
|
name?: string;
|
|
26
26
|
value?: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Currency.d.ts","sourceRoot":"","sources":["../../src/variables/Currency.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"Currency.d.ts","sourceRoot":"","sources":["../../src/variables/Currency.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,QAAQ,CAAC,EAChB,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,QAAgB,EAChB,OAAO,EACP,OAAY,GACb,EAAE;IACD,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;CACpC,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAqCpB;kBAnDQ,QAAQ;;;AAwDjB,eAAe,QAAQ,CAAC"}
|