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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientProvider.js","sourceRoot":"","sources":["../../src/provider/ClientProvider.tsx"],"names":[],"mappings":";AAAA,YAAY,
|
|
1
|
+
{"version":3,"file":"ClientProvider.js","sourceRoot":"","sources":["../../src/provider/ClientProvider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;AAgBb,iCAkIC;;AAhJD,+BAEe;AACf,0CAEyB;AACzB,8CA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,gCAAqB,EAAC;oBAChD,QAAQ,EAAE,KAAK;oBACf,SAAS,WAAA;oBACT,gBAAgB,kBAAA;oBAChB,aAAa,eAAA;oBACb,cAAc,0BAAA;iBACf,CAAC,CAAC;YACL,CAAC;YACD,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC;gBACjC,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,aAAa,CAAC;YAC1D,CAAC;YACD,OAAO,CACL,uBAAC,wBAAc,IACb,OAAO,EAAE,WAAW,CAAC,OAAO,EAC5B,iBAAiB,EAAE,iBAAiB,EACpC,aAAa,EAAE,WAAW,CAAC,aAAa,EACxC,eAAe,EAAE,WAAW,CAAC,eAAe,GAC5C,CACH,CAAC;QACJ,CAAC;QAED,OAAO,iBAAiB,CAAC,WAAW,CAAC,CAAC;IACxC,CAAC,EACD,CAAC,UAAU,EAAE,YAAY,CAAC,CAC3B,CAAC;IAEF,OAAO,CACL,uBAAC,kBAAS,CAAC,QAAQ,IACjB,KAAK,EAAE;YACL,SAAS,WAAA;YACT,MAAM,QAAA;YACN,aAAa,eAAA;YACb,YAAY,cAAA;YACZ,mBAAmB,qBAAA;SACpB,YAEA,QAAQ,GACU,CACtB,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode } from
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* Provides General Translation context to its children, which can then access `useGT`, `useLocale`, and `useDefaultLocale`.
|
|
4
4
|
*
|
|
@@ -6,8 +6,8 @@ import { ReactNode } from "react";
|
|
|
6
6
|
* @param {string} id - ID of a nested dictionary, so that only a subset of a large dictionary needs to be sent to the client.
|
|
7
7
|
*
|
|
8
8
|
* @returns {JSX.Element} The provider component for General Translation context.
|
|
9
|
-
*/
|
|
10
|
-
export default function GTProvider({ children, id }: {
|
|
9
|
+
*/
|
|
10
|
+
export default function GTProvider({ children, id, }: {
|
|
11
11
|
children?: ReactNode;
|
|
12
12
|
id?: string;
|
|
13
13
|
}): Promise<import("react/jsx-runtime").JSX.Element>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GTProvider.d.ts","sourceRoot":"","sources":["../../src/provider/GTProvider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GTProvider.d.ts","sourceRoot":"","sources":["../../src/provider/GTProvider.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAWlC;;;;;;;GAOG;AACH,wBAA8B,UAAU,CAAC,EACvC,QAAQ,EACR,EAAE,GACH,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,oDA+HA"}
|
|
@@ -75,7 +75,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
75
75
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
76
|
exports.default = GTProvider;
|
|
77
77
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
78
|
-
//
|
|
79
78
|
var react_1 = __importDefault(require("react"));
|
|
80
79
|
var internal_1 = require("gt-react/internal");
|
|
81
80
|
var getI18NConfig_1 = __importDefault(require("../utils/getI18NConfig"));
|
|
@@ -83,8 +82,9 @@ var getLocale_1 = __importDefault(require("../request/getLocale"));
|
|
|
83
82
|
var getMetadata_1 = __importDefault(require("../request/getMetadata"));
|
|
84
83
|
var generaltranslation_1 = require("generaltranslation");
|
|
85
84
|
var getDictionary_1 = __importStar(require("../dictionary/getDictionary"));
|
|
86
|
-
var
|
|
85
|
+
var internal_2 = require("gt-react/internal");
|
|
87
86
|
var ClientProvider_1 = __importDefault(require("./ClientProvider"));
|
|
87
|
+
var renderVariable_1 = __importDefault(require("../server/rendering/renderVariable"));
|
|
88
88
|
/**
|
|
89
89
|
* Provides General Translation context to its children, which can then access `useGT`, `useLocale`, and `useDefaultLocale`.
|
|
90
90
|
*
|
|
@@ -92,102 +92,111 @@ var ClientProvider_1 = __importDefault(require("./ClientProvider"));
|
|
|
92
92
|
* @param {string} id - ID of a nested dictionary, so that only a subset of a large dictionary needs to be sent to the client.
|
|
93
93
|
*
|
|
94
94
|
* @returns {JSX.Element} The provider component for General Translation context.
|
|
95
|
-
*/
|
|
95
|
+
*/
|
|
96
96
|
function GTProvider(_a) {
|
|
97
97
|
return __awaiter(this, arguments, void 0, function (_b) {
|
|
98
|
-
var
|
|
98
|
+
var getID, I18NConfig, locale, additionalMetadata, defaultLocale, renderSettings, translationRequired, translationsPromise, dictionaryEntries, dictionary, translations, existingTranslations, _c, _d;
|
|
99
99
|
var _this = this;
|
|
100
100
|
var children = _b.children, id = _b.id;
|
|
101
|
-
return __generator(this, function (
|
|
102
|
-
switch (
|
|
101
|
+
return __generator(this, function (_e) {
|
|
102
|
+
switch (_e.label) {
|
|
103
103
|
case 0:
|
|
104
|
-
I18NConfig = (0, getI18NConfig_1.default)();
|
|
105
104
|
getID = function (suffix) {
|
|
106
105
|
return id ? "".concat(id, ".").concat(suffix) : suffix;
|
|
107
106
|
};
|
|
107
|
+
I18NConfig = (0, getI18NConfig_1.default)();
|
|
108
108
|
return [4 /*yield*/, (0, getLocale_1.default)()];
|
|
109
109
|
case 1:
|
|
110
|
-
locale =
|
|
110
|
+
locale = _e.sent();
|
|
111
111
|
return [4 /*yield*/, (0, getMetadata_1.default)()];
|
|
112
112
|
case 2:
|
|
113
|
-
additionalMetadata =
|
|
113
|
+
additionalMetadata = _e.sent();
|
|
114
114
|
defaultLocale = I18NConfig.getDefaultLocale();
|
|
115
115
|
renderSettings = I18NConfig.getRenderSettings();
|
|
116
|
+
translationRequired = I18NConfig.requiresTranslation(locale);
|
|
117
|
+
if (translationRequired)
|
|
118
|
+
translationsPromise = I18NConfig.getTranslations(locale);
|
|
119
|
+
dictionaryEntries = (0, internal_1.flattenDictionary)(id ? (0, getDictionary_1.getDictionaryEntry)(id) : (0, getDictionary_1.default)());
|
|
116
120
|
dictionary = {};
|
|
117
121
|
translations = {};
|
|
118
|
-
|
|
119
|
-
if (!
|
|
120
|
-
|
|
122
|
+
existingTranslations = {};
|
|
123
|
+
if (!translationsPromise) return [3 /*break*/, 4];
|
|
124
|
+
_d = (_c = Object).entries;
|
|
125
|
+
return [4 /*yield*/, translationsPromise];
|
|
121
126
|
case 3:
|
|
122
|
-
_c
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
case
|
|
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
|
-
|
|
127
|
+
_d.apply(_c, [_e.sent()]).map(function (_a) {
|
|
128
|
+
var id = _a[0], t = _a[1].t;
|
|
129
|
+
return existingTranslations[id] = t;
|
|
130
|
+
});
|
|
131
|
+
_e.label = 4;
|
|
132
|
+
case 4:
|
|
133
|
+
// Check and standardize flattened dictionary entries before passing them to the client
|
|
134
|
+
return [4 /*yield*/, Promise.all(Object.entries(dictionaryEntries).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
135
|
+
var entryID, _c, entry, metadata, taggedEntry, _d, entryAsObjects, key, translation, translationPromise_1, _e, _f, translationPromise, loadingFallback, errorFallback;
|
|
136
|
+
var suffix = _b[0], dictionaryEntry = _b[1];
|
|
137
|
+
return __generator(this, function (_g) {
|
|
138
|
+
switch (_g.label) {
|
|
139
|
+
case 0:
|
|
140
|
+
entryID = getID(suffix);
|
|
141
|
+
_c = (0, internal_1.extractEntryMetadata)(dictionaryEntry), entry = _c.entry, metadata = _c.metadata;
|
|
142
|
+
if (typeof entry === 'undefined')
|
|
143
|
+
return [2 /*return*/];
|
|
144
|
+
// If entry is a function, execute it
|
|
145
|
+
if (typeof entry === 'function') {
|
|
146
|
+
entry = entry({});
|
|
147
|
+
metadata = __assign(__assign({}, metadata), { isFunction: true });
|
|
148
|
+
}
|
|
149
|
+
taggedEntry = I18NConfig.addGTIdentifier(children, id);
|
|
150
|
+
// Set dictionary entry to be passed to the client
|
|
151
|
+
dictionary[entryID] = [taggedEntry, metadata];
|
|
152
|
+
// If no translation is required, return
|
|
153
|
+
if (!translationRequired)
|
|
154
|
+
return [2 /*return*/];
|
|
155
|
+
_d = I18NConfig.serializeAndHash(taggedEntry, metadata === null || metadata === void 0 ? void 0 : metadata.context, entryID), entryAsObjects = _d[0], key = _d[1];
|
|
156
|
+
translation = existingTranslations === null || existingTranslations === void 0 ? void 0 : existingTranslations[entryID];
|
|
157
|
+
if (translation && translation.k === key) {
|
|
158
|
+
return [2 /*return*/, (translations[entryID] = translation)];
|
|
159
|
+
}
|
|
160
|
+
if (!(typeof taggedEntry === 'string')) return [3 /*break*/, 3];
|
|
161
|
+
translationPromise_1 = I18NConfig.translate({
|
|
162
|
+
content: (0, generaltranslation_1.splitStringToContent)(taggedEntry),
|
|
163
|
+
targetLocale: locale,
|
|
164
|
+
options: __assign({ id: entryID, hash: key }, additionalMetadata),
|
|
165
|
+
});
|
|
166
|
+
if (!(renderSettings.method !== "subtle")) return [3 /*break*/, 2];
|
|
167
|
+
_e = translations;
|
|
168
|
+
_f = entryID;
|
|
169
|
+
return [4 /*yield*/, translationPromise_1];
|
|
170
|
+
case 1: return [2 /*return*/, _e[_f] = _g.sent()];
|
|
171
|
+
case 2: return [2 /*return*/, undefined];
|
|
172
|
+
case 3:
|
|
173
|
+
;
|
|
174
|
+
translationPromise = I18NConfig.translateChildren({
|
|
175
|
+
children: entryAsObjects,
|
|
176
|
+
targetLocale: locale,
|
|
177
|
+
metadata: __assign(__assign({ id: entryID, hash: key }, additionalMetadata), (renderSettings.timeout && { timeout: renderSettings.timeout })),
|
|
178
|
+
});
|
|
179
|
+
if (renderSettings.method === 'skeleton') {
|
|
180
|
+
loadingFallback = (0, jsx_runtime_1.jsx)(react_1.default.Fragment, {}, "skeleton_".concat(entryID));
|
|
181
|
+
}
|
|
182
|
+
else if (renderSettings.method === 'replace') {
|
|
183
|
+
loadingFallback = (0, internal_2.renderDefaultChildren)({
|
|
184
|
+
children: taggedEntry,
|
|
185
|
+
defaultLocale: defaultLocale,
|
|
186
|
+
renderVariable: renderVariable_1.default
|
|
171
187
|
});
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
errorFallback: errorFallback
|
|
185
|
-
}];
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}); }))];
|
|
189
|
-
case 6:
|
|
190
|
-
_d.sent();
|
|
188
|
+
}
|
|
189
|
+
return [2 /*return*/, (translations[entryID] = {
|
|
190
|
+
promise: translationPromise,
|
|
191
|
+
loadingFallback: loadingFallback,
|
|
192
|
+
errorFallback: errorFallback,
|
|
193
|
+
})];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}); }))];
|
|
197
|
+
case 5:
|
|
198
|
+
// Check and standardize flattened dictionary entries before passing them to the client
|
|
199
|
+
_e.sent();
|
|
191
200
|
return [2 /*return*/, ((0, jsx_runtime_1.jsx)(ClientProvider_1.default, { dictionary: dictionary, translations: __assign(__assign({}, existingTranslations), translations), locale: locale, defaultLocale: defaultLocale, translationRequired: translationRequired, children: children }))];
|
|
192
201
|
}
|
|
193
202
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GTProvider.js","sourceRoot":"","sources":["../../src/provider/GTProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"GTProvider.js","sourceRoot":"","sources":["../../src/provider/GTProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,6BAqIC;;AA7JD,gDAA0B;AAC1B,8CAG2B;AAE3B,yEAAmD;AACnD,mEAA6C;AAC7C,uEAAiD;AACjD,yDAA0D;AAC1D,2EAAgF;AAChF,8CAA0D;AAC1D,oEAA8C;AAE9C,sFAAgE;AAEhE;;;;;;;GAOG;AACH,SAA8B,UAAU;wDAAC,EAMxC;;;YALC,QAAQ,cAAA,EACR,EAAE,QAAA;;;;oBAMI,KAAK,GAAG,UAAC,MAAc;wBAC3B,OAAO,EAAE,CAAC,CAAC,CAAC,UAAG,EAAE,cAAI,MAAM,CAAE,CAAC,CAAC,CAAC,MAAM,CAAC;oBACzC,CAAC,CAAC;oBAEI,UAAU,GAAG,IAAA,uBAAa,GAAE,CAAC;oBACpB,qBAAM,IAAA,mBAAS,GAAE,EAAA;;oBAA1B,MAAM,GAAG,SAAiB;oBACL,qBAAM,IAAA,qBAAW,GAAE,EAAA;;oBAAxC,kBAAkB,GAAG,SAAmB;oBACxC,aAAa,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC;oBAC9C,cAAc,GAAG,UAAU,CAAC,iBAAiB,EAAE,CAAC;oBAChD,mBAAmB,GAAG,UAAU,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;oBAGnE,IAAI,mBAAmB;wBAAE,mBAAmB,GAAG,UAAU,CAAC,eAAe,CAAC,MAAM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,OAAO,EAAE,cAAc,CAAC,OAAO,EAAE,CAAC,CACnE;qCACF,CAAC,CAAC;oCAKH,IAAI,cAAc,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;wCACzC,eAAe,GAAG,uBAAC,eAAK,CAAC,QAAQ,MAAM,mBAAY,OAAO,CAAE,CAAI,CAAC;oCACnE,CAAC;yCAAM,IAAI,cAAc,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;wCAC/C,eAAe,GAAG,IAAA,gCAAqB,EAAC;4CACtC,QAAQ,EAAE,WAAW;4CACrB,aAAa,eAAA;4CAAE,cAAc,0BAAA;yCAC9B,CAAC,CAAC;oCACL,CAAC;oCAED,sBAAO,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG;4CAC9B,OAAO,EAAE,kBAAkB;4CAC3B,eAAe,iBAAA;4CACf,aAAa,eAAA;yCACd,CAAC,EAAC;;;yBACJ,CAAC,CACH,EAAA;;oBApFD,uFAAuF;oBACvF,SAmFC,CAAC;oBAEF,sBAAO,CACL,uBAAC,wBAAc,IACb,UAAU,EAAE,UAAU,EACtB,YAAY,wBAAO,oBAAoB,GAAK,YAAY,GACxD,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,aAAa,EAC5B,mBAAmB,EAAE,mBAAmB,YAEvC,QAAQ,GACM,CAClB,EAAC;;;;CACH"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
export type ClientDictionaryEntry = ReactNode;
|
|
3
|
+
export type ClientDictionaryEntryWithOptionalMetadata = ClientDictionaryEntry | [ClientDictionaryEntry, {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
isFunction?: boolean;
|
|
6
|
+
}];
|
|
7
|
+
export type ClientDictionary = {
|
|
8
|
+
[key: string]: ClientDictionaryEntryWithOptionalMetadata;
|
|
9
|
+
};
|
|
10
|
+
export type ClientTranslations = {
|
|
11
|
+
[key: string]: any | // a translation
|
|
12
|
+
string | {
|
|
13
|
+
promise: Promise<any>;
|
|
14
|
+
loadingFallback: any;
|
|
15
|
+
errorFallback: any;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/provider/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjC,MAAM,MAAM,qBAAqB,GAAG,SAAS,CAAA;AAE7C,MAAM,MAAM,yCAAyC,GACjD,qBAAqB,GAAG,CAAC,qBAAqB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAAA;AAEjG,MAAM,MAAM,gBAAgB,GAAG;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,yCAAyC,CAAA;CAC3D,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC7B,CAAC,GAAG,EAAE,MAAM,GACR,GAAG,GAAG,gBAAgB;IACtB,MAAM,GACN;QACI,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QACtB,eAAe,EAAE,GAAG,CAAC;QACrB,aAAa,EAAE,GAAG,CAAA;KACrB,CAAA;CACR,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/provider/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.d.ts","sourceRoot":"","sources":["../../src/request/getLocale.ts"],"names":[],"mappings":"AAKA;;;;;;;;
|
|
1
|
+
{"version":3,"file":"getLocale.d.ts","sourceRoot":"","sources":["../../src/request/getLocale.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,wBAA8B,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAmBzD"}
|
|
@@ -51,7 +51,7 @@ var getLocaleFunction;
|
|
|
51
51
|
* @example
|
|
52
52
|
* const locale = await getLocale();
|
|
53
53
|
* console.log(locale); // 'en-US'
|
|
54
|
-
*/
|
|
54
|
+
*/
|
|
55
55
|
function getLocale() {
|
|
56
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
57
57
|
var customRequestConfig, customGetLocale, locale, _a, I18NConfig_1;
|
|
@@ -85,9 +85,7 @@ function getLocale() {
|
|
|
85
85
|
}); };
|
|
86
86
|
return [4 /*yield*/, getLocaleFunction()];
|
|
87
87
|
case 5: return [2 /*return*/, _c.sent()];
|
|
88
|
-
case 6:
|
|
89
|
-
;
|
|
90
|
-
return [2 /*return*/];
|
|
88
|
+
case 6: return [2 /*return*/];
|
|
91
89
|
}
|
|
92
90
|
});
|
|
93
91
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.js","sourceRoot":"","sources":["../../src/request/getLocale.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,
|
|
1
|
+
{"version":3,"file":"getLocale.js","sourceRoot":"","sources":["../../src/request/getLocale.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,4BAmBC;AAjCD,yEAAmD;AACnD,uDAAsD;AAEtD,IAAI,iBAAwC,CAAC;AAE7C;;;;;;;;GAQG;AACH,SAA8B,SAAS;;;;;;;;yBACjC,iBAAiB,EAAjB,wBAAiB;oBAAS,qBAAM,iBAAiB,EAAE,EAAA;wBAAhC,sBAAO,SAAyB,EAAC;;;oBAGhD,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;oBAClD,eAAe,GACnB,CAAA,MAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,OAAO,0CAAE,SAAS,KAAI,mBAAmB,CAAC,SAAS,CAAC;oBAC5D,qBAAM,eAAe,EAAE,EAAA;;oBAAhC,MAAM,GAAG,SAAuB;oBACtC,iBAAiB,GAAG,eAAe,CAAC;oBACpC,sBAAO,MAAM,EAAC;;;oBAER,eAAa,IAAA,uBAAa,GAAE,CAAC;oBACnC,iBAAiB,GAAG;;;wCAClB,qBAAM,IAAA,6BAAa,EACjB,YAAU,CAAC,gBAAgB,EAAE,EAC7B,YAAU,CAAC,UAAU,EAAE,CACxB,EAAA;wCAHD,sBAAA,SAGC,EAAA;;;yBAAA,CAAC;oBACG,qBAAM,iBAAiB,EAAE,EAAA;wBAAhC,sBAAO,SAAyB,EAAC;;;;;CAEpC"}
|
|
@@ -51,8 +51,10 @@ function createServerTFunction(prefixID) {
|
|
|
51
51
|
}
|
|
52
52
|
if (typeof entry === 'string') {
|
|
53
53
|
return (0, tx_1.default)(entry, {
|
|
54
|
-
id: id
|
|
55
|
-
|
|
54
|
+
id: id,
|
|
55
|
+
variables: variables,
|
|
56
|
+
variablesOptions: variablesOptions
|
|
57
|
+
});
|
|
56
58
|
}
|
|
57
59
|
return ((0, jsx_runtime_1.jsx)(T_1.default, __assign({ id: id, variables: variables, variablesOptions: variablesOptions }, metadata, { children: entry })));
|
|
58
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServerTFunction.js","sourceRoot":"","sources":["../../src/server/createServerTFunction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAKA,wCA+DC;;AApED,8CAA6E;AAC7E,iDAA2B;AAC3B,8EAAwD;AACxD,oDAA8B;AAE9B,SAAwB,qBAAqB,CACzC,QAAiB;IAGjB,IAAM,KAAK,GAAG,UAAC,EAAU;QACrB,OAAO,QAAQ,CAAC,CAAC,CAAC,UAAG,QAAQ,cAAI,EAAE,CAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/C,CAAC,CAAA;IAED,IAAM,UAAU,GAAG,IAAA,uBAAa,GAAE,CAAC;IAEnC,OAAO,UACH,EAAU,EACV,OAA6B,EAC7B,CAAY;QAGZ,EAAE,GAAG,KAAK,CAAC,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AAS,EACpB,gBAAgB,EAAE,gBAAgB,IAC9B,QAAQ,cAEX,KAAK,IACN,CACP,CAAA;IAEL,CAAC,CAAA;AAEL,CAAC"}
|
package/dist/server/getGT.d.ts
CHANGED
|
@@ -11,5 +11,20 @@
|
|
|
11
11
|
* const t = getGT();
|
|
12
12
|
* console.log(t('hello')); // Translates item 'hello'
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
14
|
+
export declare function getGT(id?: string): (id: string, options?: Record<string, any>, f?: Function) => JSX.Element | Promise<string> | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the translation function `t`, which is used to translate a JSX element from the dictionary.
|
|
17
|
+
* For translating strings directly, see `getGT()` or `useGT()`.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} [id] - Optional prefix to prepend to the translation keys.
|
|
20
|
+
* @returns {Function} A translation function that accepts a key string and returns the translated value.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const t = gt('user');
|
|
24
|
+
* console.log(t('name')); // Translates item 'user.name'
|
|
25
|
+
*
|
|
26
|
+
* const t = gt();
|
|
27
|
+
* console.log(t('hello')); // Translates item 'hello'
|
|
28
|
+
*/
|
|
29
|
+
export declare function gt(id?: string): (id: string, options?: Record<string, any>, f?: Function) => JSX.Element;
|
|
15
30
|
//# sourceMappingURL=getGT.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getGT.d.ts","sourceRoot":"","sources":["../../src/server/getGT.
|
|
1
|
+
{"version":3,"file":"getGT.d.ts","sourceRoot":"","sources":["../../src/server/getGT.tsx"],"names":[],"mappings":"AAKA;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,CAChC,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,CAAC,CAAC,EAAE,QAAQ,KACX,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,SAAS,CA0D7C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,CAC7B,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,CAAC,CAAC,EAAE,QAAQ,KACX,GAAG,CAAC,OAAO,CA8Df"}
|
package/dist/server/getGT.js
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
17
|
+
exports.getGT = getGT;
|
|
18
|
+
exports.gt = gt;
|
|
19
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
20
|
+
var internal_1 = require("gt-react/internal");
|
|
21
|
+
var T_1 = __importDefault(require("./inline/T"));
|
|
22
|
+
var getDictionary_1 = require("../dictionary/getDictionary");
|
|
23
|
+
var tx_1 = __importDefault(require("./strings/tx"));
|
|
8
24
|
/**
|
|
9
25
|
* Gets the translation function `t`, which is used to translate an item from the dictionary.
|
|
10
26
|
*
|
|
@@ -19,19 +35,96 @@ var createServerTFunction_1 = __importDefault(require("./createServerTFunction")
|
|
|
19
35
|
* console.log(t('hello')); // Translates item 'hello'
|
|
20
36
|
*/
|
|
21
37
|
function getGT(id) {
|
|
22
|
-
var
|
|
38
|
+
var getID = function (suffix) {
|
|
39
|
+
return id ? "".concat(id, ".").concat(suffix) : suffix;
|
|
40
|
+
};
|
|
41
|
+
return function (id, options, f) {
|
|
42
|
+
id = getID(id);
|
|
43
|
+
// Get entry
|
|
44
|
+
var _a = (0, internal_1.extractEntryMetadata)((0, getDictionary_1.getDictionaryEntry)(id)), entry = _a.entry, metadata = _a.metadata;
|
|
45
|
+
// Get variables and variable options
|
|
46
|
+
var variables;
|
|
47
|
+
var variablesOptions;
|
|
48
|
+
if (options) {
|
|
49
|
+
variables = options;
|
|
50
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.variablesOptions) {
|
|
51
|
+
variablesOptions = metadata.variablesOptions;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Handle if the entry is a function
|
|
55
|
+
if (typeof f === 'function') {
|
|
56
|
+
entry = f(options);
|
|
57
|
+
}
|
|
58
|
+
else if (typeof entry === 'function') {
|
|
59
|
+
entry = entry(options);
|
|
60
|
+
}
|
|
61
|
+
if (!entry) {
|
|
62
|
+
console.warn("No entry found for id: \"".concat(id, "\""));
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
if (typeof entry === 'string') {
|
|
66
|
+
return (0, tx_1.default)(entry, {
|
|
67
|
+
id: id,
|
|
68
|
+
variables: variables,
|
|
69
|
+
variablesOptions: variablesOptions
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return ((0, jsx_runtime_1.jsx)(T_1.default, __assign({ id: id, variables: variables, variablesOptions: variablesOptions }, metadata, { children: entry })));
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Gets the translation function `t`, which is used to translate a JSX element from the dictionary.
|
|
77
|
+
* For translating strings directly, see `getGT()` or `useGT()`.
|
|
78
|
+
*
|
|
79
|
+
* @param {string} [id] - Optional prefix to prepend to the translation keys.
|
|
80
|
+
* @returns {Function} A translation function that accepts a key string and returns the translated value.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* const t = gt('user');
|
|
84
|
+
* console.log(t('name')); // Translates item 'user.name'
|
|
85
|
+
*
|
|
86
|
+
* const t = gt();
|
|
87
|
+
* console.log(t('hello')); // Translates item 'hello'
|
|
88
|
+
*/
|
|
89
|
+
function gt(id) {
|
|
90
|
+
var getID = function (suffix) {
|
|
91
|
+
return id ? "".concat(id, ".").concat(suffix) : suffix;
|
|
92
|
+
};
|
|
23
93
|
/**
|
|
24
|
-
* Translates a dictionary item based on its `id` and options.
|
|
94
|
+
* Translates a dictionary item based on its `id` and options, ensuring that it is a JSX element.
|
|
25
95
|
*
|
|
26
96
|
* @param {string} [id] - The ID of the item in the dictionary to translate.
|
|
27
97
|
* @param {Record<string, any>} [options={}] - Variables or parameters (e.g., `n`) passed into the translation for dynamic content.
|
|
28
98
|
* @param {Function} [f] - Advanced feature. `f` is executed with `options` as parameters, and its result is translated based on the dictionary value of `id`. You likely don't need this parameter unless you using `getGT` on the client-side.
|
|
29
99
|
*
|
|
30
|
-
* @returns {
|
|
100
|
+
* @returns {JSX.Element}
|
|
31
101
|
*/
|
|
32
102
|
function t(id, options, f) {
|
|
33
103
|
if (options === void 0) { options = {}; }
|
|
34
|
-
|
|
104
|
+
id = getID(id);
|
|
105
|
+
// Get entry
|
|
106
|
+
var _a = (0, internal_1.extractEntryMetadata)((0, getDictionary_1.getDictionaryEntry)(id)), entry = _a.entry, metadata = _a.metadata;
|
|
107
|
+
// Get variables and variable options
|
|
108
|
+
var variables;
|
|
109
|
+
var variablesOptions;
|
|
110
|
+
if (options) {
|
|
111
|
+
variables = options;
|
|
112
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.variablesOptions) {
|
|
113
|
+
variablesOptions = metadata.variablesOptions;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Handle if the entry is a function
|
|
117
|
+
if (typeof f === 'function') {
|
|
118
|
+
entry = f(options);
|
|
119
|
+
}
|
|
120
|
+
else if (typeof entry === 'function') {
|
|
121
|
+
entry = entry(options);
|
|
122
|
+
}
|
|
123
|
+
if (!entry) {
|
|
124
|
+
console.warn("No entry found for id: \"".concat(id, "\""));
|
|
125
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
|
|
126
|
+
}
|
|
127
|
+
return ((0, jsx_runtime_1.jsx)(T_1.default, __assign({ id: id, variables: variables, variablesOptions: variablesOptions }, metadata, { children: entry })));
|
|
35
128
|
}
|
|
36
129
|
return t;
|
|
37
130
|
}
|
package/dist/server/getGT.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getGT.js","sourceRoot":"","sources":["../../src/server/getGT.
|
|
1
|
+
{"version":3,"file":"getGT.js","sourceRoot":"","sources":["../../src/server/getGT.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAkBA,sBA8DC;AAgBD,gBAkEC;;AAlKD,8CAAyD;AACzD,iDAA2B;AAC3B,6DAAiE;AACjE,oDAA8B;AAE9B;;;;;;;;;;;;GAYG;AACH,SAAgB,KAAK,CAAC,EAAW;IAM7B,IAAM,KAAK,GAAG,UAAC,MAAc;QACzB,OAAO,EAAE,CAAC,CAAC,CAAC,UAAG,EAAE,cAAI,MAAM,CAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC3C,CAAC,CAAA;IAED,OAAO,UACH,EAAU,EACV,OAA6B,EAC7B,CAAY;QAGZ,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;QAEf,YAAY;QACR,IAAA,KAAsB,IAAA,+BAAoB,EAC1C,IAAA,kCAAkB,EAAC,EAAE,CAAC,CACzB,EAFK,KAAK,WAAA,EAAE,QAAQ,cAEpB,CAAC;QAEF,qCAAqC;QACrC,IAAI,SAAS,CAAC;QAAC,IAAI,gBAAgB,CAAC;QACpC,IAAI,OAAO,EAAE,CAAC;YACV,SAAS,GAAG,OAAO,CAAC;YACpB,I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IAAA,KAAsB,IAAA,+BAAoB,EAC1C,IAAA,kCAAkB,EAAC,EAAE,CAAC,CACzB,EAFK,KAAK,WAAA,EAAE,QAAQ,cAEpB,CAAC;QAEF,qCAAqC;QACrC,IAAI,SAAS,CAAC;QAAC,IAAI,gBAAgB,CAAC;QACpC,IAAI,OAAO,EAAE,CAAC;YACV,SAAS,GAAG,OAAO,CAAC;YACpB,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,gBAAgB,EAAE,CAAC;gBAC7B,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC;YACjD,CAAC;QACL,CAAC;QAED,oCAAoC;QACpC,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE,CAAC;YAC1B,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YACrC,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QAED,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,CAAC,mCAA2B,EAAE,OAAG,CAAC,CAAC;YAC/C,OAAO,kDAAK,CAAC;QACjB,CAAC;QAED,OAAO,CACH,uBAAC,WAAC,aACE,EAAE,EAAE,EAAE,EACN,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,gBAAgB,IAC9B,QAAQ,cAEX,KAAK,IACN,CACP,CAAA;IACL,CAAC;IAED,OAAO,CAAC,CAAC;AACb,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
type RenderSettings = {
|
|
2
|
-
method:
|
|
2
|
+
method: 'skeleton' | 'replace' | 'hang' | 'subtle';
|
|
3
3
|
timeout: number | null;
|
|
4
4
|
};
|
|
5
5
|
/**
|
|
6
|
-
* Translation component that renders its children translated into the user's
|
|
6
|
+
* Translation component that renders its children translated into the user's given locale.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```jsx
|
|
@@ -17,7 +17,7 @@ type RenderSettings = {
|
|
|
17
17
|
* ```jsx
|
|
18
18
|
* // Translating a plural
|
|
19
19
|
* <T id="item_count">
|
|
20
|
-
* <Plural n={3} singular={<>You have <Num value={n}/> item
|
|
20
|
+
* <Plural n={3} singular={<>You have <Num value={n}/> item.</>}>
|
|
21
21
|
* You have <Num value={n}/> items.
|
|
22
22
|
* </Plural>
|
|
23
23
|
* </T>
|
|
@@ -45,7 +45,7 @@ type RenderSettings = {
|
|
|
45
45
|
*
|
|
46
46
|
* @throws {Error} If a plural translation is requested but the `n` option is not provided.
|
|
47
47
|
*/
|
|
48
|
-
export default function T({ children, id, context, renderSettings, variables, variablesOptions }: {
|
|
48
|
+
export default function T({ children, id, context, renderSettings, variables, variablesOptions, }: {
|
|
49
49
|
children: any;
|
|
50
50
|
id?: string;
|
|
51
51
|
context?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"T.d.ts","sourceRoot":"","sources":["../../../src/server/inline/T.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"T.d.ts","sourceRoot":"","sources":["../../../src/server/inline/T.tsx"],"names":[],"mappings":"AAQA,KAAK,cAAc,GAAG;IACpB,MAAM,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;IACnD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAA8B,CAAC,CAAC,EAC9B,QAAQ,EACR,EAAE,EACF,OAAO,EACP,cAAc,EACd,SAAS,EACT,gBAAgB,GACjB,EAAE;IACD,QAAQ,EAAE,GAAG,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,GAAG,OAAO,CAAC,GAAG,CAAC,CAkIf"}
|