gt-next 5.2.0-alpha.3 → 5.2.0-alpha.4
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/config-dir/I18NConfiguration.d.ts +34 -37
- package/dist/config-dir/I18NConfiguration.d.ts.map +1 -1
- package/dist/config-dir/I18NConfiguration.js +77 -75
- package/dist/config-dir/I18NConfiguration.js.map +1 -1
- package/dist/config-dir/TranslationManager.d.ts +5 -16
- package/dist/config-dir/TranslationManager.d.ts.map +1 -1
- package/dist/config-dir/TranslationManager.js +9 -36
- package/dist/config-dir/TranslationManager.js.map +1 -1
- package/dist/config-dir/loadTranslation.js +2 -2
- package/dist/config-dir/loadTranslation.js.map +1 -1
- package/dist/config-dir/props/InitGTProps.d.ts +0 -2
- package/dist/config-dir/props/InitGTProps.d.ts.map +1 -1
- package/dist/config-dir/props/defaultInitGTProps.d.ts +0 -1
- package/dist/config-dir/props/defaultInitGTProps.d.ts.map +1 -1
- package/dist/config-dir/props/defaultInitGTProps.js +0 -1
- package/dist/config-dir/props/defaultInitGTProps.js.map +1 -1
- package/dist/config.d.ts +0 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -29
- package/dist/config.js.map +1 -1
- package/dist/dictionary/getDictionary.d.ts.map +1 -1
- package/dist/dictionary/getDictionary.js +11 -4
- package/dist/dictionary/getDictionary.js.map +1 -1
- package/dist/errors/createErrors.d.ts +6 -3
- package/dist/errors/createErrors.d.ts.map +1 -1
- package/dist/errors/createErrors.js +14 -9
- package/dist/errors/createErrors.js.map +1 -1
- package/dist/provider/GTProvider.d.ts +1 -1
- package/dist/provider/GTProvider.d.ts.map +1 -1
- package/dist/provider/GTProvider.js +17 -168
- package/dist/provider/GTProvider.js.map +1 -1
- package/dist/server-dir/buildtime/T.d.ts +3 -17
- package/dist/server-dir/buildtime/T.d.ts.map +1 -1
- package/dist/server-dir/buildtime/T.js +53 -74
- package/dist/server-dir/buildtime/T.js.map +1 -1
- package/dist/server-dir/buildtime/getDict.d.ts +2 -5
- package/dist/server-dir/buildtime/getDict.d.ts.map +1 -1
- package/dist/server-dir/buildtime/getDict.js +19 -160
- package/dist/server-dir/buildtime/getDict.js.map +1 -1
- package/dist/server-dir/buildtime/getGT.d.ts +3 -5
- package/dist/server-dir/buildtime/getGT.d.ts.map +1 -1
- package/dist/server-dir/buildtime/getGT.js +23 -26
- package/dist/server-dir/buildtime/getGT.js.map +1 -1
- package/dist/server-dir/runtime/_Tx.d.ts +32 -2
- package/dist/server-dir/runtime/_Tx.d.ts.map +1 -1
- package/dist/server-dir/runtime/_Tx.js +89 -58
- package/dist/server-dir/runtime/_Tx.js.map +1 -1
- package/dist/server-dir/runtime/tx.d.ts +2 -4
- package/dist/server-dir/runtime/tx.d.ts.map +1 -1
- package/dist/server-dir/runtime/tx.js +8 -9
- package/dist/server-dir/runtime/tx.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RenderMethod, TranslatedChildren, TranslatedContent
|
|
1
|
+
import { RenderMethod, TranslatedChildren, TranslatedContent } from 'gt-react/internal';
|
|
2
2
|
import { Content, JsxChildren } from 'generaltranslation/internal';
|
|
3
|
-
import {
|
|
3
|
+
import { TranslationsObject } from 'gt-react/internal';
|
|
4
4
|
type I18NConfigurationParams = {
|
|
5
5
|
apiKey?: string;
|
|
6
6
|
devApiKey?: string;
|
|
@@ -8,7 +8,6 @@ type I18NConfigurationParams = {
|
|
|
8
8
|
runtimeUrl: string | undefined;
|
|
9
9
|
cacheUrl: string | null;
|
|
10
10
|
loadTranslationType: 'remote' | 'custom' | 'disabled';
|
|
11
|
-
cacheExpiryTime?: number;
|
|
12
11
|
defaultLocale: string;
|
|
13
12
|
locales: string[];
|
|
14
13
|
renderSettings: {
|
|
@@ -23,9 +22,9 @@ type I18NConfigurationParams = {
|
|
|
23
22
|
};
|
|
24
23
|
export default class I18NConfiguration {
|
|
25
24
|
translationEnabled: boolean;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
developmentApiEnabled: boolean;
|
|
26
|
+
productionApiEnabled: boolean;
|
|
27
|
+
dictionaryEnabled: boolean;
|
|
29
28
|
projectId?: string;
|
|
30
29
|
apiKey?: string;
|
|
31
30
|
devApiKey?: string;
|
|
@@ -46,20 +45,31 @@ export default class I18NConfiguration {
|
|
|
46
45
|
private _queue;
|
|
47
46
|
private _activeRequests;
|
|
48
47
|
private _translationCache;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
constructor({ apiKey, devApiKey, projectId, _versionId, runtimeUrl, cacheUrl, loadTranslationType, defaultLocale, locales, renderSettings, dictionary, maxConcurrentRequests, maxBatchSize, batchInterval, _usingPlugin, ...metadata }: I18NConfigurationParams);
|
|
49
|
+
/**
|
|
50
|
+
* Get the rendering instructions
|
|
51
|
+
* @returns An object containing the current method and timeout.
|
|
52
|
+
* As of 1/22/25: method is "skeleton", "replace", "default".
|
|
53
|
+
* Timeout is a number or null, representing no assigned timeout.
|
|
54
|
+
*/
|
|
55
|
+
getRenderSettings(): {
|
|
56
|
+
method: RenderMethod;
|
|
57
|
+
timeout?: number;
|
|
58
|
+
};
|
|
53
59
|
/**
|
|
54
60
|
* Gets config for dynamic translation on the client side.
|
|
55
61
|
*/
|
|
56
62
|
getClientSideConfig(): {
|
|
57
63
|
projectId: string | undefined;
|
|
58
|
-
devApiKey: string | undefined;
|
|
59
|
-
runtimeUrl: string | undefined;
|
|
60
64
|
translationEnabled: boolean;
|
|
61
|
-
|
|
65
|
+
runtimeUrl: string | undefined;
|
|
66
|
+
devApiKey: string | undefined;
|
|
62
67
|
dictionaryEnabled: boolean;
|
|
68
|
+
renderSettings: {
|
|
69
|
+
method: RenderMethod;
|
|
70
|
+
timeout?: number;
|
|
71
|
+
};
|
|
72
|
+
runtimeTranslationEnabled: boolean;
|
|
63
73
|
};
|
|
64
74
|
/**
|
|
65
75
|
* Gets the application's default locale
|
|
@@ -72,40 +82,27 @@ export default class I18NConfiguration {
|
|
|
72
82
|
*/
|
|
73
83
|
getLocales(): string[];
|
|
74
84
|
/**
|
|
75
|
-
* @returns true if
|
|
76
|
-
*/
|
|
77
|
-
isDictionaryEnabled(): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* @returns A boolean indicating whether automatic translation is enabled or disabled for this config
|
|
85
|
+
* @returns true if build time translation is enabled
|
|
80
86
|
*/
|
|
81
87
|
isTranslationEnabled(): boolean;
|
|
82
88
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @returns {boolean} A boolean indicating whether the dev runtime translation is enabled
|
|
89
|
+
* @returns true if dictionaries are enabled
|
|
85
90
|
*/
|
|
86
|
-
|
|
91
|
+
isDictionaryEnabled(): boolean;
|
|
87
92
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @returns {boolean} A boolean indicating whether the client runtime translation is enabled
|
|
93
|
+
* @returns true if development runtime translation API is enabled
|
|
90
94
|
*/
|
|
91
|
-
|
|
95
|
+
isDevelopmentApiEnabled(): boolean;
|
|
92
96
|
/**
|
|
93
|
-
*
|
|
94
|
-
* @returns An object containing the current method and timeout.
|
|
95
|
-
* As of 1/22/25: method is "skeleton", "replace", "default".
|
|
96
|
-
* Timeout is a number or null, representing no assigned timeout.
|
|
97
|
+
* @returns true if production runtime translation API is enabled
|
|
97
98
|
*/
|
|
98
|
-
|
|
99
|
-
method: RenderMethod;
|
|
100
|
-
timeout?: number;
|
|
101
|
-
};
|
|
99
|
+
isProductionApiEnabled(): boolean;
|
|
102
100
|
/**
|
|
103
101
|
* Check if translation is required based on the user's locale
|
|
104
102
|
* @param locale - The user's locale
|
|
105
103
|
* @returns True if translation is required, otherwise false
|
|
106
104
|
*/
|
|
107
|
-
requiresTranslation(locale: string): boolean;
|
|
108
|
-
addGTIdentifier(children: Children): TaggedChildren;
|
|
105
|
+
requiresTranslation(locale: string): [boolean, boolean];
|
|
109
106
|
/**
|
|
110
107
|
* Get the translation dictionaries for this user's locale, if they exist
|
|
111
108
|
* Globally shared cache or saved locally
|
|
@@ -114,7 +111,7 @@ export default class I18NConfiguration {
|
|
|
114
111
|
*/
|
|
115
112
|
getCachedTranslations(locale: string): Promise<TranslationsObject>;
|
|
116
113
|
/**
|
|
117
|
-
*
|
|
114
|
+
* Synchronously retrieves translations for a given locale which are already cached locally
|
|
118
115
|
* @param {string} locale - The locale code.
|
|
119
116
|
* @returns {TranslationsObject} The translations data or an empty object if not found.
|
|
120
117
|
*/
|
|
@@ -136,10 +133,10 @@ export default class I18NConfiguration {
|
|
|
136
133
|
* @param params - Parameters for translation
|
|
137
134
|
* @returns A promise that resolves when translation is complete
|
|
138
135
|
*/
|
|
139
|
-
|
|
136
|
+
translateJsx(params: {
|
|
140
137
|
source: JsxChildren;
|
|
141
138
|
targetLocale: string;
|
|
142
|
-
|
|
139
|
+
options: {
|
|
143
140
|
hash: string;
|
|
144
141
|
} & Record<string, any>;
|
|
145
142
|
}): Promise<TranslatedChildren>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"I18NConfiguration.d.ts","sourceRoot":"","sources":["../../src/config-dir/I18NConfiguration.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"I18NConfiguration.d.ts","sourceRoot":"","sources":["../../src/config-dir/I18NConfiguration.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EAGlB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,KAAK,uBAAuB,GAAG;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,QAAQ,EAAE,MAAM,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AAE;QACzB,MAAM,EAAE,WAAW,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACjD,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA6B/B;;;OAGG;YACW,iBAAiB;IAyH/B;;OAEG;IACH,OAAO,CAAC,cAAc;CAYvB"}
|
|
@@ -65,12 +65,13 @@ var generaltranslation_1 = require("generaltranslation");
|
|
|
65
65
|
var TranslationManager_1 = __importDefault(require("./TranslationManager"));
|
|
66
66
|
var internal_1 = require("gt-react/internal");
|
|
67
67
|
var createErrors_1 = require("../errors/createErrors");
|
|
68
|
+
var defaultInitGTProps_1 = __importDefault(require("./props/defaultInitGTProps"));
|
|
68
69
|
var I18NConfiguration = /** @class */ (function () {
|
|
69
70
|
function I18NConfiguration(_a) {
|
|
70
71
|
// ----- CLOUD INTEGRATION ----- //
|
|
71
72
|
var
|
|
72
73
|
// Cloud integration
|
|
73
|
-
apiKey = _a.apiKey, devApiKey = _a.devApiKey, projectId = _a.projectId, _versionId = _a._versionId, runtimeUrl = _a.runtimeUrl, cacheUrl = _a.cacheUrl,
|
|
74
|
+
apiKey = _a.apiKey, devApiKey = _a.devApiKey, projectId = _a.projectId, _versionId = _a._versionId, runtimeUrl = _a.runtimeUrl, cacheUrl = _a.cacheUrl, loadTranslationType = _a.loadTranslationType,
|
|
74
75
|
// Locale info
|
|
75
76
|
defaultLocale = _a.defaultLocale, locales = _a.locales,
|
|
76
77
|
// Render method
|
|
@@ -82,30 +83,30 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
82
83
|
// Internal
|
|
83
84
|
_usingPlugin = _a._usingPlugin,
|
|
84
85
|
// Other metadata
|
|
85
|
-
metadata = __rest(_a, ["apiKey", "devApiKey", "projectId", "_versionId", "runtimeUrl", "cacheUrl", "
|
|
86
|
-
this.loadTranslationEnabled = true;
|
|
86
|
+
metadata = __rest(_a, ["apiKey", "devApiKey", "projectId", "_versionId", "runtimeUrl", "cacheUrl", "loadTranslationType", "defaultLocale", "locales", "renderSettings", "dictionary", "maxConcurrentRequests", "maxBatchSize", "batchInterval", "_usingPlugin"]);
|
|
87
87
|
this.apiKey = apiKey;
|
|
88
88
|
this.devApiKey = devApiKey;
|
|
89
89
|
this.projectId = projectId;
|
|
90
90
|
this.runtimeUrl = runtimeUrl;
|
|
91
91
|
this.cacheUrl = cacheUrl;
|
|
92
92
|
this._versionId = _versionId; // version id for the dictionary
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.
|
|
107
|
-
|
|
108
|
-
|
|
93
|
+
// IS BUILDTIME TRANSLATION ENABLED
|
|
94
|
+
this.translationEnabled = !!(loadTranslationType === 'custom' ||
|
|
95
|
+
(loadTranslationType === 'remote' &&
|
|
96
|
+
this.projectId && // projectId required because it's part of the GET request
|
|
97
|
+
this.cacheUrl));
|
|
98
|
+
// IS RUNTIME TRANSLATION ENABLED
|
|
99
|
+
var runtimeApiEnabled = !!(this.runtimeUrl ===
|
|
100
|
+
defaultInitGTProps_1.default.runtimeUrl
|
|
101
|
+
? this.projectId
|
|
102
|
+
: this.runtimeUrl);
|
|
103
|
+
this.developmentApiEnabled = !!(runtimeApiEnabled &&
|
|
104
|
+
this.devApiKey &&
|
|
105
|
+
process.env.NODE_ENV === 'development');
|
|
106
|
+
this.productionApiEnabled = !!(runtimeApiEnabled && this.apiKey);
|
|
107
|
+
// DICTIONARY ENABLED
|
|
108
|
+
this.dictionaryEnabled = _usingPlugin;
|
|
109
|
+
// ----- SETUP ----- //
|
|
109
110
|
// Locales
|
|
110
111
|
this.defaultLocale = defaultLocale;
|
|
111
112
|
this.locales = locales;
|
|
@@ -123,13 +124,9 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
123
124
|
this._translationManager.setConfig({
|
|
124
125
|
cacheUrl: cacheUrl,
|
|
125
126
|
projectId: projectId,
|
|
126
|
-
|
|
127
|
-
loadTranslationEnabled: this.loadTranslationEnabled,
|
|
127
|
+
translationEnabled: this.translationEnabled,
|
|
128
128
|
_versionId: _versionId,
|
|
129
129
|
});
|
|
130
|
-
// Cache of hashes to speed up <GTProvider>
|
|
131
|
-
this._taggedDictionary = new Map();
|
|
132
|
-
this._template = new Map();
|
|
133
130
|
// Batching
|
|
134
131
|
this.maxConcurrentRequests = maxConcurrentRequests;
|
|
135
132
|
this.maxBatchSize = maxBatchSize;
|
|
@@ -138,22 +135,33 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
138
135
|
this._activeRequests = 0;
|
|
139
136
|
this._translationCache = new Map(); // cache for ongoing promises, so things aren't translated twice
|
|
140
137
|
this._startBatching();
|
|
141
|
-
// Internal
|
|
142
|
-
this._usingPlugin = _usingPlugin;
|
|
143
138
|
}
|
|
139
|
+
// ------ CONFIG ----- //
|
|
140
|
+
/**
|
|
141
|
+
* Get the rendering instructions
|
|
142
|
+
* @returns An object containing the current method and timeout.
|
|
143
|
+
* As of 1/22/25: method is "skeleton", "replace", "default".
|
|
144
|
+
* Timeout is a number or null, representing no assigned timeout.
|
|
145
|
+
*/
|
|
146
|
+
I18NConfiguration.prototype.getRenderSettings = function () {
|
|
147
|
+
return this.renderSettings;
|
|
148
|
+
};
|
|
144
149
|
/**
|
|
145
150
|
* Gets config for dynamic translation on the client side.
|
|
146
151
|
*/
|
|
147
152
|
I18NConfiguration.prototype.getClientSideConfig = function () {
|
|
153
|
+
var _a = this, projectId = _a.projectId, translationEnabled = _a.translationEnabled, runtimeUrl = _a.runtimeUrl, devApiKey = _a.devApiKey, developmentApiEnabled = _a.developmentApiEnabled, dictionaryEnabled = _a.dictionaryEnabled, renderSettings = _a.renderSettings;
|
|
148
154
|
return {
|
|
149
|
-
projectId:
|
|
150
|
-
|
|
151
|
-
runtimeUrl:
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
+
projectId: projectId,
|
|
156
|
+
translationEnabled: translationEnabled,
|
|
157
|
+
runtimeUrl: runtimeUrl,
|
|
158
|
+
devApiKey: devApiKey,
|
|
159
|
+
dictionaryEnabled: dictionaryEnabled,
|
|
160
|
+
renderSettings: renderSettings,
|
|
161
|
+
runtimeTranslationEnabled: developmentApiEnabled,
|
|
155
162
|
};
|
|
156
163
|
};
|
|
164
|
+
// ----- LOCALES ----- //
|
|
157
165
|
/**
|
|
158
166
|
* Gets the application's default locale
|
|
159
167
|
* @returns {string} A BCP-47 locale tag
|
|
@@ -168,53 +176,45 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
168
176
|
I18NConfiguration.prototype.getLocales = function () {
|
|
169
177
|
return this.locales;
|
|
170
178
|
};
|
|
179
|
+
// ----- FEATURE FLAGS ----- //
|
|
171
180
|
/**
|
|
172
|
-
* @returns true if
|
|
173
|
-
*/
|
|
174
|
-
I18NConfiguration.prototype.isDictionaryEnabled = function () {
|
|
175
|
-
return this._usingPlugin;
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* @returns A boolean indicating whether automatic translation is enabled or disabled for this config
|
|
181
|
+
* @returns true if build time translation is enabled
|
|
179
182
|
*/
|
|
180
183
|
I18NConfiguration.prototype.isTranslationEnabled = function () {
|
|
181
184
|
return this.translationEnabled;
|
|
182
185
|
};
|
|
183
186
|
/**
|
|
184
|
-
*
|
|
185
|
-
* @returns {boolean} A boolean indicating whether the dev runtime translation is enabled
|
|
187
|
+
* @returns true if dictionaries are enabled
|
|
186
188
|
*/
|
|
187
|
-
I18NConfiguration.prototype.
|
|
188
|
-
return this.
|
|
189
|
+
I18NConfiguration.prototype.isDictionaryEnabled = function () {
|
|
190
|
+
return this.dictionaryEnabled;
|
|
189
191
|
};
|
|
190
192
|
/**
|
|
191
|
-
*
|
|
192
|
-
* @returns {boolean} A boolean indicating whether the client runtime translation is enabled
|
|
193
|
+
* @returns true if development runtime translation API is enabled
|
|
193
194
|
*/
|
|
194
|
-
I18NConfiguration.prototype.
|
|
195
|
-
return this.
|
|
195
|
+
I18NConfiguration.prototype.isDevelopmentApiEnabled = function () {
|
|
196
|
+
return this.developmentApiEnabled;
|
|
196
197
|
};
|
|
197
198
|
/**
|
|
198
|
-
*
|
|
199
|
-
* @returns An object containing the current method and timeout.
|
|
200
|
-
* As of 1/22/25: method is "skeleton", "replace", "default".
|
|
201
|
-
* Timeout is a number or null, representing no assigned timeout.
|
|
199
|
+
* @returns true if production runtime translation API is enabled
|
|
202
200
|
*/
|
|
203
|
-
I18NConfiguration.prototype.
|
|
204
|
-
return this.
|
|
201
|
+
I18NConfiguration.prototype.isProductionApiEnabled = function () {
|
|
202
|
+
return this.productionApiEnabled;
|
|
205
203
|
};
|
|
204
|
+
// ----- UTILITY FUNCTIONS ----- //
|
|
206
205
|
/**
|
|
207
206
|
* Check if translation is required based on the user's locale
|
|
208
207
|
* @param locale - The user's locale
|
|
209
208
|
* @returns True if translation is required, otherwise false
|
|
210
209
|
*/
|
|
211
210
|
I18NConfiguration.prototype.requiresTranslation = function (locale) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return
|
|
211
|
+
if (!this.translationEnabled)
|
|
212
|
+
return [false, false];
|
|
213
|
+
var translationRequired = (0, generaltranslation_1.requiresTranslation)(this.defaultLocale, locale, this.locales);
|
|
214
|
+
var dialectTranslationRequired = translationRequired && (0, generaltranslation_1.isSameLanguage)(locale, this.defaultLocale);
|
|
215
|
+
return [translationRequired, dialectTranslationRequired];
|
|
217
216
|
};
|
|
217
|
+
// ----- CACHED TRANSLATIONS ----- //
|
|
218
218
|
/**
|
|
219
219
|
* Get the translation dictionaries for this user's locale, if they exist
|
|
220
220
|
* Globally shared cache or saved locally
|
|
@@ -233,7 +233,7 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
233
233
|
});
|
|
234
234
|
};
|
|
235
235
|
/**
|
|
236
|
-
*
|
|
236
|
+
* Synchronously retrieves translations for a given locale which are already cached locally
|
|
237
237
|
* @param {string} locale - The locale code.
|
|
238
238
|
* @returns {TranslationsObject} The translations data or an empty object if not found.
|
|
239
239
|
*/
|
|
@@ -241,6 +241,7 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
241
241
|
var _a;
|
|
242
242
|
return ((_a = this._translationManager) === null || _a === void 0 ? void 0 : _a.getRecentTranslations(locale)) || {};
|
|
243
243
|
};
|
|
244
|
+
// ----- RUNTIME TRANSLATION ----- //
|
|
244
245
|
/**
|
|
245
246
|
* Translate content into language associated with a given locale
|
|
246
247
|
* @param params - Parameters for translation
|
|
@@ -279,13 +280,13 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
279
280
|
* @param params - Parameters for translation
|
|
280
281
|
* @returns A promise that resolves when translation is complete
|
|
281
282
|
*/
|
|
282
|
-
I18NConfiguration.prototype.
|
|
283
|
+
I18NConfiguration.prototype.translateJsx = function (params) {
|
|
283
284
|
return __awaiter(this, void 0, void 0, function () {
|
|
284
|
-
var source, targetLocale,
|
|
285
|
+
var source, targetLocale, options, cacheKey, translationPromise;
|
|
285
286
|
var _this = this;
|
|
286
287
|
return __generator(this, function (_a) {
|
|
287
|
-
source = params.source, targetLocale = params.targetLocale,
|
|
288
|
-
cacheKey = constructCacheKey(targetLocale,
|
|
288
|
+
source = params.source, targetLocale = params.targetLocale, options = params.options;
|
|
289
|
+
cacheKey = constructCacheKey(targetLocale, options);
|
|
289
290
|
if (this._translationCache.has(cacheKey)) {
|
|
290
291
|
return [2 /*return*/, this._translationCache.get(cacheKey)];
|
|
291
292
|
}
|
|
@@ -295,12 +296,11 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
295
296
|
type: 'jsx',
|
|
296
297
|
source: source,
|
|
297
298
|
targetLocale: targetLocale,
|
|
298
|
-
metadata:
|
|
299
|
+
metadata: options,
|
|
299
300
|
resolve: resolve,
|
|
300
301
|
reject: reject,
|
|
301
302
|
});
|
|
302
303
|
}).catch(function (error) {
|
|
303
|
-
console.error(error);
|
|
304
304
|
_this._translationCache.delete(cacheKey);
|
|
305
305
|
throw new Error(error);
|
|
306
306
|
});
|
|
@@ -325,7 +325,7 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
325
325
|
case 1:
|
|
326
326
|
_b.trys.push([1, 6, 7, 8]);
|
|
327
327
|
fetchWithAbort = function (url, options, timeout) { return __awaiter(_this, void 0, void 0, function () {
|
|
328
|
-
var controller, timeoutId
|
|
328
|
+
var controller, timeoutId;
|
|
329
329
|
return __generator(this, function (_a) {
|
|
330
330
|
switch (_a.label) {
|
|
331
331
|
case 0:
|
|
@@ -335,19 +335,14 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
335
335
|
: setTimeout(function () { return controller.abort(); }, timeout);
|
|
336
336
|
_a.label = 1;
|
|
337
337
|
case 1:
|
|
338
|
-
_a.trys.push([1, 3, 4
|
|
338
|
+
_a.trys.push([1, , 3, 4]);
|
|
339
339
|
return [4 /*yield*/, fetch(url, __assign(__assign({}, options), { signal: controller.signal }))];
|
|
340
340
|
case 2: return [2 /*return*/, _a.sent()];
|
|
341
341
|
case 3:
|
|
342
|
-
error_2 = _a.sent();
|
|
343
|
-
if (error_2 instanceof Error && error_2.name === 'AbortError')
|
|
344
|
-
throw new Error('Request timed out'); // Handle the timeout case
|
|
345
|
-
throw error_2; // Re-throw other errors
|
|
346
|
-
case 4:
|
|
347
342
|
if (timeoutId !== undefined)
|
|
348
343
|
clearTimeout(timeoutId); // Ensure timeout is cleared
|
|
349
344
|
return [7 /*endfinally*/];
|
|
350
|
-
case
|
|
345
|
+
case 4: return [2 /*return*/];
|
|
351
346
|
}
|
|
352
347
|
});
|
|
353
348
|
}); };
|
|
@@ -415,13 +410,20 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
415
410
|
return [3 /*break*/, 8];
|
|
416
411
|
case 6:
|
|
417
412
|
error_1 = _b.sent();
|
|
418
|
-
|
|
413
|
+
// Error logging
|
|
414
|
+
if (error_1 instanceof Error && error_1.name === 'AbortError') {
|
|
415
|
+
console.warn(createErrors_1.runtimeTranslationTimeoutWarning); // Warning for timeout
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
console.error(error_1);
|
|
419
|
+
}
|
|
420
|
+
// Reject all promises
|
|
419
421
|
batch.forEach(function (request) {
|
|
420
422
|
// record translation error
|
|
421
423
|
if (_this._translationManager) {
|
|
422
424
|
_this._translationManager.setTranslations(request.targetLocale, request.metadata.hash, { state: 'error', error: 'Translation failed.', code: 500 });
|
|
423
425
|
}
|
|
424
|
-
return request.reject(new internal_1.GTTranslationError('Translation failed
|
|
426
|
+
return request.reject(new internal_1.GTTranslationError('Translation failed:' + error_1, 500));
|
|
425
427
|
});
|
|
426
428
|
return [3 /*break*/, 8];
|
|
427
429
|
case 7:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"I18NConfiguration.js","sourceRoot":"","sources":["../../src/config-dir/I18NConfiguration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"I18NConfiguration.js","sourceRoot":"","sources":["../../src/config-dir/I18NConfiguration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAyE;AACzE,4EAA8E;AAC9E,8CAM2B;AAC3B,uDAGgC;AAGhC,kFAA4D;AA2C5D;IAkCE,2BAAY,EAwBc;QACxB,mCAAmC;QAvBnC;QADA,oBAAoB;QACpB,MAAM,YAAA,EACN,SAAS,eAAA,EACT,SAAS,eAAA,EACT,UAAU,gBAAA,EACV,UAAU,gBAAA,EACV,QAAQ,cAAA,EACR,mBAAmB,yBAAA;QACnB,cAAc;QACd,aAAa,mBAAA,EACb,OAAO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ject, TranslationLoading, TranslationError, TranslationSu
|
|
|
4
4
|
* @typedef {object} TranslationManagerConfig
|
|
5
5
|
* @property {string} cacheUrl - The URL of the remote cache.
|
|
6
6
|
* @property {string} projectId - The project identifier for translations.
|
|
7
|
-
* @property {number} [cacheExpiryTime=60000] - The cache expiration time in milliseconds.
|
|
8
7
|
*/
|
|
9
8
|
export type TranslationManagerConfig = {
|
|
10
9
|
cacheUrl?: string | null;
|
|
11
10
|
projectId?: string;
|
|
12
|
-
cacheExpiryTime?: number;
|
|
13
11
|
_versionId?: string;
|
|
14
|
-
|
|
12
|
+
translationEnabled: boolean;
|
|
15
13
|
};
|
|
16
14
|
/**
|
|
17
15
|
* Manages remote translations.
|
|
@@ -21,7 +19,6 @@ export declare class TranslationManager {
|
|
|
21
19
|
private translationsMap;
|
|
22
20
|
private fetchPromises;
|
|
23
21
|
private requestedTranslations;
|
|
24
|
-
private lastFetchTime;
|
|
25
22
|
/**
|
|
26
23
|
* Creates an instance of TranslationManager.
|
|
27
24
|
* @constructor
|
|
@@ -38,31 +35,23 @@ export declare class TranslationManager {
|
|
|
38
35
|
* @returns {Promise<TranslationsObject | undefined>} The fetched translations or undefined if not found.
|
|
39
36
|
*/
|
|
40
37
|
private _fetchTranslations;
|
|
41
|
-
/**
|
|
42
|
-
* Checks if translations are expired based on the configured TTL.
|
|
43
|
-
* @param {string} reference - The translation reference.
|
|
44
|
-
* @returns {boolean} True if expired, false otherwise.
|
|
45
|
-
*/
|
|
46
|
-
private _isExpired;
|
|
47
38
|
/**
|
|
48
39
|
* Retrieves translations for a given locale from the remote or local cache.
|
|
49
40
|
* @param {string} locale - The locale code.
|
|
50
|
-
* @returns {Promise<TranslationsObject | undefined>} The translations data or
|
|
41
|
+
* @returns {Promise<TranslationsObject | undefined>} The translations data or undefined if not found.
|
|
51
42
|
*/
|
|
52
43
|
getCachedTranslations(locale: string): Promise<TranslationsObject | undefined>;
|
|
53
44
|
/**
|
|
54
|
-
* Retrieves translations for a given locale which are already cached locally
|
|
45
|
+
* Retrieves translations for a given locale which are already cached locally.
|
|
55
46
|
* @param {string} locale - The locale code.
|
|
56
|
-
* @returns {
|
|
47
|
+
* @returns {TranslationsObject | undefined} The translations data or undefined if not found.
|
|
57
48
|
*/
|
|
58
49
|
getRecentTranslations(locale: string): TranslationsObject | undefined;
|
|
59
50
|
/**
|
|
60
51
|
* Sets a new translation entry.
|
|
61
52
|
* @param {string} locale - The locale code.
|
|
62
53
|
* @param {string} hash - The key for the new entry.
|
|
63
|
-
* @param {
|
|
64
|
-
* @param {any} translation - The translation value.
|
|
65
|
-
* @param {boolean} [isRuntimeTranslation=true] - Whether the translation was a runtime translation.
|
|
54
|
+
* @param {TranslationSuccess | TranslationLoading | TranslationError} translation - The translation value.
|
|
66
55
|
* @returns {boolean} True if the entry was set successfully, false otherwise.
|
|
67
56
|
*/
|
|
68
57
|
setTranslations(locale: string, hash: string, translation: TranslationSuccess | TranslationLoading | TranslationError): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TranslationManager.d.ts","sourceRoot":"","sources":["../../src/config-dir/TranslationManager.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAG3B
|
|
1
|
+
{"version":3,"file":"TranslationManager.d.ts","sourceRoot":"","sources":["../../src/config-dir/TranslationManager.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAG3B;;;;;GAKG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,eAAe,CAAkC;IACzD,OAAO,CAAC,aAAa,CAAuD;IAC5E,OAAO,CAAC,qBAAqB,CAAuB;IAEpD;;;OAGG;;IAaH;;;OAGG;IACH,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,IAAI;IAI7D;;;;OAIG;YACW,kBAAkB;IAahC;;;;OAIG;IACG,qBAAqB,CACzB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;IA2B1C;;;;OAIG;IACH,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAKrE;;;;;;OAMG;IACH,eAAe,CACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,kBAAkB,GAAG,kBAAkB,GAAG,gBAAgB,GACtE,OAAO;IAWV;;;OAGG;IACH,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK7C;;;;OAIG;IACH,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;CAIjD;AAED,QAAA,MAAM,kBAAkB,oBAA2B,CAAC;AACpD,eAAe,kBAAkB,CAAC"}
|