gt-next 1.3.15 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +14 -0
- package/dist/config/I18NConfiguration.d.ts +28 -18
- package/dist/config/I18NConfiguration.d.ts.map +1 -1
- package/dist/config/I18NConfiguration.js +109 -41
- package/dist/config/I18NConfiguration.js.map +1 -1
- package/dist/config/RemoteTranslationsManager.d.ts +2 -8
- package/dist/config/RemoteTranslationsManager.d.ts.map +1 -1
- package/dist/config/RemoteTranslationsManager.js +10 -18
- package/dist/config/RemoteTranslationsManager.js.map +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -5
- package/dist/config.js.map +1 -1
- package/dist/index.server.d.ts +2 -2
- package/dist/index.server.d.ts.map +1 -1
- package/dist/index.server.js +4 -3
- package/dist/index.server.js.map +1 -1
- package/dist/middleware/createNextMiddleware.d.ts +3 -2
- package/dist/middleware/createNextMiddleware.d.ts.map +1 -1
- package/dist/middleware/createNextMiddleware.js +41 -55
- package/dist/middleware/createNextMiddleware.js.map +1 -1
- package/dist/next/getNextLocale.d.ts.map +1 -1
- package/dist/next/getNextLocale.js +30 -17
- package/dist/next/getNextLocale.js.map +1 -1
- package/dist/primitives/defaultInitGTProps.js +4 -4
- package/dist/primitives/defaultInitGTProps.js.map +1 -1
- package/dist/provider/ClientProvider.d.ts +4 -3
- package/dist/provider/ClientProvider.d.ts.map +1 -1
- package/dist/provider/ClientProvider.js +39 -27
- package/dist/provider/ClientProvider.js.map +1 -1
- package/dist/provider/GTProvider.d.ts +3 -3
- package/dist/provider/GTProvider.d.ts.map +1 -1
- package/dist/provider/GTProvider.js +89 -80
- package/dist/provider/GTProvider.js.map +1 -1
- package/dist/provider/types.d.ts +18 -0
- package/dist/provider/types.d.ts.map +1 -0
- package/dist/provider/types.js +3 -0
- package/dist/provider/types.js.map +1 -0
- package/dist/request/getLocale.d.ts +1 -1
- package/dist/request/getLocale.d.ts.map +1 -1
- package/dist/request/getLocale.js +2 -4
- package/dist/request/getLocale.js.map +1 -1
- package/dist/server/createServerTFunction.js +4 -2
- package/dist/server/createServerTFunction.js.map +1 -1
- package/dist/server/getGT.d.ts +16 -1
- package/dist/server/getGT.d.ts.map +1 -1
- package/dist/server/getGT.js +99 -6
- package/dist/server/getGT.js.map +1 -1
- package/dist/server/inline/T.d.ts +4 -4
- package/dist/server/inline/T.d.ts.map +1 -1
- package/dist/server/inline/T.js +48 -39
- package/dist/server/inline/T.js.map +1 -1
- package/dist/server/rendering/renderDefaultChildren.d.ts +0 -7
- package/dist/server/rendering/renderDefaultChildren.d.ts.map +1 -1
- package/dist/server/rendering/renderDefaultChildren.js +88 -72
- package/dist/server/rendering/renderDefaultChildren.js.map +1 -1
- package/dist/server/rendering/renderTranslatedChildren.d.ts +0 -9
- package/dist/server/rendering/renderTranslatedChildren.d.ts.map +1 -1
- package/dist/server/rendering/renderTranslatedChildren.js +224 -160
- package/dist/server/rendering/renderTranslatedChildren.js.map +1 -1
- package/dist/server/strings/tx.d.ts +10 -8
- package/dist/server/strings/tx.d.ts.map +1 -1
- package/dist/server/strings/tx.js +37 -33
- package/dist/server/strings/tx.js.map +1 -1
- package/dist/variables/Currency.js +1 -1
- package/dist/variables/Currency.js.map +1 -1
- package/dist/variables/DateTime.js +1 -1
- package/dist/variables/DateTime.js.map +1 -1
- package/dist/variables/Num.js +1 -1
- package/dist/variables/Num.js.map +1 -1
- package/package.json +4 -3
package/.prettierrc
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"semi": true,
|
|
3
|
+
"singleQuote": true,
|
|
4
|
+
"tabWidth": 2,
|
|
5
|
+
"useTabs": false,
|
|
6
|
+
"trailingComma": "es5",
|
|
7
|
+
"bracketSpacing": true,
|
|
8
|
+
"arrowParens": "always",
|
|
9
|
+
"printWidth": 80,
|
|
10
|
+
"endOfLine": "lf",
|
|
11
|
+
"jsxSingleQuote": true,
|
|
12
|
+
"proseWrap": "preserve",
|
|
13
|
+
"htmlWhitespaceSensitivity": "ignore"
|
|
14
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import GT from
|
|
1
|
+
import GT from 'generaltranslation';
|
|
2
2
|
type I18NConfigurationParams = {
|
|
3
3
|
apiKey: string;
|
|
4
4
|
projectID: string;
|
|
@@ -7,12 +7,13 @@ type I18NConfigurationParams = {
|
|
|
7
7
|
defaultLocale: string;
|
|
8
8
|
locales?: string[];
|
|
9
9
|
renderSettings: {
|
|
10
|
-
method:
|
|
10
|
+
method: 'skeleton' | 'replace' | 'hang' | 'subtle';
|
|
11
11
|
timeout: number | null;
|
|
12
12
|
};
|
|
13
13
|
translations?: Record<string, () => Promise<Record<string, any>>>;
|
|
14
14
|
maxConcurrentRequests: number;
|
|
15
15
|
batchInterval: number;
|
|
16
|
+
env?: string;
|
|
16
17
|
[key: string]: any;
|
|
17
18
|
};
|
|
18
19
|
export default class I18NConfiguration {
|
|
@@ -21,9 +22,10 @@ export default class I18NConfiguration {
|
|
|
21
22
|
defaultLocale: string;
|
|
22
23
|
locales: string[] | undefined;
|
|
23
24
|
renderSettings: {
|
|
24
|
-
method:
|
|
25
|
+
method: 'skeleton' | 'replace' | 'hang' | 'subtle';
|
|
25
26
|
timeout: number | null;
|
|
26
27
|
};
|
|
28
|
+
env: string;
|
|
27
29
|
private _remoteTranslationsManager;
|
|
28
30
|
gt: GT;
|
|
29
31
|
metadata: Record<string, any>;
|
|
@@ -32,29 +34,31 @@ export default class I18NConfiguration {
|
|
|
32
34
|
private _queue;
|
|
33
35
|
private _activeRequests;
|
|
34
36
|
private _translationCache;
|
|
35
|
-
|
|
37
|
+
private _taggedDictionary;
|
|
38
|
+
private _template;
|
|
39
|
+
constructor({ apiKey, projectID, baseURL, cacheURL, defaultLocale, locales, renderSettings, dictionary, maxConcurrentRequests, batchInterval, env, ...metadata }: I18NConfigurationParams);
|
|
36
40
|
/**
|
|
37
41
|
* Gets the application's default locale
|
|
38
|
-
* @returns {string} A BCP-47
|
|
39
|
-
|
|
42
|
+
* @returns {string} A BCP-47 locale tag
|
|
43
|
+
*/
|
|
40
44
|
getDefaultLocale(): string;
|
|
41
45
|
/**
|
|
42
46
|
* Gets the list of approved locales for this app
|
|
43
|
-
* @returns {string[] | undefined} A list of BCP-47
|
|
44
|
-
|
|
47
|
+
* @returns {string[] | undefined} A list of BCP-47 locale tags, or undefined if none were provided
|
|
48
|
+
*/
|
|
45
49
|
getLocales(): string[] | undefined;
|
|
46
50
|
/**
|
|
47
51
|
* @returns A boolean indicating whether automatic translation is enabled or disabled for this config
|
|
48
|
-
|
|
52
|
+
*/
|
|
49
53
|
translationEnabled(): boolean;
|
|
50
54
|
/**
|
|
51
55
|
* Get the rendering instructions
|
|
52
56
|
* @returns An object containing the current method and timeout.
|
|
53
57
|
* As of 7/31/24: method is "skeleton", "replace", "hang", "subtle".
|
|
54
58
|
* Timeout is a number or null, representing no assigned timeout.
|
|
55
|
-
|
|
59
|
+
*/
|
|
56
60
|
getRenderSettings(): {
|
|
57
|
-
method:
|
|
61
|
+
method: 'skeleton' | 'replace' | 'hang' | 'subtle';
|
|
58
62
|
timeout: number | null;
|
|
59
63
|
};
|
|
60
64
|
/**
|
|
@@ -63,14 +67,20 @@ export default class I18NConfiguration {
|
|
|
63
67
|
* @returns True if translation is required, otherwise false
|
|
64
68
|
*/
|
|
65
69
|
requiresTranslation(locale: string): boolean;
|
|
70
|
+
addGTIdentifier(children: any, id?: string): any;
|
|
71
|
+
/**
|
|
72
|
+
* @returns {[any, string]} A xxhash hash and the children that were created from it
|
|
73
|
+
*/
|
|
74
|
+
serializeAndHash(children: any, context?: string, id?: string): [any, string];
|
|
66
75
|
/**
|
|
67
76
|
* Get the translation dictionaries for this user's locale, if they exist
|
|
68
|
-
*
|
|
77
|
+
* Globally shared cache
|
|
78
|
+
* @param locale - The locale set by the user
|
|
69
79
|
* @returns A promise that resolves to the translations.
|
|
70
|
-
|
|
80
|
+
*/
|
|
71
81
|
getTranslations(locale: string): Promise<Record<string, any>>;
|
|
72
82
|
/**
|
|
73
|
-
* Translate content into language
|
|
83
|
+
* Translate content into language associated with a given locale
|
|
74
84
|
* @param params - Parameters for translation
|
|
75
85
|
* @returns Translated string
|
|
76
86
|
*/
|
|
@@ -79,17 +89,17 @@ export default class I18NConfiguration {
|
|
|
79
89
|
key: string;
|
|
80
90
|
variable?: string;
|
|
81
91
|
})[];
|
|
82
|
-
|
|
92
|
+
targetLocale: string;
|
|
83
93
|
options: Record<string, any>;
|
|
84
94
|
}): Promise<string>;
|
|
85
95
|
/**
|
|
86
96
|
* Translate the children components
|
|
87
97
|
* @param params - Parameters for translation
|
|
88
98
|
* @returns A promise that resolves when translation is complete
|
|
89
|
-
|
|
99
|
+
*/
|
|
90
100
|
translateChildren(params: {
|
|
91
101
|
children: any;
|
|
92
|
-
|
|
102
|
+
targetLocale: string;
|
|
93
103
|
metadata: Record<string, any>;
|
|
94
104
|
}): Promise<any>;
|
|
95
105
|
/**
|
|
@@ -99,7 +109,7 @@ export default class I18NConfiguration {
|
|
|
99
109
|
private _sendBatchRequest;
|
|
100
110
|
/**
|
|
101
111
|
* Start the batching process with a set interval
|
|
102
|
-
|
|
112
|
+
*/
|
|
103
113
|
private _startBatching;
|
|
104
114
|
}
|
|
105
115
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"I18NConfiguration.d.ts","sourceRoot":"","sources":["../../src/config/I18NConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"I18NConfiguration.d.ts","sourceRoot":"","sources":["../../src/config/I18NConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,MAAM,oBAAoB,CAAC;AAO7D,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,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AAM,EAAE;QAC9B,QAAQ,EAAE,GAAG,CAAC;QACd,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC/B,GAAG,OAAO,CAAC,GAAG,CAAC;IAgChB;;;OAGG;YACW,iBAAiB;IAuC/B;;OAEG;IACH,OAAO,CAAC,cAAc;CAWvB"}
|
|
@@ -87,6 +87,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
87
87
|
var generaltranslation_1 = __importStar(require("generaltranslation"));
|
|
88
88
|
var RemoteTranslationsManager_1 = __importDefault(require("./RemoteTranslationsManager"));
|
|
89
89
|
var defaultInitGTProps_1 = __importDefault(require("../primitives/defaultInitGTProps"));
|
|
90
|
+
var internal_1 = require("gt-react/internal");
|
|
90
91
|
var I18NConfiguration = /** @class */ (function () {
|
|
91
92
|
function I18NConfiguration(_a) {
|
|
92
93
|
var
|
|
@@ -100,8 +101,10 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
100
101
|
dictionary = _a.dictionary,
|
|
101
102
|
// Batching config
|
|
102
103
|
maxConcurrentRequests = _a.maxConcurrentRequests, batchInterval = _a.batchInterval,
|
|
104
|
+
// Environment
|
|
105
|
+
env = _a.env,
|
|
103
106
|
// Other metadata
|
|
104
|
-
metadata = __rest(_a, ["apiKey", "projectID", "baseURL", "cacheURL", "defaultLocale", "locales", "renderSettings", "dictionary", "maxConcurrentRequests", "batchInterval"]);
|
|
107
|
+
metadata = __rest(_a, ["apiKey", "projectID", "baseURL", "cacheURL", "defaultLocale", "locales", "renderSettings", "dictionary", "maxConcurrentRequests", "batchInterval", "env"]);
|
|
105
108
|
// Cloud integration
|
|
106
109
|
this.projectID = projectID;
|
|
107
110
|
this.baseURL = baseURL;
|
|
@@ -111,17 +114,29 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
111
114
|
// Render method
|
|
112
115
|
this.renderSettings = renderSettings;
|
|
113
116
|
// GT
|
|
114
|
-
this.gt = new generaltranslation_1.default({
|
|
117
|
+
this.gt = new generaltranslation_1.default({
|
|
118
|
+
projectID: projectID,
|
|
119
|
+
apiKey: apiKey,
|
|
120
|
+
defaultLocale: defaultLocale,
|
|
121
|
+
baseURL: baseURL,
|
|
122
|
+
});
|
|
123
|
+
// Default env is production
|
|
124
|
+
this.env = env || "production";
|
|
115
125
|
// Other metadata
|
|
116
|
-
this.metadata = __assign(__assign({
|
|
126
|
+
this.metadata = __assign(__assign({ env: this.env, defaultLocale: this.defaultLocale }, (this.renderSettings.timeout && {
|
|
127
|
+
timeout: this.renderSettings.timeout - batchInterval,
|
|
128
|
+
})), metadata);
|
|
117
129
|
// Dictionary managers
|
|
118
130
|
if (cacheURL && projectID) {
|
|
119
131
|
this._remoteTranslationsManager = RemoteTranslationsManager_1.default;
|
|
120
132
|
this._remoteTranslationsManager.setConfig({
|
|
121
133
|
cacheURL: cacheURL,
|
|
122
|
-
projectID: projectID
|
|
134
|
+
projectID: projectID,
|
|
123
135
|
});
|
|
124
136
|
}
|
|
137
|
+
// Cache of hashes to speed up <GTProvider>
|
|
138
|
+
this._taggedDictionary = new Map();
|
|
139
|
+
this._template = new Map();
|
|
125
140
|
// Batching
|
|
126
141
|
this.maxConcurrentRequests = maxConcurrentRequests;
|
|
127
142
|
this.batchInterval = batchInterval;
|
|
@@ -132,30 +147,34 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
132
147
|
}
|
|
133
148
|
/**
|
|
134
149
|
* Gets the application's default locale
|
|
135
|
-
* @returns {string} A BCP-47
|
|
136
|
-
|
|
150
|
+
* @returns {string} A BCP-47 locale tag
|
|
151
|
+
*/
|
|
137
152
|
I18NConfiguration.prototype.getDefaultLocale = function () {
|
|
138
153
|
return this.defaultLocale;
|
|
139
154
|
};
|
|
140
155
|
/**
|
|
141
156
|
* Gets the list of approved locales for this app
|
|
142
|
-
* @returns {string[] | undefined} A list of BCP-47
|
|
143
|
-
|
|
157
|
+
* @returns {string[] | undefined} A list of BCP-47 locale tags, or undefined if none were provided
|
|
158
|
+
*/
|
|
144
159
|
I18NConfiguration.prototype.getLocales = function () {
|
|
145
160
|
return this.locales;
|
|
146
161
|
};
|
|
147
162
|
/**
|
|
148
163
|
* @returns A boolean indicating whether automatic translation is enabled or disabled for this config
|
|
149
|
-
|
|
164
|
+
*/
|
|
150
165
|
I18NConfiguration.prototype.translationEnabled = function () {
|
|
151
|
-
return
|
|
166
|
+
return this.baseURL &&
|
|
167
|
+
this.projectID &&
|
|
168
|
+
(this.baseURL === defaultInitGTProps_1.default.baseURL ? this.gt.apiKey : true)
|
|
169
|
+
? true
|
|
170
|
+
: false;
|
|
152
171
|
};
|
|
153
172
|
/**
|
|
154
173
|
* Get the rendering instructions
|
|
155
174
|
* @returns An object containing the current method and timeout.
|
|
156
175
|
* As of 7/31/24: method is "skeleton", "replace", "hang", "subtle".
|
|
157
176
|
* Timeout is a number or null, representing no assigned timeout.
|
|
158
|
-
|
|
177
|
+
*/
|
|
159
178
|
I18NConfiguration.prototype.getRenderSettings = function () {
|
|
160
179
|
return this.renderSettings;
|
|
161
180
|
};
|
|
@@ -165,51 +184,91 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
165
184
|
* @returns True if translation is required, otherwise false
|
|
166
185
|
*/
|
|
167
186
|
I18NConfiguration.prototype.requiresTranslation = function (locale) {
|
|
168
|
-
return this.translationEnabled() &&
|
|
187
|
+
return (this.translationEnabled() &&
|
|
188
|
+
(0, generaltranslation_1.requiresTranslation)(this.defaultLocale, locale, this.locales));
|
|
189
|
+
};
|
|
190
|
+
I18NConfiguration.prototype.addGTIdentifier = function (children, id) {
|
|
191
|
+
// In development, recompute every time
|
|
192
|
+
if (this.env === "development" || !id) {
|
|
193
|
+
return (0, internal_1.addGTIdentifier)(children, id);
|
|
194
|
+
}
|
|
195
|
+
// In production, since dictionary content isn't changing, cache results
|
|
196
|
+
var taggedDictionaryEntry = this._taggedDictionary.get(id);
|
|
197
|
+
if (taggedDictionaryEntry) {
|
|
198
|
+
return taggedDictionaryEntry;
|
|
199
|
+
}
|
|
200
|
+
var taggedChildren = (0, internal_1.addGTIdentifier)(children, id);
|
|
201
|
+
this._taggedDictionary.set(id, taggedChildren);
|
|
202
|
+
return taggedChildren;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* @returns {[any, string]} A xxhash hash and the children that were created from it
|
|
206
|
+
*/
|
|
207
|
+
I18NConfiguration.prototype.serializeAndHash = function (children, context, id) {
|
|
208
|
+
// In development, recomputes hashes each time
|
|
209
|
+
if (this.env === "development" || !id) {
|
|
210
|
+
var childrenAsObjects_1 = (0, internal_1.writeChildrenAsObjects)(children);
|
|
211
|
+
return [
|
|
212
|
+
childrenAsObjects_1,
|
|
213
|
+
(0, internal_1.hashReactChildrenObjects)(context ? [childrenAsObjects_1, context] : childrenAsObjects_1)
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
// In production, since dictionary content isn't changing, cache results
|
|
217
|
+
var templateEntry = this._template.get(id);
|
|
218
|
+
if (templateEntry) {
|
|
219
|
+
return [templateEntry.t, templateEntry.k];
|
|
220
|
+
}
|
|
221
|
+
var childrenAsObjects = (0, internal_1.writeChildrenAsObjects)(children);
|
|
222
|
+
var hash = (0, internal_1.hashReactChildrenObjects)(context ? [childrenAsObjects, context] : childrenAsObjects);
|
|
223
|
+
this._template.set(id, { k: hash, t: childrenAsObjects });
|
|
224
|
+
return [childrenAsObjects, hash];
|
|
169
225
|
};
|
|
170
226
|
/**
|
|
171
227
|
* Get the translation dictionaries for this user's locale, if they exist
|
|
172
|
-
*
|
|
228
|
+
* Globally shared cache
|
|
229
|
+
* @param locale - The locale set by the user
|
|
173
230
|
* @returns A promise that resolves to the translations.
|
|
174
|
-
|
|
231
|
+
*/
|
|
175
232
|
I18NConfiguration.prototype.getTranslations = function (locale) {
|
|
176
233
|
return __awaiter(this, void 0, void 0, function () {
|
|
177
234
|
var _a;
|
|
178
235
|
return __generator(this, function (_b) {
|
|
179
236
|
switch (_b.label) {
|
|
180
237
|
case 0: return [4 /*yield*/, ((_a = this._remoteTranslationsManager) === null || _a === void 0 ? void 0 : _a.getTranslations(locale))];
|
|
181
|
-
case 1: return [2 /*return*/, (_b.sent()) || {}];
|
|
238
|
+
case 1: return [2 /*return*/, ((_b.sent()) || {})];
|
|
182
239
|
}
|
|
183
240
|
});
|
|
184
241
|
});
|
|
185
242
|
};
|
|
186
243
|
/**
|
|
187
|
-
* Translate content into language
|
|
244
|
+
* Translate content into language associated with a given locale
|
|
188
245
|
* @param params - Parameters for translation
|
|
189
246
|
* @returns Translated string
|
|
190
247
|
*/
|
|
191
248
|
I18NConfiguration.prototype.translate = function (params) {
|
|
192
249
|
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
-
var cacheKey, content,
|
|
250
|
+
var cacheKey, content, targetLocale, options, translationPromise;
|
|
194
251
|
var _this = this;
|
|
195
252
|
return __generator(this, function (_a) {
|
|
196
|
-
cacheKey = constructCacheKey(params.
|
|
253
|
+
cacheKey = constructCacheKey(params.targetLocale, params.options);
|
|
197
254
|
if (this._translationCache.has(cacheKey)) {
|
|
198
255
|
return [2 /*return*/, this._translationCache.get(cacheKey)];
|
|
199
256
|
}
|
|
200
|
-
content = params.content,
|
|
257
|
+
content = params.content, targetLocale = params.targetLocale, options = params.options;
|
|
201
258
|
translationPromise = new Promise(function (resolve, reject) {
|
|
202
259
|
_this._queue.push({
|
|
203
|
-
type:
|
|
260
|
+
type: 'string',
|
|
204
261
|
data: {
|
|
205
262
|
content: content,
|
|
206
|
-
|
|
263
|
+
targetLocale: targetLocale,
|
|
207
264
|
projectID: _this.projectID,
|
|
208
|
-
metadata: __assign(__assign({}, _this.metadata), options)
|
|
265
|
+
metadata: __assign(__assign({}, _this.metadata), options),
|
|
209
266
|
},
|
|
210
|
-
revalidate:
|
|
267
|
+
revalidate: _this._remoteTranslationsManager
|
|
268
|
+
? _this._remoteTranslationsManager.getTranslationRequested(targetLocale)
|
|
269
|
+
: false,
|
|
211
270
|
resolve: resolve,
|
|
212
|
-
reject: reject
|
|
271
|
+
reject: reject,
|
|
213
272
|
});
|
|
214
273
|
});
|
|
215
274
|
this._translationCache.set(cacheKey, translationPromise);
|
|
@@ -224,28 +283,33 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
224
283
|
* Translate the children components
|
|
225
284
|
* @param params - Parameters for translation
|
|
226
285
|
* @returns A promise that resolves when translation is complete
|
|
227
|
-
|
|
286
|
+
*/
|
|
228
287
|
I18NConfiguration.prototype.translateChildren = function (params) {
|
|
229
288
|
return __awaiter(this, void 0, void 0, function () {
|
|
230
|
-
var cacheKey, children,
|
|
289
|
+
var cacheKey, children, targetLocale, metadata, translationPromise;
|
|
231
290
|
var _this = this;
|
|
232
291
|
return __generator(this, function (_a) {
|
|
233
|
-
cacheKey = constructCacheKey(params.
|
|
292
|
+
cacheKey = constructCacheKey(params.targetLocale, params.metadata);
|
|
293
|
+
// In memory cache to make sure the same translation isn't requested twice
|
|
234
294
|
if (this._translationCache.has(cacheKey)) {
|
|
295
|
+
// Returns the previous request
|
|
235
296
|
return [2 /*return*/, this._translationCache.get(cacheKey)];
|
|
236
297
|
}
|
|
237
|
-
children = params.children,
|
|
298
|
+
children = params.children, targetLocale = params.targetLocale, metadata = params.metadata;
|
|
238
299
|
translationPromise = new Promise(function (resolve, reject) {
|
|
300
|
+
// In memory queue to batch requests
|
|
239
301
|
_this._queue.push({
|
|
240
|
-
type:
|
|
302
|
+
type: 'react',
|
|
241
303
|
data: {
|
|
242
304
|
children: children,
|
|
243
|
-
|
|
244
|
-
metadata: __assign(__assign({}, _this.metadata), metadata)
|
|
305
|
+
targetLocale: targetLocale,
|
|
306
|
+
metadata: __assign(__assign({}, _this.metadata), metadata),
|
|
245
307
|
},
|
|
246
|
-
revalidate:
|
|
308
|
+
revalidate: _this._remoteTranslationsManager
|
|
309
|
+
? _this._remoteTranslationsManager.getTranslationRequested(targetLocale)
|
|
310
|
+
: false,
|
|
247
311
|
resolve: resolve,
|
|
248
|
-
reject: reject
|
|
312
|
+
reject: reject,
|
|
249
313
|
});
|
|
250
314
|
});
|
|
251
315
|
this._translationCache.set(cacheKey, translationPromise);
|
|
@@ -270,8 +334,8 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
270
334
|
_a.trys.push([1, 3, 4, 5]);
|
|
271
335
|
batchPromise = this.gt.translateBatch(batch);
|
|
272
336
|
batch.forEach(function (item) {
|
|
273
|
-
if (_this._remoteTranslationsManager && item.revalidate)
|
|
274
|
-
_this._remoteTranslationsManager.setTranslationRequested(item.data.
|
|
337
|
+
if (_this._remoteTranslationsManager && !item.revalidate)
|
|
338
|
+
_this._remoteTranslationsManager.setTranslationRequested(item.data.targetLocale);
|
|
275
339
|
});
|
|
276
340
|
return [4 /*yield*/, batchPromise];
|
|
277
341
|
case 2:
|
|
@@ -282,8 +346,11 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
282
346
|
return item.reject('Translation failed.');
|
|
283
347
|
if (result && typeof result === 'object') {
|
|
284
348
|
item.resolve(result.translation);
|
|
285
|
-
if (result.translation &&
|
|
286
|
-
|
|
349
|
+
if (result.translation &&
|
|
350
|
+
result.locale &&
|
|
351
|
+
result.reference &&
|
|
352
|
+
_this._remoteTranslationsManager) {
|
|
353
|
+
_this._remoteTranslationsManager.setTranslations(result.locale, result.reference.key, result.reference.id, result.translation);
|
|
287
354
|
}
|
|
288
355
|
}
|
|
289
356
|
});
|
|
@@ -303,11 +370,12 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
303
370
|
};
|
|
304
371
|
/**
|
|
305
372
|
* Start the batching process with a set interval
|
|
306
|
-
|
|
373
|
+
*/
|
|
307
374
|
I18NConfiguration.prototype._startBatching = function () {
|
|
308
375
|
var _this = this;
|
|
309
376
|
setInterval(function () {
|
|
310
|
-
if (_this._queue.length > 0 &&
|
|
377
|
+
if (_this._queue.length > 0 &&
|
|
378
|
+
_this._activeRequests < _this.maxConcurrentRequests) {
|
|
311
379
|
_this._sendBatchRequest(_this._queue);
|
|
312
380
|
_this._queue = [];
|
|
313
381
|
}
|
|
@@ -317,7 +385,7 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
317
385
|
}());
|
|
318
386
|
exports.default = I18NConfiguration;
|
|
319
387
|
// Constructs the unique identification key for the map which is the in-memory same-render-cycle cache
|
|
320
|
-
var constructCacheKey = function (
|
|
321
|
-
return "".concat(
|
|
388
|
+
var constructCacheKey = function (targetLocale, metadata) {
|
|
389
|
+
return "".concat(targetLocale, "-").concat(metadata.hash);
|
|
322
390
|
};
|
|
323
391
|
//# sourceMappingURL=I18NConfiguration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"I18NConfiguration.js","sourceRoot":"","sources":["../../src/config/I18NConfiguration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uEAA6D;AAC7D,
|
|
1
|
+
{"version":3,"file":"I18NConfiguration.js","sourceRoot":"","sources":["../../src/config/I18NConfiguration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uEAA6D;AAC7D,0FAEqC;AACrC,wFAAkE;AAClE,8CAA0H;AAoB1H;IA8BE,2BAAY,EAoBc;QAlBxB;QADA,oBAAoB;QACpB,MAAM,YAAA,EACN,SAAS,eAAA,EACT,OAAO,aAAA,EACP,QAAQ,cAAA;QACR,cAAc;QACd,aAAa,mBAAA,EACb,OAAO,aAAA;QACP,gBAAgB;QAChB,cAAc,oBAAA;QACd,eAAe;QACf,UAAU,gBAAA;QACV,kBAAkB;QAClB,qBAAqB,2BAAA,EACrB,aAAa,mBAAA;QACb,cAAc;QACd,GAAG,SAAA;QACH,iBAAiB;QACd,QAAQ,cAnBD,2JAoBX,CADY;QAEX,oBAAoB;Q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,EAAE,CAAC;;;;;;KAE1B;IAED;;OAEG;IACK,0CAAc,GAAtB;QAAA,iBAUC;QATC,WAAW,CAAC;YACV,IACE,KAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;gBACtB,KAAI,CAAC,eAAe,GAAG,KAAI,CAAC,qBAAqB,EACjD,CAAC;gBACD,KAAI,CAAC,iBAAiB,CAAC,KAAI,CAAC,MAAM,CAAC,CAAC;gBACpC,KAAI,CAAC,MAAM,GAAG,EAAE,CAAC;YACnB,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACzB,CAAC;IACH,wBAAC;AAAD,CAAC,AApVD,IAoVC;;AAED,sGAAsG;AACtG,IAAM,iBAAiB,GAAG,UACxB,YAAoB,EACpB,QAA6B;IAE7B,OAAO,UAAG,YAAY,cAAI,QAAQ,CAAC,IAAI,CAAE,CAAC;AAC5C,CAAC,CAAC"}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a reference string from locale.
|
|
3
|
-
* @param {string} locale - The locale/language code.
|
|
4
|
-
* @returns {string} The encoded reference.
|
|
5
|
-
*/
|
|
6
|
-
export declare function getTranslationReference(locale: string): string;
|
|
7
1
|
/**
|
|
8
2
|
* Configuration type for RemoteTranslationsManager.
|
|
9
3
|
*/
|
|
@@ -36,13 +30,13 @@ export declare class RemoteTranslationsManager {
|
|
|
36
30
|
private _fetchTranslations;
|
|
37
31
|
/**
|
|
38
32
|
* Retrieves translations for a given locale.
|
|
39
|
-
* @param {string} locale - The locale
|
|
33
|
+
* @param {string} locale - The locale code.
|
|
40
34
|
* @returns {Promise<Record<string, any> | null>} The translations data or null if not found.
|
|
41
35
|
*/
|
|
42
36
|
getTranslations(locale: string): Promise<Record<string, any> | null>;
|
|
43
37
|
/**
|
|
44
38
|
* Sets a new translation entry.
|
|
45
|
-
* @param {string} locale - The locale
|
|
39
|
+
* @param {string} locale - The locale code.
|
|
46
40
|
* @param {string} key - The key for the new entry.
|
|
47
41
|
* @param {string} [id=key] - The id for the new entry, defaults to key if not provided.
|
|
48
42
|
* @param {any} translation - The translation value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteTranslationsManager.d.ts","sourceRoot":"","sources":["../../src/config/RemoteTranslationsManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RemoteTranslationsManager.d.ts","sourceRoot":"","sources":["../../src/config/RemoteTranslationsManager.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,KAAK,wBAAwB,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,qBAAa,yBAAyB;IACpC,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,eAAe,CAAmC;IAC1D,OAAO,CAAC,aAAa,CAAmD;IACxE,OAAO,CAAC,qBAAqB,CAAuB;IAEpD;;OAEG;;IAWH;;;OAGG;IACH,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,IAAI;IAI7D;;;;OAIG;YACW,kBAAkB;IAiBhC;;;;OAIG;IACG,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAqB1E;;;;;;;OAOG;IACH,eAAe,CACb,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,YAAM,EAChB,WAAW,EAAE,GAAG,GACf,OAAO;IAcV;;OAEG;IACH,uBAAuB,CAAC,MAAM,EAAE,MAAM;IAKtC;;OAEG;IACH,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;CAIjD;AAED,QAAA,MAAM,yBAAyB,2BAAkC,CAAC;AAClE,eAAe,yBAAyB,CAAC"}
|
|
@@ -48,15 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.RemoteTranslationsManager = void 0;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Generates a reference string from locale.
|
|
54
|
-
* @param {string} locale - The locale/language code.
|
|
55
|
-
* @returns {string} The encoded reference.
|
|
56
|
-
*/
|
|
57
|
-
function getTranslationReference(locale) {
|
|
58
|
-
return encodeURIComponent(locale);
|
|
59
|
-
}
|
|
51
|
+
var generaltranslation_1 = require("generaltranslation");
|
|
60
52
|
/**
|
|
61
53
|
* Manages remote translations.
|
|
62
54
|
*/
|
|
@@ -66,8 +58,8 @@ var RemoteTranslationsManager = /** @class */ (function () {
|
|
|
66
58
|
*/
|
|
67
59
|
function RemoteTranslationsManager() {
|
|
68
60
|
this.config = {
|
|
69
|
-
cacheURL:
|
|
70
|
-
projectID:
|
|
61
|
+
cacheURL: 'https://cache.gtx.dev',
|
|
62
|
+
projectID: '',
|
|
71
63
|
};
|
|
72
64
|
this.translationsMap = new Map();
|
|
73
65
|
this.fetchPromises = new Map();
|
|
@@ -113,7 +105,7 @@ var RemoteTranslationsManager = /** @class */ (function () {
|
|
|
113
105
|
};
|
|
114
106
|
/**
|
|
115
107
|
* Retrieves translations for a given locale.
|
|
116
|
-
* @param {string} locale - The locale
|
|
108
|
+
* @param {string} locale - The locale code.
|
|
117
109
|
* @returns {Promise<Record<string, any> | null>} The translations data or null if not found.
|
|
118
110
|
*/
|
|
119
111
|
RemoteTranslationsManager.prototype.getTranslations = function (locale) {
|
|
@@ -122,7 +114,7 @@ var RemoteTranslationsManager = /** @class */ (function () {
|
|
|
122
114
|
return __generator(this, function (_a) {
|
|
123
115
|
switch (_a.label) {
|
|
124
116
|
case 0:
|
|
125
|
-
reference =
|
|
117
|
+
reference = (0, generaltranslation_1.standardizeLocale)(locale);
|
|
126
118
|
if (this.translationsMap.has(reference)) {
|
|
127
119
|
return [2 /*return*/, this.translationsMap.get(reference) || null];
|
|
128
120
|
}
|
|
@@ -146,7 +138,7 @@ var RemoteTranslationsManager = /** @class */ (function () {
|
|
|
146
138
|
};
|
|
147
139
|
/**
|
|
148
140
|
* Sets a new translation entry.
|
|
149
|
-
* @param {string} locale - The locale
|
|
141
|
+
* @param {string} locale - The locale code.
|
|
150
142
|
* @param {string} key - The key for the new entry.
|
|
151
143
|
* @param {string} [id=key] - The id for the new entry, defaults to key if not provided.
|
|
152
144
|
* @param {any} translation - The translation value.
|
|
@@ -157,9 +149,9 @@ var RemoteTranslationsManager = /** @class */ (function () {
|
|
|
157
149
|
if (id === void 0) { id = key; }
|
|
158
150
|
if (!(locale && key && id && translation))
|
|
159
151
|
return false;
|
|
160
|
-
var reference =
|
|
152
|
+
var reference = (0, generaltranslation_1.standardizeLocale)(locale);
|
|
161
153
|
var currentTranslations = this.translationsMap.get(reference) || {};
|
|
162
|
-
this.translationsMap.set(reference, __assign(__assign({}, currentTranslations), (_a = {}, _a[id] =
|
|
154
|
+
this.translationsMap.set(reference, __assign(__assign({}, currentTranslations), (_a = {}, _a[id] = translation && typeof translation === 'object' && translation.t
|
|
163
155
|
? __assign(__assign({}, translation), { k: key }) : { k: key, t: translation }, _a)));
|
|
164
156
|
return true;
|
|
165
157
|
};
|
|
@@ -167,14 +159,14 @@ var RemoteTranslationsManager = /** @class */ (function () {
|
|
|
167
159
|
* Marks translations as requested for a given locale
|
|
168
160
|
*/
|
|
169
161
|
RemoteTranslationsManager.prototype.setTranslationRequested = function (locale) {
|
|
170
|
-
var reference =
|
|
162
|
+
var reference = (0, generaltranslation_1.standardizeLocale)(locale);
|
|
171
163
|
this.requestedTranslations.set(reference, true);
|
|
172
164
|
};
|
|
173
165
|
/**
|
|
174
166
|
* Checks if translations have been requested for a given locale
|
|
175
167
|
*/
|
|
176
168
|
RemoteTranslationsManager.prototype.getTranslationRequested = function (locale) {
|
|
177
|
-
var reference =
|
|
169
|
+
var reference = (0, generaltranslation_1.standardizeLocale)(locale);
|
|
178
170
|
return this.requestedTranslations.get(reference) ? true : false;
|
|
179
171
|
};
|
|
180
172
|
return RemoteTranslationsManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteTranslationsManager.js","sourceRoot":"","sources":["../../src/config/RemoteTranslationsManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"RemoteTranslationsManager.js","sourceRoot":"","sources":["../../src/config/RemoteTranslationsManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAuD;AAUvD;;GAEG;AACH;IAME;;OAEG;IACH;QACE,IAAI,CAAC,MAAM,GAAG;YACZ,QAAQ,EAAE,uBAAuB;YACjC,SAAS,EAAE,EAAE;SACd,CAAC;QACF,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,EAAE,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,qBAAqB,GAAG,IAAI,GAAG,EAAE,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,6CAAS,GAAT,UAAU,SAA4C;QACpD,IAAI,CAAC,MAAM,yBAAQ,IAAI,CAAC,MAAM,GAAK,SAAS,CAAE,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACW,sDAAkB,GAAhC,UACE,SAAiB;;;;;;;wBAGE,qBAAM,KAAK,CAC1B,UAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,cAAI,IAAI,CAAC,MAAM,CAAC,SAAS,cAAI,SAAS,CAAE,CAChE,EAAA;;wBAFK,QAAQ,GAAG,SAEhB;wBACc,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAA9B,MAAM,GAAG,SAAqB;wBACpC,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;4BAC/B,sBAAO,MAAM,EAAC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