gt-next 4.2.2 → 4.2.4-beta
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/_dictionary.d.ts.map +1 -0
- package/dist/_dictionary.js.map +1 -0
- package/dist/{types/_request.d.ts.map → _request.d.ts.map} +1 -1
- package/dist/{esm/_request.js.map → _request.js.map} +1 -1
- package/dist/branches/Branch.d.ts.map +1 -0
- package/dist/branches/Branch.js.map +1 -0
- package/dist/branches/Plural.d.ts.map +1 -0
- package/dist/branches/Plural.js.map +1 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js.map +1 -0
- package/dist/config/I18NConfiguration.d.ts.map +1 -0
- package/dist/config/I18NConfiguration.js.map +1 -0
- package/dist/config/RemoteTranslationsManager.d.ts.map +1 -0
- package/dist/config/RemoteTranslationsManager.js.map +1 -0
- package/dist/config/getI18NConfig.d.ts.map +1 -0
- package/dist/config/getI18NConfig.js.map +1 -0
- package/dist/config/props/InitGTProps.d.ts.map +1 -0
- package/dist/config/props/InitGTProps.js.map +1 -0
- package/dist/config/props/defaultInitGTProps.d.ts.map +1 -0
- package/dist/config/props/defaultInitGTProps.js.map +1 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js.map +1 -0
- package/dist/dictionary/getDictionary.d.ts +3 -0
- package/dist/dictionary/getDictionary.d.ts.map +1 -0
- package/dist/dictionary/getDictionary.js.map +1 -0
- package/dist/errors/createErrors.d.ts.map +1 -0
- package/dist/errors/createErrors.js.map +1 -0
- package/dist/index.client.d.ts.map +1 -0
- package/dist/index.client.js.map +1 -0
- package/dist/index.server.d.ts.map +1 -0
- package/dist/index.server.js.map +1 -0
- package/dist/middleware/createNextMiddleware.d.ts.map +1 -0
- package/dist/middleware/createNextMiddleware.js.map +1 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js.map +1 -0
- package/dist/next/getNextDomain.d.ts.map +1 -0
- package/dist/next/getNextDomain.js.map +1 -0
- package/dist/next/getNextLocale.d.ts.map +1 -0
- package/dist/next/getNextLocale.js.map +1 -0
- package/dist/provider/ClientProvider.d.ts.map +1 -0
- package/dist/provider/ClientProvider.js.map +1 -0
- package/dist/provider/GTProvider.d.ts.map +1 -0
- package/dist/provider/GTProvider.js.map +1 -0
- package/dist/request/getLocale.d.ts.map +1 -0
- package/dist/request/getLocale.js.map +1 -0
- package/dist/request/getMetadata.d.ts.map +1 -0
- package/dist/request/getMetadata.js.map +1 -0
- package/dist/{types/server → server}/getGT.d.ts +1 -1
- package/dist/server/getGT.d.ts.map +1 -0
- package/dist/{cjs/server → server}/getGT.js +22 -18
- package/dist/server/getGT.js.map +1 -0
- package/dist/server/inline/Resolver.d.ts.map +1 -0
- package/dist/server/inline/Resolver.js.map +1 -0
- package/dist/server/inline/T.d.ts.map +1 -0
- package/dist/server/inline/T.js.map +1 -0
- package/dist/server/rendering/renderVariable.d.ts.map +1 -0
- package/dist/server/rendering/renderVariable.js.map +1 -0
- package/dist/server/strings/tx.d.ts.map +1 -0
- package/dist/{cjs/server → server}/strings/tx.js +1 -2
- package/dist/server/strings/tx.js.map +1 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js.map +1 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/{esm/types → types}/types.js.map +1 -1
- package/dist/utils/checkTypes.d.ts.map +1 -0
- package/dist/utils/checkTypes.js.map +1 -0
- package/dist/utils/getDefaultFromEnv.d.ts.map +1 -0
- package/dist/utils/getDefaultFromEnv.js.map +1 -0
- package/dist/utils/getGTProp.d.ts.map +1 -0
- package/dist/utils/getGTProp.js.map +1 -0
- package/dist/variables/Currency.d.ts.map +1 -0
- package/dist/variables/Currency.js.map +1 -0
- package/dist/variables/DateTime.d.ts.map +1 -0
- package/dist/variables/DateTime.js.map +1 -0
- package/dist/variables/Num.d.ts.map +1 -0
- package/dist/variables/Num.js.map +1 -0
- package/dist/variables/Var.d.ts.map +1 -0
- package/dist/variables/Var.js.map +1 -0
- package/package.json +11 -21
- package/tsconfig.json +1 -1
- package/dist/cjs/_dictionary.js.map +0 -1
- package/dist/cjs/_request.js.map +0 -1
- package/dist/cjs/branches/Branch.js.map +0 -1
- package/dist/cjs/branches/Plural.js.map +0 -1
- package/dist/cjs/client.js.map +0 -1
- package/dist/cjs/config/I18NConfiguration.js.map +0 -1
- package/dist/cjs/config/RemoteTranslationsManager.js.map +0 -1
- package/dist/cjs/config/getI18NConfig.js.map +0 -1
- package/dist/cjs/config/props/InitGTProps.js.map +0 -1
- package/dist/cjs/config/props/defaultInitGTProps.js.map +0 -1
- package/dist/cjs/config.js.map +0 -1
- package/dist/cjs/dictionary/getDictionary.js.map +0 -1
- package/dist/cjs/errors/createErrors.js.map +0 -1
- package/dist/cjs/index.client.js.map +0 -1
- package/dist/cjs/index.server.js.map +0 -1
- package/dist/cjs/middleware/createNextMiddleware.js.map +0 -1
- package/dist/cjs/middleware.js.map +0 -1
- package/dist/cjs/next/getNextDomain.js.map +0 -1
- package/dist/cjs/next/getNextLocale.js.map +0 -1
- package/dist/cjs/provider/ClientProvider.js.map +0 -1
- package/dist/cjs/provider/GTProvider.js.map +0 -1
- package/dist/cjs/request/getLocale.js.map +0 -1
- package/dist/cjs/request/getMetadata.js.map +0 -1
- package/dist/cjs/server/getGT.js.map +0 -1
- package/dist/cjs/server/inline/Resolver.js.map +0 -1
- package/dist/cjs/server/inline/T.js.map +0 -1
- package/dist/cjs/server/rendering/renderVariable.js.map +0 -1
- package/dist/cjs/server/strings/tx.js.map +0 -1
- package/dist/cjs/server.js.map +0 -1
- package/dist/cjs/types/types.js.map +0 -1
- package/dist/cjs/utils/checkTypes.js.map +0 -1
- package/dist/cjs/utils/getDefaultFromEnv.js.map +0 -1
- package/dist/cjs/utils/getGTProp.js.map +0 -1
- package/dist/cjs/variables/Currency.js.map +0 -1
- package/dist/cjs/variables/DateTime.js.map +0 -1
- package/dist/cjs/variables/Num.js.map +0 -1
- package/dist/cjs/variables/Var.js.map +0 -1
- package/dist/esm/_dictionary.js +0 -4
- package/dist/esm/_dictionary.js.map +0 -1
- package/dist/esm/_request.js +0 -6
- package/dist/esm/branches/Branch.js +0 -45
- package/dist/esm/branches/Branch.js.map +0 -1
- package/dist/esm/branches/Plural.js +0 -45
- package/dist/esm/branches/Plural.js.map +0 -1
- package/dist/esm/client.js +0 -4
- package/dist/esm/client.js.map +0 -1
- package/dist/esm/config/I18NConfiguration.js +0 -379
- package/dist/esm/config/I18NConfiguration.js.map +0 -1
- package/dist/esm/config/RemoteTranslationsManager.js +0 -200
- package/dist/esm/config/RemoteTranslationsManager.js.map +0 -1
- package/dist/esm/config/getI18NConfig.js +0 -48
- package/dist/esm/config/getI18NConfig.js.map +0 -1
- package/dist/esm/config/props/InitGTProps.js +0 -2
- package/dist/esm/config/props/InitGTProps.js.map +0 -1
- package/dist/esm/config/props/defaultInitGTProps.js +0 -62
- package/dist/esm/config/props/defaultInitGTProps.js.map +0 -1
- package/dist/esm/config.js +0 -196
- package/dist/esm/config.js.map +0 -1
- package/dist/esm/dictionary/getDictionary.js +0 -18
- package/dist/esm/dictionary/getDictionary.js.map +0 -1
- package/dist/esm/errors/createErrors.js +0 -22
- package/dist/esm/errors/createErrors.js.map +0 -1
- package/dist/esm/index.client.js +0 -8
- package/dist/esm/index.client.js.map +0 -1
- package/dist/esm/index.server.js +0 -11
- package/dist/esm/index.server.js.map +0 -1
- package/dist/esm/middleware/createNextMiddleware.js +0 -127
- package/dist/esm/middleware/createNextMiddleware.js.map +0 -1
- package/dist/esm/middleware.js +0 -3
- package/dist/esm/middleware.js.map +0 -1
- package/dist/esm/next/getNextDomain.js +0 -60
- package/dist/esm/next/getNextDomain.js.map +0 -1
- package/dist/esm/next/getNextLocale.js +0 -86
- package/dist/esm/next/getNextLocale.js.map +0 -1
- package/dist/esm/provider/ClientProvider.js +0 -222
- package/dist/esm/provider/ClientProvider.js.map +0 -1
- package/dist/esm/provider/GTProvider.js +0 -226
- package/dist/esm/provider/GTProvider.js.map +0 -1
- package/dist/esm/request/getLocale.js +0 -87
- package/dist/esm/request/getLocale.js.map +0 -1
- package/dist/esm/request/getMetadata.js +0 -83
- package/dist/esm/request/getMetadata.js.map +0 -1
- package/dist/esm/server/getGT.js +0 -207
- package/dist/esm/server/getGT.js.map +0 -1
- package/dist/esm/server/inline/Resolver.js +0 -48
- package/dist/esm/server/inline/Resolver.js.map +0 -1
- package/dist/esm/server/inline/T.js +0 -221
- package/dist/esm/server/inline/T.js.map +0 -1
- package/dist/esm/server/rendering/renderVariable.js +0 -19
- package/dist/esm/server/rendering/renderVariable.js.map +0 -1
- package/dist/esm/server/strings/tx.js +0 -156
- package/dist/esm/server/strings/tx.js.map +0 -1
- package/dist/esm/server.js +0 -10
- package/dist/esm/server.js.map +0 -1
- package/dist/esm/types/types.js +0 -34
- package/dist/esm/utils/checkTypes.js +0 -13
- package/dist/esm/utils/checkTypes.js.map +0 -1
- package/dist/esm/utils/getDefaultFromEnv.js +0 -18
- package/dist/esm/utils/getDefaultFromEnv.js.map +0 -1
- package/dist/esm/utils/getGTProp.js +0 -8
- package/dist/esm/utils/getGTProp.js.map +0 -1
- package/dist/esm/variables/Currency.js +0 -61
- package/dist/esm/variables/Currency.js.map +0 -1
- package/dist/esm/variables/DateTime.js +0 -74
- package/dist/esm/variables/DateTime.js.map +0 -1
- package/dist/esm/variables/Num.js +0 -50
- package/dist/esm/variables/Num.js.map +0 -1
- package/dist/esm/variables/Var.js +0 -41
- package/dist/esm/variables/Var.js.map +0 -1
- package/dist/types/_dictionary.d.ts.map +0 -1
- package/dist/types/branches/Branch.d.ts.map +0 -1
- package/dist/types/branches/Plural.d.ts.map +0 -1
- package/dist/types/client.d.ts.map +0 -1
- package/dist/types/config/I18NConfiguration.d.ts.map +0 -1
- package/dist/types/config/RemoteTranslationsManager.d.ts.map +0 -1
- package/dist/types/config/getI18NConfig.d.ts.map +0 -1
- package/dist/types/config/props/InitGTProps.d.ts.map +0 -1
- package/dist/types/config/props/defaultInitGTProps.d.ts.map +0 -1
- package/dist/types/config.d.ts.map +0 -1
- package/dist/types/dictionary/getDictionary.d.ts +0 -3
- package/dist/types/dictionary/getDictionary.d.ts.map +0 -1
- package/dist/types/errors/createErrors.d.ts.map +0 -1
- package/dist/types/index.client.d.ts.map +0 -1
- package/dist/types/index.server.d.ts.map +0 -1
- package/dist/types/middleware/createNextMiddleware.d.ts.map +0 -1
- package/dist/types/middleware.d.ts.map +0 -1
- package/dist/types/next/getNextDomain.d.ts.map +0 -1
- package/dist/types/next/getNextLocale.d.ts.map +0 -1
- package/dist/types/provider/ClientProvider.d.ts.map +0 -1
- package/dist/types/provider/GTProvider.d.ts.map +0 -1
- package/dist/types/request/getLocale.d.ts.map +0 -1
- package/dist/types/request/getMetadata.d.ts.map +0 -1
- package/dist/types/server/getGT.d.ts.map +0 -1
- package/dist/types/server/inline/Resolver.d.ts.map +0 -1
- package/dist/types/server/inline/T.d.ts.map +0 -1
- package/dist/types/server/rendering/renderVariable.d.ts.map +0 -1
- package/dist/types/server/strings/tx.d.ts.map +0 -1
- package/dist/types/server.d.ts.map +0 -1
- package/dist/types/types/types.d.ts.map +0 -1
- package/dist/types/utils/checkTypes.d.ts.map +0 -1
- package/dist/types/utils/getDefaultFromEnv.d.ts.map +0 -1
- package/dist/types/utils/getGTProp.d.ts.map +0 -1
- package/dist/types/variables/Currency.d.ts.map +0 -1
- package/dist/types/variables/DateTime.d.ts.map +0 -1
- package/dist/types/variables/Num.d.ts.map +0 -1
- package/dist/types/variables/Var.d.ts.map +0 -1
- package/tsconfig.base.json +0 -20
- package/tsconfig.cjs.json +0 -7
- package/tsconfig.esm.json +0 -7
- /package/dist/{types/_dictionary.d.ts → _dictionary.d.ts} +0 -0
- /package/dist/{cjs/_dictionary.js → _dictionary.js} +0 -0
- /package/dist/{types/_request.d.ts → _request.d.ts} +0 -0
- /package/dist/{cjs/_request.js → _request.js} +0 -0
- /package/dist/{types/branches → branches}/Branch.d.ts +0 -0
- /package/dist/{cjs/branches → branches}/Branch.js +0 -0
- /package/dist/{types/branches → branches}/Plural.d.ts +0 -0
- /package/dist/{cjs/branches → branches}/Plural.js +0 -0
- /package/dist/{types/client.d.ts → client.d.ts} +0 -0
- /package/dist/{cjs/client.js → client.js} +0 -0
- /package/dist/{types/config → config}/I18NConfiguration.d.ts +0 -0
- /package/dist/{cjs/config → config}/I18NConfiguration.js +0 -0
- /package/dist/{types/config → config}/RemoteTranslationsManager.d.ts +0 -0
- /package/dist/{cjs/config → config}/RemoteTranslationsManager.js +0 -0
- /package/dist/{types/config → config}/getI18NConfig.d.ts +0 -0
- /package/dist/{cjs/config → config}/getI18NConfig.js +0 -0
- /package/dist/{types/config → config}/props/InitGTProps.d.ts +0 -0
- /package/dist/{cjs/config → config}/props/InitGTProps.js +0 -0
- /package/dist/{types/config → config}/props/defaultInitGTProps.d.ts +0 -0
- /package/dist/{cjs/config → config}/props/defaultInitGTProps.js +0 -0
- /package/dist/{types/config.d.ts → config.d.ts} +0 -0
- /package/dist/{cjs/config.js → config.js} +0 -0
- /package/dist/{cjs/dictionary → dictionary}/getDictionary.js +0 -0
- /package/dist/{types/errors → errors}/createErrors.d.ts +0 -0
- /package/dist/{cjs/errors → errors}/createErrors.js +0 -0
- /package/dist/{types/index.client.d.ts → index.client.d.ts} +0 -0
- /package/dist/{cjs/index.client.js → index.client.js} +0 -0
- /package/dist/{types/index.server.d.ts → index.server.d.ts} +0 -0
- /package/dist/{cjs/index.server.js → index.server.js} +0 -0
- /package/dist/{types/middleware → middleware}/createNextMiddleware.d.ts +0 -0
- /package/dist/{cjs/middleware → middleware}/createNextMiddleware.js +0 -0
- /package/dist/{types/middleware.d.ts → middleware.d.ts} +0 -0
- /package/dist/{cjs/middleware.js → middleware.js} +0 -0
- /package/dist/{types/next → next}/getNextDomain.d.ts +0 -0
- /package/dist/{cjs/next → next}/getNextDomain.js +0 -0
- /package/dist/{types/next → next}/getNextLocale.d.ts +0 -0
- /package/dist/{cjs/next → next}/getNextLocale.js +0 -0
- /package/dist/{types/provider → provider}/ClientProvider.d.ts +0 -0
- /package/dist/{cjs/provider → provider}/ClientProvider.js +0 -0
- /package/dist/{types/provider → provider}/GTProvider.d.ts +0 -0
- /package/dist/{cjs/provider → provider}/GTProvider.js +0 -0
- /package/dist/{types/request → request}/getLocale.d.ts +0 -0
- /package/dist/{cjs/request → request}/getLocale.js +0 -0
- /package/dist/{types/request → request}/getMetadata.d.ts +0 -0
- /package/dist/{cjs/request → request}/getMetadata.js +0 -0
- /package/dist/{types/server → server}/inline/Resolver.d.ts +0 -0
- /package/dist/{cjs/server → server}/inline/Resolver.js +0 -0
- /package/dist/{types/server → server}/inline/T.d.ts +0 -0
- /package/dist/{cjs/server → server}/inline/T.js +0 -0
- /package/dist/{types/server → server}/rendering/renderVariable.d.ts +0 -0
- /package/dist/{cjs/server → server}/rendering/renderVariable.js +0 -0
- /package/dist/{types/server → server}/strings/tx.d.ts +0 -0
- /package/dist/{types/server.d.ts → server.d.ts} +0 -0
- /package/dist/{cjs/server.js → server.js} +0 -0
- /package/dist/types/{types/types.d.ts → types.d.ts} +0 -0
- /package/dist/{cjs/types → types}/types.js +0 -0
- /package/dist/{types/utils → utils}/checkTypes.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/checkTypes.js +0 -0
- /package/dist/{types/utils → utils}/getDefaultFromEnv.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/getDefaultFromEnv.js +0 -0
- /package/dist/{types/utils → utils}/getGTProp.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/getGTProp.js +0 -0
- /package/dist/{types/variables → variables}/Currency.d.ts +0 -0
- /package/dist/{cjs/variables → variables}/Currency.js +0 -0
- /package/dist/{types/variables → variables}/DateTime.d.ts +0 -0
- /package/dist/{cjs/variables → variables}/DateTime.js +0 -0
- /package/dist/{types/variables → variables}/Num.d.ts +0 -0
- /package/dist/{cjs/variables → variables}/Num.js +0 -0
- /package/dist/{types/variables → variables}/Var.d.ts +0 -0
- /package/dist/{cjs/variables → variables}/Var.js +0 -0
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
49
|
-
import getI18NConfig from '../../config/getI18NConfig';
|
|
50
|
-
import getLocale from '../../request/getLocale';
|
|
51
|
-
import getMetadata from '../../request/getMetadata';
|
|
52
|
-
import { Suspense } from 'react';
|
|
53
|
-
import Resolver from './Resolver';
|
|
54
|
-
import { renderDefaultChildren, renderSkeleton, renderTranslatedChildren, } from 'gt-react/internal';
|
|
55
|
-
import renderVariable from '../rendering/renderVariable';
|
|
56
|
-
/**
|
|
57
|
-
* Translation component that renders its children translated into the user's given locale.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```jsx
|
|
61
|
-
* // Basic usage:
|
|
62
|
-
* <T id="welcome_message">
|
|
63
|
-
* Hello, <Var name="name" value={firstname}>!
|
|
64
|
-
* </T>
|
|
65
|
-
* ```
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```jsx
|
|
69
|
-
* // Translating a plural
|
|
70
|
-
* <T id="item_count">
|
|
71
|
-
* <Plural n={3} singular={<>You have <Num value={n}/> item.</>}>
|
|
72
|
-
* You have <Num value={n}/> items.
|
|
73
|
-
* </Plural>
|
|
74
|
-
* </T>
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* When used on the server-side, can create translations on demand.
|
|
78
|
-
* If you need to ensure server-side usage import from `'gt-next/server'`.
|
|
79
|
-
*
|
|
80
|
-
* When used on the client-side, will throw an error if no `id` prop is provided.
|
|
81
|
-
*
|
|
82
|
-
* By default, General Translation saves the translation in a remote cache if an `id` option is passed.
|
|
83
|
-
*
|
|
84
|
-
* @param {React.ReactNode} children - The content to be translated or displayed.
|
|
85
|
-
* @param {string} [id] - Optional identifier for the translation string. If not provided, a hash will be generated from the content.
|
|
86
|
-
* @param {Object} [renderSettings] - Optional settings controlling how fallback content is rendered during translation.
|
|
87
|
-
* @param {"skeleton" | "replace" | "hang" | "subtle" | "default"} [renderSettings.method] - Specifies the rendering method:
|
|
88
|
-
* - "skeleton": show a placeholder while translation is loading.
|
|
89
|
-
* - "replace": show the default content as a fallback while the translation is loading.
|
|
90
|
-
* - "hang": wait until the translation is fully loaded before rendering anything.
|
|
91
|
-
* - "subtle": display children without a translation initially, with translations being applied later if available.
|
|
92
|
-
* - "default": behave like skeleton unless language is same (ie en-GB vs en-US), then behave like replace
|
|
93
|
-
* @param {number | null} [renderSettings.timeout] - Optional timeout for translation loading.
|
|
94
|
-
* @param {any} [context] - Additional context for translation key generation.
|
|
95
|
-
* @param {Object} [props] - Additional props for the component.
|
|
96
|
-
* @returns {JSX.Element} The rendered translation or fallback content based on the provided configuration.
|
|
97
|
-
*
|
|
98
|
-
* @throws {Error} If a plural translation is requested but the `n` option is not provided.
|
|
99
|
-
*/
|
|
100
|
-
function T(_a) {
|
|
101
|
-
return __awaiter(this, arguments, void 0, function (_b) {
|
|
102
|
-
var I18NConfig, locale, defaultLocale, regionalTranslationRequired, translationRequired, translationsPromise, taggedChildren, _c, childrenAsObjects, key, translations, translation, target, renderSettings, translationPromise, _d, _e, _f, loadingFallback, renderDefaultLocale, renderLoadingSkeleton, renderLoadingDefault, renderTranslatedChildrenPromise;
|
|
103
|
-
var _g;
|
|
104
|
-
var children = _b.children, id = _b.id, context = _b.context, variables = _b.variables, variablesOptions = _b.variablesOptions;
|
|
105
|
-
return __generator(this, function (_h) {
|
|
106
|
-
switch (_h.label) {
|
|
107
|
-
case 0:
|
|
108
|
-
if (!children) {
|
|
109
|
-
return [2 /*return*/];
|
|
110
|
-
}
|
|
111
|
-
I18NConfig = getI18NConfig();
|
|
112
|
-
return [4 /*yield*/, getLocale()];
|
|
113
|
-
case 1:
|
|
114
|
-
locale = _h.sent();
|
|
115
|
-
defaultLocale = I18NConfig.getDefaultLocale();
|
|
116
|
-
regionalTranslationRequired = I18NConfig.requiresRegionalTranslation(locale);
|
|
117
|
-
translationRequired = I18NConfig.requiresTranslation(locale) || regionalTranslationRequired;
|
|
118
|
-
if (translationRequired) {
|
|
119
|
-
translationsPromise = I18NConfig.getTranslations(locale);
|
|
120
|
-
}
|
|
121
|
-
taggedChildren = I18NConfig.addGTIdentifier(children, id);
|
|
122
|
-
// If no translation is required, render the default children
|
|
123
|
-
// The dictionary wraps text in this <T> component
|
|
124
|
-
// Thus, we need to also handle variables
|
|
125
|
-
if (!translationRequired) {
|
|
126
|
-
return [2 /*return*/, renderDefaultChildren({
|
|
127
|
-
children: taggedChildren,
|
|
128
|
-
variables: variables,
|
|
129
|
-
variablesOptions: variablesOptions,
|
|
130
|
-
defaultLocale: defaultLocale,
|
|
131
|
-
renderVariable: renderVariable,
|
|
132
|
-
})];
|
|
133
|
-
}
|
|
134
|
-
_c = I18NConfig.serializeAndHash(taggedChildren, context, undefined // id is not provided here, to catch erroneous situations where the same id is being used for different <T> components
|
|
135
|
-
), childrenAsObjects = _c[0], key = _c[1];
|
|
136
|
-
return [4 /*yield*/, translationsPromise];
|
|
137
|
-
case 2:
|
|
138
|
-
translations = _h.sent();
|
|
139
|
-
translation = id ? translations === null || translations === void 0 ? void 0 : translations[id] : undefined;
|
|
140
|
-
// checks if an appropriate translation exists
|
|
141
|
-
if (translation && (translation === null || translation === void 0 ? void 0 : translation[key])) {
|
|
142
|
-
target = translation[key];
|
|
143
|
-
return [2 /*return*/, renderTranslatedChildren({
|
|
144
|
-
source: taggedChildren,
|
|
145
|
-
target: target,
|
|
146
|
-
variables: variables,
|
|
147
|
-
variablesOptions: variablesOptions,
|
|
148
|
-
locales: [locale, defaultLocale],
|
|
149
|
-
renderVariable: renderVariable,
|
|
150
|
-
})];
|
|
151
|
-
}
|
|
152
|
-
renderSettings = I18NConfig.getRenderSettings();
|
|
153
|
-
_e = (_d = I18NConfig).translateChildren;
|
|
154
|
-
_g = {
|
|
155
|
-
source: childrenAsObjects,
|
|
156
|
-
targetLocale: locale
|
|
157
|
-
};
|
|
158
|
-
_f = [__assign(__assign({}, (id && { id: id })), { hash: key })];
|
|
159
|
-
return [4 /*yield*/, getMetadata()];
|
|
160
|
-
case 3:
|
|
161
|
-
translationPromise = _e.apply(_d, [(_g.metadata = __assign.apply(void 0, [__assign.apply(void 0, _f.concat([(_h.sent())])), (renderSettings.timeout && { timeout: renderSettings.timeout })]),
|
|
162
|
-
_g)]);
|
|
163
|
-
renderDefaultLocale = function () {
|
|
164
|
-
return renderDefaultChildren({
|
|
165
|
-
children: taggedChildren,
|
|
166
|
-
variables: variables,
|
|
167
|
-
variablesOptions: variablesOptions,
|
|
168
|
-
defaultLocale: defaultLocale,
|
|
169
|
-
renderVariable: renderVariable,
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
renderLoadingSkeleton = function () {
|
|
173
|
-
return renderSkeleton({
|
|
174
|
-
children: taggedChildren,
|
|
175
|
-
variables: variables,
|
|
176
|
-
defaultLocale: defaultLocale,
|
|
177
|
-
renderVariable: renderVariable,
|
|
178
|
-
});
|
|
179
|
-
};
|
|
180
|
-
renderLoadingDefault = function () {
|
|
181
|
-
if (regionalTranslationRequired)
|
|
182
|
-
return renderDefaultLocale();
|
|
183
|
-
return renderLoadingSkeleton();
|
|
184
|
-
};
|
|
185
|
-
renderTranslatedChildrenPromise = translationPromise.then(function (translation) {
|
|
186
|
-
return renderTranslatedChildren({
|
|
187
|
-
source: taggedChildren,
|
|
188
|
-
target: translation,
|
|
189
|
-
variables: variables,
|
|
190
|
-
variablesOptions: variablesOptions,
|
|
191
|
-
locales: [locale, defaultLocale],
|
|
192
|
-
renderVariable: renderVariable,
|
|
193
|
-
});
|
|
194
|
-
}).catch(function () {
|
|
195
|
-
return renderDefaultLocale();
|
|
196
|
-
});
|
|
197
|
-
if (renderSettings.method === 'replace') {
|
|
198
|
-
loadingFallback = renderDefaultLocale();
|
|
199
|
-
}
|
|
200
|
-
else if (renderSettings.method === 'skeleton') {
|
|
201
|
-
loadingFallback = renderLoadingSkeleton();
|
|
202
|
-
}
|
|
203
|
-
else if (renderSettings.method === 'hang') {
|
|
204
|
-
return [2 /*return*/, (_jsx(Resolver, { children: renderTranslatedChildrenPromise }))];
|
|
205
|
-
}
|
|
206
|
-
else if (renderSettings.method === 'subtle') {
|
|
207
|
-
return [2 /*return*/, undefined]; // TODO: implement subtle rendering
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
loadingFallback = renderLoadingDefault();
|
|
211
|
-
}
|
|
212
|
-
// For skeleton & replace, return a suspense component so that
|
|
213
|
-
// something is shown while waiting for the translation
|
|
214
|
-
return [2 /*return*/, (_jsx(Suspense, { fallback: loadingFallback, children: _jsx(Resolver, { children: renderTranslatedChildrenPromise }) }))];
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
T.gtTransformation = 'translate-server';
|
|
220
|
-
export default T;
|
|
221
|
-
//# sourceMappingURL=T.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"T.js","sourceRoot":"","sources":["../../../../src/server/inline/T.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,cAAc,MAAM,6BAA6B,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,SAAe,CAAC;wDAAC,EAWhB;;;YAVC,QAAQ,cAAA,EACR,EAAE,QAAA,EACF,OAAO,aAAA,EACP,SAAS,eAAA,EACT,gBAAgB,sBAAA;;;;oBAOhB,IAAI,CAAC,QAAQ,EAAE,CAAC;wBACd,sBAAO;oBACT,CAAC;oBAEK,UAAU,GAAG,aAAa,EAAE,CAAC;oBACpB,qBAAM,SAAS,EAAE,EAAA;;oBAA1B,MAAM,GAAG,SAAiB;oBAC1B,aAAa,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC;oBAC9C,2BAA2B,GAAG,UAAU,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;oBAC7E,mBAAmB,GAAG,UAAU,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,2BAA2B,CAAC;oBAKlG,IAAI,mBAAmB,EAAE,CAAC;wBACxB,mBAAmB,GAAG,UAAU,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;oBAC3D,CAAC;oBAIK,cAAc,GAAG,UAAU,CAAC,eAAe,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,qBAAqB,EAAE,CAAC;oBAC5C,CAAC;yBAAM,IAAI,cAAc,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;wBAC5C,sBAAO,CAAC,KAAC,QAAQ,IAAC,QAAQ,EAAE,+BAA+B,GAAG,CAAC,EAAC;oBAClE,CAAC;yBAAM,IAAI,cAAc,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;wBAC9C,sBAAO,SAAS,EAAC,CAAC,mCAAmC;oBACvD,CAAC;yBAAM,CAAC;wBACN,eAAe,GAAG,oBAAoB,EAAE,CAAC;oBAC3C,CAAC;oBAED,8DAA8D;oBAC9D,uDAAuD;oBACvD,sBAAO,CACL,KAAC,QAAQ,IAAC,QAAQ,EAAE,eAAkC,YACpD,KAAC,QAAQ,IACP,QAAQ,EAAE,+BAA+B,GACzC,GACO,CACZ,EAAC;;;;CACH;AAED,CAAC,CAAC,gBAAgB,GAAG,kBAAkB,CAAC;AAExC,eAAe,CAAC,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import Num from "../../variables/Num";
|
|
3
|
-
import Var from "../../variables/Var";
|
|
4
|
-
import Currency from "../../variables/Currency";
|
|
5
|
-
import DateTime from "../../variables/DateTime";
|
|
6
|
-
export default function renderVariable(_a) {
|
|
7
|
-
var variableType = _a.variableType, variableName = _a.variableName, variableValue = _a.variableValue, variableOptions = _a.variableOptions, locales = _a.locales;
|
|
8
|
-
if (variableType === "number") {
|
|
9
|
-
return (_jsx(Num, { name: variableName, value: variableValue, options: variableOptions, locales: locales }));
|
|
10
|
-
}
|
|
11
|
-
else if (variableType === "datetime") {
|
|
12
|
-
return (_jsx(DateTime, { name: variableName, value: variableValue, options: variableOptions, locales: locales }));
|
|
13
|
-
}
|
|
14
|
-
else if (variableType === "currency") {
|
|
15
|
-
return (_jsx(Currency, { name: variableName, value: variableValue, options: variableOptions, locales: locales }));
|
|
16
|
-
}
|
|
17
|
-
return (_jsx(Var, { name: variableName, value: variableValue }));
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=renderVariable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderVariable.js","sourceRoot":"","sources":["../../../../src/server/rendering/renderVariable.tsx"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,qBAAqB,CAAC;AACtC,OAAO,GAAG,MAAM,qBAAqB,CAAC;AACtC,OAAO,QAAQ,MAAM,0BAA0B,CAAC;AAChD,OAAO,QAAQ,MAAM,0BAA0B,CAAC;AAEhD,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAQtC;QAPG,YAAY,kBAAA,EAAE,YAAY,kBAAA,EAAE,aAAa,mBAAA,EAAE,eAAe,qBAAA,EAAE,OAAO,aAAA;IAQnE,IAAI,YAAY,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,CACH,KAAC,GAAG,IACA,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,OAAO,GAClB,CACL,CAAA;IACL,CAAC;SAAM,IAAI,YAAY,KAAK,UAAU,EAAE,CAAC;QACrC,OAAO,CACH,KAAC,QAAQ,IACL,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,OAAO,GAClB,CACL,CAAA;IACL,CAAC;SAAM,IAAI,YAAY,KAAK,UAAU,EAAE,CAAC;QACrC,OAAO,CACH,KAAC,QAAQ,IACL,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,OAAO,GAClB,CACL,CAAA;IACL,CAAC;IACD,OAAO,CACH,KAAC,GAAG,IAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,GAAI,CACpD,CAAC;AACN,CAAC"}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
import { renderContentToString, splitStringToContent, } from 'generaltranslation';
|
|
49
|
-
import getI18NConfig from '../../config/getI18NConfig';
|
|
50
|
-
import getLocale from '../../request/getLocale';
|
|
51
|
-
import getMetadata from '../../request/getMetadata';
|
|
52
|
-
import { createStringTranslationError } from '../../errors/createErrors';
|
|
53
|
-
/**
|
|
54
|
-
* Translates the provided content string based on the specified locale and options.
|
|
55
|
-
* If no translation is required, it renders the content as is. Otherwise, it fetches the
|
|
56
|
-
* required translations or falls back to on-demand translation if enabled.
|
|
57
|
-
*
|
|
58
|
-
* By default, General Translation saves the translation in a remote cache if an `id` option is passed.
|
|
59
|
-
*
|
|
60
|
-
* @async
|
|
61
|
-
* @function tx (translate)
|
|
62
|
-
*
|
|
63
|
-
* @param {string} content - The content string that needs to be translated.
|
|
64
|
-
* @param {Object} [options] - Translation options.
|
|
65
|
-
* @param {string} [options.id] - A unique identifier for the content, used for caching and fetching translations.
|
|
66
|
-
* @param {string} [options.locale] - The target locale for translation. Defaults to the current locale if not provided.
|
|
67
|
-
* @param {string} [options.context] - Additional context for the translation process, which may influence the translation's outcome.
|
|
68
|
-
* @param {Object} [options.variables] - An optional map of variables to be injected into the translated content.
|
|
69
|
-
* @param {Object} [options.variableOptions] - Options for formatting numbers and dates using `Intl.NumberFormat` or `Intl.DateTimeFormat`.
|
|
70
|
-
*
|
|
71
|
-
* @returns {Promise<string>} - A promise that resolves to the translated content string, or the original content if no translation is needed.
|
|
72
|
-
*
|
|
73
|
-
* @throws {Error} - Throws an error if the translation process fails or if there are issues with fetching necessary data.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* // Basic usage with default locale detection
|
|
77
|
-
* const translation = await tx("Hello, world!");
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* // Providing specific translation options
|
|
81
|
-
* const translation = await tx("Hello, world!", { locale: 'es', context: 'Translate informally' });
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* // Using variables in the content string
|
|
85
|
-
* const translation = await tx("The price is {price}", { locale: 'es-MX', variables: { price: 29.99 } });
|
|
86
|
-
*/
|
|
87
|
-
export default function tx(content_1) {
|
|
88
|
-
return __awaiter(this, arguments, void 0, function (content, options) {
|
|
89
|
-
var I18NConfig, defaultLocale, locale, _a, contentArray, r, _b, _, hash, translations, target, translationPromise, _c, _d, _e, renderSettings, target, error_1;
|
|
90
|
-
var _f;
|
|
91
|
-
var _g;
|
|
92
|
-
if (options === void 0) { options = {}; }
|
|
93
|
-
return __generator(this, function (_h) {
|
|
94
|
-
switch (_h.label) {
|
|
95
|
-
case 0:
|
|
96
|
-
if (!content)
|
|
97
|
-
return [2 /*return*/, ''];
|
|
98
|
-
I18NConfig = getI18NConfig();
|
|
99
|
-
defaultLocale = I18NConfig.getDefaultLocale();
|
|
100
|
-
_a = options.locale;
|
|
101
|
-
if (_a) return [3 /*break*/, 2];
|
|
102
|
-
return [4 /*yield*/, getLocale()];
|
|
103
|
-
case 1:
|
|
104
|
-
_a = (_h.sent());
|
|
105
|
-
_h.label = 2;
|
|
106
|
-
case 2:
|
|
107
|
-
locale = _a;
|
|
108
|
-
contentArray = splitStringToContent(content);
|
|
109
|
-
r = function (content, locales) {
|
|
110
|
-
return renderContentToString(content, locales, options.variables, options.variablesOptions);
|
|
111
|
-
};
|
|
112
|
-
if (!I18NConfig.requiresTranslation(locale))
|
|
113
|
-
return [2 /*return*/, r(contentArray, [defaultLocale])];
|
|
114
|
-
_b = I18NConfig.serializeAndHash(contentArray, options.context, undefined // id is not provided here, to catch erroneous situations where the same id is being used for different <T> components
|
|
115
|
-
), _ = _b[0], hash = _b[1];
|
|
116
|
-
if (!options.id) return [3 /*break*/, 4];
|
|
117
|
-
return [4 /*yield*/, I18NConfig.getTranslations(locale)];
|
|
118
|
-
case 3:
|
|
119
|
-
translations = _h.sent();
|
|
120
|
-
target = (_g = translations[options.id]) === null || _g === void 0 ? void 0 : _g[hash];
|
|
121
|
-
if (target)
|
|
122
|
-
return [2 /*return*/, r(target, [locale, defaultLocale])];
|
|
123
|
-
_h.label = 4;
|
|
124
|
-
case 4:
|
|
125
|
-
;
|
|
126
|
-
_d = (_c = I18NConfig).translateContent;
|
|
127
|
-
_f = {
|
|
128
|
-
source: contentArray,
|
|
129
|
-
targetLocale: locale
|
|
130
|
-
};
|
|
131
|
-
_e = [__assign({}, options)];
|
|
132
|
-
return [4 /*yield*/, getMetadata()];
|
|
133
|
-
case 5:
|
|
134
|
-
translationPromise = _d.apply(_c, [(_f.options = __assign.apply(void 0, [__assign.apply(void 0, _e.concat([(_h.sent())])), { hash: hash }]),
|
|
135
|
-
_f)]);
|
|
136
|
-
renderSettings = I18NConfig.getRenderSettings();
|
|
137
|
-
if (!(renderSettings.method !== "subtle" ||
|
|
138
|
-
!options.id) // because it is only saved if an id is present
|
|
139
|
-
) return [3 /*break*/, 9]; // because it is only saved if an id is present
|
|
140
|
-
_h.label = 6;
|
|
141
|
-
case 6:
|
|
142
|
-
_h.trys.push([6, 8, , 9]);
|
|
143
|
-
return [4 /*yield*/, translationPromise];
|
|
144
|
-
case 7:
|
|
145
|
-
target = _h.sent();
|
|
146
|
-
return [2 /*return*/, r(target, [locale, defaultLocale])];
|
|
147
|
-
case 8:
|
|
148
|
-
error_1 = _h.sent();
|
|
149
|
-
console.error(createStringTranslationError(content, options.id), error_1);
|
|
150
|
-
return [2 /*return*/, r(contentArray, [defaultLocale])];
|
|
151
|
-
case 9: return [2 /*return*/, r(contentArray, [defaultLocale])];
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
//# sourceMappingURL=tx.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tx.js","sourceRoot":"","sources":["../../../../src/server/strings/tx.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACL,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAGzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,OAAO,UAAgB,EAAE;wDAC9B,OAAe,EACf,OAUM;;;;QAVN,wBAAA,EAAA,YAUM;;;;oBAGN,IAAI,CAAC,OAAO;wBAAE,sBAAO,EAAE,EAAC;oBAElB,UAAU,GAAG,aAAa,EAAE,CAAC;oBAC7B,aAAa,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC;oBACrC,KAAA,OAAO,CA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AAC,iBAAiB,EAAE,CAAC;yBAGpD,CAAA,cAAc,CAAC,MAAM,KAAK,QAAQ;wBAClC,CAAC,OAAO,CAAC,EAAE,CAAA,CAAC,+CAA+C;sBAD3D,wBACW,CAAC,+CAA+C;;;;oBAG1C,qBAAM,kBAAkB,EAAA;;oBAAjC,MAAM,GAAG,SAAwB;oBACvC,sBAAO,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,EAAC;;;oBAE1C,OAAO,CAAC,KAAK,CACX,4BAA4B,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,EACjD,OAAK,CACN,CAAC;oBACF,sBAAO,CAAC,CACN,YAAY,EACZ,CAAC,aAAa,CAAC,CAChB,EAAC;wBAKN,sBAAO,CAAC,CACN,YAAY,EACZ,CAAC,aAAa,CAAC,CAChB,EAAC;;;;CACH"}
|
package/dist/esm/server.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import T from "./server/inline/T";
|
|
2
|
-
import tx from "./server/strings/tx";
|
|
3
|
-
import getLocale from "./request/getLocale";
|
|
4
|
-
import getI18NConfig from "./config/getI18NConfig";
|
|
5
|
-
import { getGT } from "./server/getGT";
|
|
6
|
-
export function getDefaultLocale() {
|
|
7
|
-
return getI18NConfig().getDefaultLocale();
|
|
8
|
-
}
|
|
9
|
-
export { T, tx, getLocale, getGT };
|
|
10
|
-
//# sourceMappingURL=server.js.map
|
package/dist/esm/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,mBAAmB,CAAC;AAClC,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACrC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,aAAa,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,MAAM,UAAU,gBAAgB;IAC5B,OAAO,aAAa,EAAE,CAAC,gBAAgB,EAAE,CAAC;AAC9C,CAAC;AAED,OAAO,EACH,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAC1B,CAAA"}
|
package/dist/esm/types/types.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var GTTranslationError = /** @class */ (function (_super) {
|
|
17
|
-
__extends(GTTranslationError, _super);
|
|
18
|
-
function GTTranslationError(error, code) {
|
|
19
|
-
var _this = _super.call(this, error) || this;
|
|
20
|
-
_this.error = error;
|
|
21
|
-
_this.code = code;
|
|
22
|
-
_this.code = code;
|
|
23
|
-
return _this;
|
|
24
|
-
}
|
|
25
|
-
GTTranslationError.prototype.toTranslationError = function () {
|
|
26
|
-
return {
|
|
27
|
-
error: this.error,
|
|
28
|
-
code: this.code
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
return GTTranslationError;
|
|
32
|
-
}(Error));
|
|
33
|
-
export { GTTranslationError };
|
|
34
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Check if the target is a TranslationPromise
|
|
2
|
-
export function isTranslationPromise(target) {
|
|
3
|
-
if (typeof target !== 'object' || target === null) {
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
6
|
-
var hasPromise = 'promise' in target && target.promise instanceof Promise;
|
|
7
|
-
var hasErrorFallback = 'errorFallback' in target;
|
|
8
|
-
var hasLoadingFallback = 'loadingFallback' in target;
|
|
9
|
-
var hasHash = 'hash' in target && typeof target.hash === 'string';
|
|
10
|
-
var hasType = 'type' in target && (target.type === 'jsx' || target.type === 'content');
|
|
11
|
-
return hasPromise && hasErrorFallback && hasLoadingFallback && hasHash && hasType;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=checkTypes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkTypes.js","sourceRoot":"","sources":["../../../src/utils/checkTypes.ts"],"names":[],"mappings":"AAGA,8CAA8C;AAC9C,MAAM,UAAU,oBAAoB,CAAC,MAAe;IAClD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAM,UAAU,GAAG,SAAS,IAAI,MAAM,IAAI,MAAM,CAAC,OAAO,YAAY,OAAO,CAAC;IAC5E,IAAM,gBAAgB,GAAG,eAAe,IAAI,MAAM,CAAC;IACnD,IAAM,kBAAkB,GAAG,iBAAiB,IAAI,MAAM,CAAC;IACvD,IAAM,OAAO,GAAG,MAAM,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC;IACpE,IAAM,OAAO,GAAG,MAAM,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAEzF,OAAO,UAAU,IAAI,gBAAgB,IAAI,kBAAkB,IAAI,OAAO,IAAI,OAAO,CAAC;AACpF,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retrieves the value of an environment variable as a string.
|
|
3
|
-
*
|
|
4
|
-
* This function checks if the `process` object is defined and if the specified environment
|
|
5
|
-
* variable is set. If both conditions are met, it returns the value of the environment
|
|
6
|
-
* variable. If not, it returns an empty string.
|
|
7
|
-
*
|
|
8
|
-
* @param {string} VARIABLE - The name of the environment variable to retrieve.
|
|
9
|
-
* @returns {string} The value of the environment variable, or an empty string if the variable is not set.
|
|
10
|
-
*/
|
|
11
|
-
export default function getDefaultFromEnv(VARIABLE) {
|
|
12
|
-
var _a;
|
|
13
|
-
if (typeof process !== 'undefined' && ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a[VARIABLE])) {
|
|
14
|
-
return process.env[VARIABLE];
|
|
15
|
-
}
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=getDefaultFromEnv.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultFromEnv.js","sourceRoot":"","sources":["../../../src/utils/getDefaultFromEnv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,QAAgB;;IACtD,IAAI,OAAO,OAAO,KAAK,WAAW,KAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,0CAAG,QAAQ,CAAC,CAAA,EAAE,CAAC;QAC7D,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAW,CAAC;IAC3C,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export default function getGTProp(child) {
|
|
2
|
-
var _a;
|
|
3
|
-
if (child && typeof child === 'object' && ((_a = child.props) === null || _a === void 0 ? void 0 : _a['data-_gt'])) {
|
|
4
|
-
return child.props['data-_gt'];
|
|
5
|
-
}
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=getGTProp.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getGTProp.js","sourceRoot":"","sources":["../../../src/utils/getGTProp.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,SAAS,CAC7B,KAAU;;IAEV,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,KAAI,MAAA,KAAK,CAAC,KAAK,0CAAG,UAAU,CAAC,CAAA,EAAE,CAAC;QAClE,OAAO,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
-
import { formatCurrency } from 'generaltranslation';
|
|
25
|
-
import getI18NConfig from '../config/getI18NConfig';
|
|
26
|
-
/**
|
|
27
|
-
* The `<Currency>` component renders a formatted currency string, allowing customization of name, default value, currency type, and formatting options.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```jsx
|
|
31
|
-
* <Currency
|
|
32
|
-
* name="price"
|
|
33
|
-
* currency="USD"
|
|
34
|
-
* >
|
|
35
|
-
* 1000
|
|
36
|
-
* </Currency>
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @param {any} [children] - Optional content to render inside the currency component.
|
|
40
|
-
* @param {string} [name] - Optional name for the currency field.
|
|
41
|
-
* @param {any} [value] - The default value to be used.
|
|
42
|
-
* @param {string} [currency] - The currency type (e.g., USD, EUR, etc.).
|
|
43
|
-
* @param {Intl.NumberFormatOptions} [options] - Optional formatting options to customize how the currency is displayed.
|
|
44
|
-
* @returns {JSX.Element} The formatted currency component.
|
|
45
|
-
*/
|
|
46
|
-
function Currency(_a) {
|
|
47
|
-
var children = _a.children, name = _a.name, value = _a.value, _b = _a.currency, currency = _b === void 0 ? "USD" : _b, _c = _a.options, options = _c === void 0 ? {} : _c, _d = _a.locales, locales = _d === void 0 ? [getI18NConfig().getDefaultLocale()] : _d, props = __rest(_a, ["children", "name", "value", "currency", "options", "locales"]);
|
|
48
|
-
var generaltranslation = props["data-_gt"];
|
|
49
|
-
// Determine the value to be formatted
|
|
50
|
-
var renderedValue = (typeof children !== 'undefined' && typeof value === 'undefined') ? children : value;
|
|
51
|
-
renderedValue = (typeof renderedValue === 'string') ? parseFloat(renderedValue) : renderedValue;
|
|
52
|
-
// Format the number as currency according to the locale
|
|
53
|
-
var formattedValue = (typeof renderedValue === 'number')
|
|
54
|
-
? formatCurrency({ value: renderedValue, currency: currency, locales: locales, options: options })
|
|
55
|
-
: renderedValue;
|
|
56
|
-
return (_jsx("span", { "data-_gt": generaltranslation, "data-_gt-variable-name": name, "data-_gt-variable-type": "currency", "data-_gt-variable-options": JSON.stringify(__assign({ style: 'currency', currency: currency }, options)), "data-_gt-unformatted-value": (typeof renderedValue === 'number' && !isNaN(renderedValue)) ? renderedValue : undefined, style: { display: 'contents' }, suppressHydrationWarning: true, children: typeof formattedValue === 'string' ? formattedValue : undefined }));
|
|
57
|
-
}
|
|
58
|
-
;
|
|
59
|
-
Currency.gtTransformation = "variable-currency";
|
|
60
|
-
export default Currency;
|
|
61
|
-
//# sourceMappingURL=Currency.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Currency.js","sourceRoot":"","sources":["../../../src/variables/Currency.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,aAAa,MAAM,yBAAyB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,QAAQ,CAAC,EAgBjB;IAfG,IAAA,QAAQ,cAAA,EACR,IAAI,UAAA,EACJ,KAAK,WAAA,EACL,gBAAgB,EAAhB,QAAQ,mBAAG,KAAK,KAAA,EAChB,eAAY,EAAZ,OAAO,mBAAG,EAAE,KAAA,EACZ,eAA8C,EAA9C,OAAO,mBAAG,CAAC,aAAa,EAAE,CAAC,gBAAgB,EAAE,CAAC,KAAA,EAC3C,KAAK,cAPM,+DAQjB,CADW;IAWA,IAAY,kBAAkB,GAAK,KAAK,YAAV,CAAW;IAEjD,sCAAsC;IACtC,IAAI,aAAa,GAAG,CAAC,OAAO,QAAQ,KAAK,WAAW,IAAI,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;IACzG,aAAa,GAAG,CAAC,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;IAEhG,wDAAwD;IACxD,IAAM,cAAc,GAAG,CAAC,OAAO,aAAa,KAAK,QAAQ,CAAC;QACtD,CAAC,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