gt-next 4.2.0 → 4.2.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/dist/cjs/_dictionary.js.map +1 -0
- package/dist/cjs/_request.js.map +1 -0
- package/dist/cjs/branches/Branch.js.map +1 -0
- package/dist/cjs/branches/Plural.js.map +1 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/config/I18NConfiguration.js.map +1 -0
- package/dist/cjs/config/RemoteTranslationsManager.js.map +1 -0
- package/dist/cjs/config/getI18NConfig.js.map +1 -0
- package/dist/cjs/config/props/InitGTProps.js.map +1 -0
- package/dist/cjs/config/props/defaultInitGTProps.js.map +1 -0
- package/dist/cjs/config.js.map +1 -0
- package/dist/cjs/dictionary/getDictionary.js.map +1 -0
- package/dist/cjs/errors/createErrors.js.map +1 -0
- package/dist/cjs/index.client.js.map +1 -0
- package/dist/cjs/index.server.js.map +1 -0
- package/dist/cjs/middleware/createNextMiddleware.js.map +1 -0
- package/dist/cjs/middleware.js.map +1 -0
- package/dist/cjs/next/getNextDomain.js.map +1 -0
- package/dist/cjs/next/getNextLocale.js.map +1 -0
- package/dist/cjs/provider/ClientProvider.js.map +1 -0
- package/dist/cjs/provider/GTProvider.js.map +1 -0
- package/dist/cjs/request/getLocale.js.map +1 -0
- package/dist/cjs/request/getMetadata.js.map +1 -0
- package/dist/cjs/server/getGT.js.map +1 -0
- package/dist/cjs/server/inline/Resolver.js.map +1 -0
- package/dist/cjs/server/inline/T.js.map +1 -0
- package/dist/cjs/server/rendering/renderVariable.js.map +1 -0
- package/dist/cjs/server/strings/tx.js.map +1 -0
- package/dist/cjs/server.js.map +1 -0
- package/dist/cjs/types/types.js.map +1 -0
- package/dist/cjs/utils/checkTypes.js.map +1 -0
- package/dist/cjs/utils/getDefaultFromEnv.js.map +1 -0
- package/dist/cjs/utils/getGTProp.js.map +1 -0
- package/dist/cjs/variables/Currency.js.map +1 -0
- package/dist/cjs/variables/DateTime.js.map +1 -0
- package/dist/cjs/variables/Num.js.map +1 -0
- package/dist/cjs/variables/Var.js.map +1 -0
- package/dist/esm/_dictionary.js +4 -0
- package/dist/esm/_dictionary.js.map +1 -0
- package/dist/esm/_request.js +6 -0
- package/dist/{_request.js.map → esm/_request.js.map} +1 -1
- package/dist/esm/branches/Branch.js +45 -0
- package/dist/esm/branches/Branch.js.map +1 -0
- package/dist/esm/branches/Plural.js +45 -0
- package/dist/esm/branches/Plural.js.map +1 -0
- package/dist/esm/client.js +4 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/config/I18NConfiguration.js +379 -0
- package/dist/esm/config/I18NConfiguration.js.map +1 -0
- package/dist/esm/config/RemoteTranslationsManager.js +200 -0
- package/dist/esm/config/RemoteTranslationsManager.js.map +1 -0
- package/dist/esm/config/getI18NConfig.js +48 -0
- package/dist/esm/config/getI18NConfig.js.map +1 -0
- package/dist/esm/config/props/InitGTProps.js +2 -0
- package/dist/esm/config/props/InitGTProps.js.map +1 -0
- package/dist/esm/config/props/defaultInitGTProps.js +62 -0
- package/dist/esm/config/props/defaultInitGTProps.js.map +1 -0
- package/dist/esm/config.js +196 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/dictionary/getDictionary.js +18 -0
- package/dist/esm/dictionary/getDictionary.js.map +1 -0
- package/dist/esm/errors/createErrors.js +22 -0
- package/dist/esm/errors/createErrors.js.map +1 -0
- package/dist/esm/index.client.js +8 -0
- package/dist/esm/index.client.js.map +1 -0
- package/dist/esm/index.server.js +11 -0
- package/dist/esm/index.server.js.map +1 -0
- package/dist/esm/middleware/createNextMiddleware.js +127 -0
- package/dist/esm/middleware/createNextMiddleware.js.map +1 -0
- package/dist/esm/middleware.js +3 -0
- package/dist/esm/middleware.js.map +1 -0
- package/dist/{provider/ClientResolver.js → esm/next/getNextDomain.js} +23 -43
- package/dist/esm/next/getNextDomain.js.map +1 -0
- package/dist/esm/next/getNextLocale.js +86 -0
- package/dist/esm/next/getNextLocale.js.map +1 -0
- package/dist/esm/provider/ClientProvider.js +222 -0
- package/dist/esm/provider/ClientProvider.js.map +1 -0
- package/dist/esm/provider/GTProvider.js +226 -0
- package/dist/esm/provider/GTProvider.js.map +1 -0
- package/dist/esm/request/getLocale.js +87 -0
- package/dist/esm/request/getLocale.js.map +1 -0
- package/dist/esm/request/getMetadata.js +83 -0
- package/dist/esm/request/getMetadata.js.map +1 -0
- package/dist/esm/server/getGT.js +207 -0
- package/dist/esm/server/getGT.js.map +1 -0
- package/dist/esm/server/inline/Resolver.js +48 -0
- package/dist/esm/server/inline/Resolver.js.map +1 -0
- package/dist/esm/server/inline/T.js +221 -0
- package/dist/esm/server/inline/T.js.map +1 -0
- package/dist/esm/server/rendering/renderVariable.js +19 -0
- package/dist/esm/server/rendering/renderVariable.js.map +1 -0
- package/dist/esm/server/strings/tx.js +156 -0
- package/dist/esm/server/strings/tx.js.map +1 -0
- package/dist/esm/server.js +10 -0
- package/dist/esm/server.js.map +1 -0
- package/dist/esm/types/types.js +34 -0
- package/dist/{types → esm/types}/types.js.map +1 -1
- package/dist/esm/utils/checkTypes.js +13 -0
- package/dist/esm/utils/checkTypes.js.map +1 -0
- package/dist/esm/utils/getDefaultFromEnv.js +18 -0
- package/dist/esm/utils/getDefaultFromEnv.js.map +1 -0
- package/dist/esm/utils/getGTProp.js +8 -0
- package/dist/esm/utils/getGTProp.js.map +1 -0
- package/dist/esm/variables/Currency.js +61 -0
- package/dist/esm/variables/Currency.js.map +1 -0
- package/dist/esm/variables/DateTime.js +74 -0
- package/dist/esm/variables/DateTime.js.map +1 -0
- package/dist/esm/variables/Num.js +50 -0
- package/dist/esm/variables/Num.js.map +1 -0
- package/dist/esm/variables/Var.js +41 -0
- package/dist/esm/variables/Var.js.map +1 -0
- package/dist/types/_dictionary.d.ts.map +1 -0
- package/dist/{_request.d.ts.map → types/_request.d.ts.map} +1 -1
- package/dist/types/branches/Branch.d.ts.map +1 -0
- package/dist/types/branches/Plural.d.ts.map +1 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/config/I18NConfiguration.d.ts.map +1 -0
- package/dist/types/config/RemoteTranslationsManager.d.ts.map +1 -0
- package/dist/types/config/getI18NConfig.d.ts.map +1 -0
- package/dist/types/config/props/InitGTProps.d.ts.map +1 -0
- package/dist/types/config/props/defaultInitGTProps.d.ts.map +1 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/dictionary/getDictionary.d.ts.map +1 -0
- package/dist/types/errors/createErrors.d.ts.map +1 -0
- package/dist/types/index.client.d.ts.map +1 -0
- package/dist/types/index.server.d.ts.map +1 -0
- package/dist/types/middleware/createNextMiddleware.d.ts.map +1 -0
- package/dist/types/middleware.d.ts.map +1 -0
- package/dist/types/next/getNextDomain.d.ts.map +1 -0
- package/dist/types/next/getNextLocale.d.ts.map +1 -0
- package/dist/types/provider/ClientProvider.d.ts.map +1 -0
- package/dist/types/provider/GTProvider.d.ts.map +1 -0
- package/dist/types/request/getLocale.d.ts.map +1 -0
- package/dist/types/request/getMetadata.d.ts.map +1 -0
- package/dist/types/server/getGT.d.ts.map +1 -0
- package/dist/types/server/inline/Resolver.d.ts.map +1 -0
- package/dist/types/server/inline/T.d.ts.map +1 -0
- package/dist/types/server/rendering/renderVariable.d.ts.map +1 -0
- package/dist/types/server/strings/tx.d.ts.map +1 -0
- package/dist/types/server.d.ts.map +1 -0
- package/dist/types/types/types.d.ts.map +1 -0
- package/dist/types/utils/checkTypes.d.ts.map +1 -0
- package/dist/types/utils/getDefaultFromEnv.d.ts.map +1 -0
- package/dist/types/utils/getGTProp.d.ts.map +1 -0
- package/dist/types/variables/Currency.d.ts.map +1 -0
- package/dist/types/variables/DateTime.d.ts.map +1 -0
- package/dist/types/variables/Num.d.ts.map +1 -0
- package/dist/types/variables/Var.d.ts.map +1 -0
- package/package.json +22 -13
- package/tsconfig.base.json +20 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.esm.json +7 -0
- package/dist/_dictionary.d.ts.map +0 -1
- package/dist/_dictionary.js.map +0 -1
- package/dist/branches/Branch.d.ts.map +0 -1
- package/dist/branches/Branch.js.map +0 -1
- package/dist/branches/Plural.d.ts.map +0 -1
- package/dist/branches/Plural.js.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/config/I18NConfiguration.d.ts.map +0 -1
- package/dist/config/I18NConfiguration.js.map +0 -1
- package/dist/config/RemoteTranslationsManager.d.ts.map +0 -1
- package/dist/config/RemoteTranslationsManager.js.map +0 -1
- package/dist/config/getI18NConfig.d.ts.map +0 -1
- package/dist/config/getI18NConfig.js.map +0 -1
- package/dist/config/props/InitGTProps.d.ts.map +0 -1
- package/dist/config/props/InitGTProps.js.map +0 -1
- package/dist/config/props/defaultInitGTProps.d.ts.map +0 -1
- package/dist/config/props/defaultInitGTProps.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/dictionary/getDictionary.d.ts.map +0 -1
- package/dist/dictionary/getDictionary.js.map +0 -1
- package/dist/errors/createErrors.d.ts.map +0 -1
- package/dist/errors/createErrors.js.map +0 -1
- package/dist/index.client.d.ts.map +0 -1
- package/dist/index.client.js.map +0 -1
- package/dist/index.server.d.ts.map +0 -1
- package/dist/index.server.js.map +0 -1
- package/dist/middleware/createNextMiddleware.d.ts.map +0 -1
- package/dist/middleware/createNextMiddleware.js.map +0 -1
- package/dist/middleware.d.ts.map +0 -1
- package/dist/middleware.js.map +0 -1
- package/dist/next/getNextDomain.d.ts.map +0 -1
- package/dist/next/getNextDomain.js.map +0 -1
- package/dist/next/getNextLocale.d.ts.map +0 -1
- package/dist/next/getNextLocale.js.map +0 -1
- package/dist/provider/ClientProvider.d.ts.map +0 -1
- package/dist/provider/ClientProvider.js.map +0 -1
- package/dist/provider/ClientResolver.d.ts +0 -2
- package/dist/provider/ClientResolver.d.ts.map +0 -1
- package/dist/provider/ClientResolver.js.map +0 -1
- package/dist/provider/GTProvider.d.ts.map +0 -1
- package/dist/provider/GTProvider.js.map +0 -1
- package/dist/request/getLocale.d.ts.map +0 -1
- package/dist/request/getLocale.js.map +0 -1
- package/dist/request/getMetadata.d.ts.map +0 -1
- package/dist/request/getMetadata.js.map +0 -1
- package/dist/server/getGT.d.ts.map +0 -1
- package/dist/server/getGT.js.map +0 -1
- package/dist/server/inline/Resolver.d.ts.map +0 -1
- package/dist/server/inline/Resolver.js.map +0 -1
- package/dist/server/inline/T.d.ts.map +0 -1
- package/dist/server/inline/T.js.map +0 -1
- package/dist/server/rendering/renderVariable.d.ts.map +0 -1
- package/dist/server/rendering/renderVariable.js.map +0 -1
- package/dist/server/strings/tx.d.ts.map +0 -1
- package/dist/server/strings/tx.js.map +0 -1
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/utils/checkTypes.d.ts.map +0 -1
- package/dist/utils/checkTypes.js.map +0 -1
- package/dist/utils/getDefaultFromEnv.d.ts.map +0 -1
- package/dist/utils/getDefaultFromEnv.js.map +0 -1
- package/dist/utils/getGTProp.d.ts.map +0 -1
- package/dist/utils/getGTProp.js.map +0 -1
- package/dist/variables/Currency.d.ts.map +0 -1
- package/dist/variables/Currency.js.map +0 -1
- package/dist/variables/DateTime.d.ts.map +0 -1
- package/dist/variables/DateTime.js.map +0 -1
- package/dist/variables/Num.d.ts.map +0 -1
- package/dist/variables/Num.js.map +0 -1
- package/dist/variables/Var.d.ts.map +0 -1
- package/dist/variables/Var.js.map +0 -1
- /package/dist/{_dictionary.js → cjs/_dictionary.js} +0 -0
- /package/dist/{_request.js → cjs/_request.js} +0 -0
- /package/dist/{branches → cjs/branches}/Branch.js +0 -0
- /package/dist/{branches → cjs/branches}/Plural.js +0 -0
- /package/dist/{client.js → cjs/client.js} +0 -0
- /package/dist/{config → cjs/config}/I18NConfiguration.js +0 -0
- /package/dist/{config → cjs/config}/RemoteTranslationsManager.js +0 -0
- /package/dist/{config → cjs/config}/getI18NConfig.js +0 -0
- /package/dist/{config → cjs/config}/props/InitGTProps.js +0 -0
- /package/dist/{config → cjs/config}/props/defaultInitGTProps.js +0 -0
- /package/dist/{config.js → cjs/config.js} +0 -0
- /package/dist/{dictionary → cjs/dictionary}/getDictionary.js +0 -0
- /package/dist/{errors → cjs/errors}/createErrors.js +0 -0
- /package/dist/{index.client.js → cjs/index.client.js} +0 -0
- /package/dist/{index.server.js → cjs/index.server.js} +0 -0
- /package/dist/{middleware → cjs/middleware}/createNextMiddleware.js +0 -0
- /package/dist/{middleware.js → cjs/middleware.js} +0 -0
- /package/dist/{next → cjs/next}/getNextDomain.js +0 -0
- /package/dist/{next → cjs/next}/getNextLocale.js +0 -0
- /package/dist/{provider → cjs/provider}/ClientProvider.js +0 -0
- /package/dist/{provider → cjs/provider}/GTProvider.js +0 -0
- /package/dist/{request → cjs/request}/getLocale.js +0 -0
- /package/dist/{request → cjs/request}/getMetadata.js +0 -0
- /package/dist/{server → cjs/server}/getGT.js +0 -0
- /package/dist/{server → cjs/server}/inline/Resolver.js +0 -0
- /package/dist/{server → cjs/server}/inline/T.js +0 -0
- /package/dist/{server → cjs/server}/rendering/renderVariable.js +0 -0
- /package/dist/{server → cjs/server}/strings/tx.js +0 -0
- /package/dist/{server.js → cjs/server.js} +0 -0
- /package/dist/{types → cjs/types}/types.js +0 -0
- /package/dist/{utils → cjs/utils}/checkTypes.js +0 -0
- /package/dist/{utils → cjs/utils}/getDefaultFromEnv.js +0 -0
- /package/dist/{utils → cjs/utils}/getGTProp.js +0 -0
- /package/dist/{variables → cjs/variables}/Currency.js +0 -0
- /package/dist/{variables → cjs/variables}/DateTime.js +0 -0
- /package/dist/{variables → cjs/variables}/Num.js +0 -0
- /package/dist/{variables → cjs/variables}/Var.js +0 -0
- /package/dist/{_dictionary.d.ts → types/_dictionary.d.ts} +0 -0
- /package/dist/{_request.d.ts → types/_request.d.ts} +0 -0
- /package/dist/{branches → types/branches}/Branch.d.ts +0 -0
- /package/dist/{branches → types/branches}/Plural.d.ts +0 -0
- /package/dist/{client.d.ts → types/client.d.ts} +0 -0
- /package/dist/{config → types/config}/I18NConfiguration.d.ts +0 -0
- /package/dist/{config → types/config}/RemoteTranslationsManager.d.ts +0 -0
- /package/dist/{config → types/config}/getI18NConfig.d.ts +0 -0
- /package/dist/{config → types/config}/props/InitGTProps.d.ts +0 -0
- /package/dist/{config → types/config}/props/defaultInitGTProps.d.ts +0 -0
- /package/dist/{config.d.ts → types/config.d.ts} +0 -0
- /package/dist/{dictionary → types/dictionary}/getDictionary.d.ts +0 -0
- /package/dist/{errors → types/errors}/createErrors.d.ts +0 -0
- /package/dist/{index.client.d.ts → types/index.client.d.ts} +0 -0
- /package/dist/{index.server.d.ts → types/index.server.d.ts} +0 -0
- /package/dist/{middleware → types/middleware}/createNextMiddleware.d.ts +0 -0
- /package/dist/{middleware.d.ts → types/middleware.d.ts} +0 -0
- /package/dist/{next → types/next}/getNextDomain.d.ts +0 -0
- /package/dist/{next → types/next}/getNextLocale.d.ts +0 -0
- /package/dist/{provider → types/provider}/ClientProvider.d.ts +0 -0
- /package/dist/{provider → types/provider}/GTProvider.d.ts +0 -0
- /package/dist/{request → types/request}/getLocale.d.ts +0 -0
- /package/dist/{request → types/request}/getMetadata.d.ts +0 -0
- /package/dist/{server → types/server}/getGT.d.ts +0 -0
- /package/dist/{server → types/server}/inline/Resolver.d.ts +0 -0
- /package/dist/{server → types/server}/inline/T.d.ts +0 -0
- /package/dist/{server → types/server}/rendering/renderVariable.d.ts +0 -0
- /package/dist/{server → types/server}/strings/tx.d.ts +0 -0
- /package/dist/{server.d.ts → types/server.d.ts} +0 -0
- /package/dist/types/{types.d.ts → types/types.d.ts} +0 -0
- /package/dist/{utils → types/utils}/checkTypes.d.ts +0 -0
- /package/dist/{utils → types/utils}/getDefaultFromEnv.d.ts +0 -0
- /package/dist/{utils → types/utils}/getGTProp.d.ts +0 -0
- /package/dist/{variables → types/variables}/Currency.d.ts +0 -0
- /package/dist/{variables → types/variables}/DateTime.d.ts +0 -0
- /package/dist/{variables → types/variables}/Num.d.ts +0 -0
- /package/dist/{variables → types/variables}/Var.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InitGTProps.js","sourceRoot":"","sources":["../../../../src/config/props/InitGTProps.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
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);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { libraryDefaultLocale, defaultCacheUrl, defaultRuntimeApiUrl } from "generaltranslation/internal";
|
|
38
|
+
import getDefaultFromEnv from "../../utils/getDefaultFromEnv";
|
|
39
|
+
import { listSupportedLocales } from "@generaltranslation/supported-locales";
|
|
40
|
+
var defaultInitGTProps = {
|
|
41
|
+
remoteCache: true,
|
|
42
|
+
runtimeTranslation: true,
|
|
43
|
+
apiKey: getDefaultFromEnv('GT_API_KEY'),
|
|
44
|
+
devApiKey: '',
|
|
45
|
+
projectId: getDefaultFromEnv('GT_PROJECT_ID'),
|
|
46
|
+
runtimeUrl: defaultRuntimeApiUrl,
|
|
47
|
+
cacheUrl: defaultCacheUrl,
|
|
48
|
+
cacheExpiryTime: 60000,
|
|
49
|
+
defaultLocale: libraryDefaultLocale,
|
|
50
|
+
getLocale: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
51
|
+
return [2 /*return*/, libraryDefaultLocale];
|
|
52
|
+
}); }); },
|
|
53
|
+
locales: listSupportedLocales(),
|
|
54
|
+
getMetadata: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
55
|
+
return [2 /*return*/, ({})];
|
|
56
|
+
}); }); },
|
|
57
|
+
maxConcurrentRequests: 100,
|
|
58
|
+
maxBatchSize: 25,
|
|
59
|
+
batchInterval: 50
|
|
60
|
+
};
|
|
61
|
+
export default defaultInitGTProps;
|
|
62
|
+
//# sourceMappingURL=defaultInitGTProps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultInitGTProps.js","sourceRoot":"","sources":["../../../../src/config/props/defaultInitGTProps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAC1G,OAAO,iBAAiB,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAE7E,IAAM,kBAAkB,GAAG;IACvB,WAAW,EAAE,IAAI;IACjB,kBAAkB,EAAE,IAAI;IACxB,MAAM,EAAE,iBAAiB,CAAC,YAAY,CAAC;IACvC,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,iBAAiB,CAAC,eAAe,CAAC;IAC7C,UAAU,EAAE,oBAAoB;IAChC,QAAQ,EAAE,eAAe;IACzB,eAAe,EAAE,KAAK;IACtB,aAAa,EAAE,oBAAoB;IACnC,SAAS,EAAE;QAAY,sBAAA,oBAAoB,EAAA;aAAA;IAC3C,OAAO,EAAE,oBAAoB,EAAE;IAC/B,WAAW,EAAE;QAAY,sBAAA,CAAC,EAAE,CAAC,EAAA;aAAA;IAC7B,qBAAqB,EAAE,GAAG;IAC1B,YAAY,EAAE,EAAE;IAChB,aAAa,EAAE,EAAE;CACX,CAAC;AAEX,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
24
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
25
|
+
if (ar || !(i in from)) {
|
|
26
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
27
|
+
ar[i] = from[i];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
31
|
+
};
|
|
32
|
+
import path from 'path';
|
|
33
|
+
import fs from 'fs';
|
|
34
|
+
import defaultInitGTProps from './config/props/defaultInitGTProps';
|
|
35
|
+
import { APIKeyMissingError, createUnsupportedLocalesWarning, projectIdMissingError } from './errors/createErrors';
|
|
36
|
+
import { getSupportedLocale } from '@generaltranslation/supported-locales';
|
|
37
|
+
import { defaultRenderSettings } from "gt-react/internal";
|
|
38
|
+
/**
|
|
39
|
+
* Initializes General Translation settings for a Next.js application.
|
|
40
|
+
*
|
|
41
|
+
* Use it in `next.config.js` to enable GT translation functionality as a plugin.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* // In next.config.mjs
|
|
45
|
+
* import { initGT } from 'gt-next/config';
|
|
46
|
+
*
|
|
47
|
+
* const withGT = initGT({
|
|
48
|
+
* projectId: 'abc-123',
|
|
49
|
+
* locales: ['en', 'es', 'fr'],
|
|
50
|
+
* defaultLocale: 'en'
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* export default withGT({})
|
|
54
|
+
*
|
|
55
|
+
* @param {string|undefined} config - Optional config filepath (defaults to './gt.config.json'). If a file is found, it will be parsed for GT config variables.
|
|
56
|
+
* @param {string|undefined} i18n - Optional i18n configuration file path. If a string is provided, it will be used as a path.
|
|
57
|
+
* @param {string|undefined} dictionary - Optional dictionary configuration file path. If a string is provided, it will be used as a path.
|
|
58
|
+
* @param {string} [apiKey=defaultInitGTProps.apiKey] - API key for the GeneralTranslation service. Required if using the default GT base URL.
|
|
59
|
+
* @param {string} [devApiKey=defaultInitGTProps.devApiKey] - API key for dev environment only.
|
|
60
|
+
* @param {string} [projectId=defaultInitGTProps.projectId] - Project ID for the GeneralTranslation service. Required for most functionality.
|
|
61
|
+
* @param {string} [runtimeUrl=defaultInitGTProps.runtimeUrl] - The base URL for the GT API. Set to an empty string to disable automatic translations.
|
|
62
|
+
* @param {string} [cacheUrl=defaultInitGTProps.cacheUrl] - The URL for cached translations.
|
|
63
|
+
* @param {number} [cacheExpiryTime=defaultInitGTProps.cacheExpiryTime] - How long to cache translations in memory (milliseconds).
|
|
64
|
+
* @param {boolean} [runtimeTranslation=defaultInitGTProps.runtimeTranslation] - Whether to enable runtime translation.
|
|
65
|
+
* @param {boolean} [remoteCache=defaultInitGTProps.remoteCache] - Whether to enable remote caching of translations.
|
|
66
|
+
* @param {string[]} [locales=defaultInitGTProps.locales] - List of supported locales for the application.
|
|
67
|
+
* @param {string} [defaultLocale=defaultInitGTProps.defaultLocale] - The default locale to use if none is specified.
|
|
68
|
+
* @param {object} [renderSettings=defaultInitGTProps.renderSettings] - Render settings for how translations should be handled.
|
|
69
|
+
* @param {number} [maxConcurrentRequests=defaultInitGTProps.maxConcurrentRequests] - Maximum number of concurrent requests allowed.
|
|
70
|
+
* @param {number} [maxBatchSize=defaultInitGTProps.maxBatchSize] - Maximum translation requests in the same batch.
|
|
71
|
+
* @param {number} [batchInterval=defaultInitGTProps.batchInterval] - The interval in milliseconds between batched translation requests.
|
|
72
|
+
* @param {object} metadata - Additional metadata that can be passed for extended configuration.
|
|
73
|
+
*
|
|
74
|
+
* @returns {function(NextConfig): NextConfig} - A function that accepts a Next.js config object and returns an updated config with GT settings applied.
|
|
75
|
+
*
|
|
76
|
+
* @throws {Error} If the project ID is missing and default URLs are used, or if the API key is required and missing.
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
79
|
+
export function initGT(_a) {
|
|
80
|
+
var _b, _c;
|
|
81
|
+
if (_a === void 0) { _a = defaultInitGTProps; }
|
|
82
|
+
var _d = _a.config, config = _d === void 0 ? './gt.config.json' : _d, i18n = _a.i18n, dictionary = _a.dictionary, _e = _a.runtimeTranslation, runtimeTranslation = _e === void 0 ? defaultInitGTProps.runtimeTranslation : _e, _f = _a.remoteCache, remoteCache = _f === void 0 ? defaultInitGTProps.remoteCache : _f, _g = _a.apiKey, apiKey = _g === void 0 ? defaultInitGTProps.apiKey : _g, devApiKey = _a.devApiKey, _h = _a.projectId, projectId = _h === void 0 ? defaultInitGTProps.projectId : _h, _j = _a.runtimeUrl, runtimeUrl = _j === void 0 ? defaultInitGTProps.runtimeUrl : _j, _k = _a.cacheUrl, cacheUrl = _k === void 0 ? defaultInitGTProps.cacheUrl : _k, _l = _a.cacheExpiryTime, cacheExpiryTime = _l === void 0 ? defaultInitGTProps.cacheExpiryTime : _l, _m = _a.locales, locales = _m === void 0 ? defaultInitGTProps.locales : _m, _o = _a.defaultLocale, defaultLocale = _o === void 0 ? defaultInitGTProps.defaultLocale : _o, renderSettings = _a.renderSettings, _p = _a.maxConcurrentRequests, maxConcurrentRequests = _p === void 0 ? defaultInitGTProps.maxConcurrentRequests : _p, _q = _a.maxBatchSize, maxBatchSize = _q === void 0 ? defaultInitGTProps.maxBatchSize : _q, _r = _a.batchInterval, batchInterval = _r === void 0 ? defaultInitGTProps.batchInterval : _r, metadata = __rest(_a, ["config", "i18n", "dictionary", "runtimeTranslation", "remoteCache", "apiKey", "devApiKey", "projectId", "runtimeUrl", "cacheUrl", "cacheExpiryTime", "locales", "defaultLocale", "renderSettings", "maxConcurrentRequests", "maxBatchSize", "batchInterval"]);
|
|
83
|
+
// Load from config file if it's a string and exists
|
|
84
|
+
var loadedConfig = {};
|
|
85
|
+
try {
|
|
86
|
+
if (typeof config === 'string' && fs.existsSync(config)) {
|
|
87
|
+
var fileContent = fs.readFileSync(config, 'utf-8');
|
|
88
|
+
loadedConfig = JSON.parse(fileContent);
|
|
89
|
+
}
|
|
90
|
+
if (((_b = loadedConfig.locales) === null || _b === void 0 ? void 0 : _b.length) === 0) {
|
|
91
|
+
loadedConfig.locales = locales;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error('Error reading GT config file:', error);
|
|
96
|
+
}
|
|
97
|
+
// Merge loaded file config, default props, and function args
|
|
98
|
+
var mergedConfig = __assign(__assign(__assign({}, defaultInitGTProps), loadedConfig), __assign({ i18n: i18n, dictionary: dictionary, runtimeTranslation: runtimeTranslation, remoteCache: remoteCache, apiKey: apiKey, devApiKey: devApiKey, projectId: projectId, runtimeUrl: runtimeUrl, cacheUrl: cacheUrl, cacheExpiryTime: cacheExpiryTime, locales: locales, defaultLocale: defaultLocale, renderSettings: renderSettings || defaultRenderSettings, maxConcurrentRequests: maxConcurrentRequests, maxBatchSize: maxBatchSize, batchInterval: batchInterval }, metadata));
|
|
99
|
+
// Destructure final config
|
|
100
|
+
var finalI18n = mergedConfig.i18n, finalDictionary = mergedConfig.dictionary, finalRuntimeTranslation = mergedConfig.runtimeTranslation, finalRemoteCache = mergedConfig.remoteCache, finalApiKey = mergedConfig.apiKey, finalDevApiKey = mergedConfig.devApiKey, finalProjectId = mergedConfig.projectId, finalRuntimeUrl = mergedConfig.runtimeUrl, finalCacheUrl = mergedConfig.cacheUrl, finalCacheExpiryTime = mergedConfig.cacheExpiryTime, finalLocales = mergedConfig.locales, finalDefaultLocale = mergedConfig.defaultLocale, finalRenderSettings = mergedConfig.renderSettings, finalMaxConcurrentRequests = mergedConfig.maxConcurrentRequests, finalMaxBatchSize = mergedConfig.maxBatchSize, finalBatchInterval = mergedConfig.batchInterval, restMetadata = __rest(mergedConfig, ["i18n", "dictionary", "runtimeTranslation", "remoteCache", "apiKey", "devApiKey", "projectId", "runtimeUrl", "cacheUrl", "cacheExpiryTime", "locales", "defaultLocale", "renderSettings", "maxConcurrentRequests", "maxBatchSize", "batchInterval"]);
|
|
101
|
+
// ----- ERROR CHECKS ----- //
|
|
102
|
+
if (finalRuntimeTranslation || finalRemoteCache) {
|
|
103
|
+
if (!finalProjectId) {
|
|
104
|
+
console.error(projectIdMissingError);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
var envApiKey = process.env.GT_API_KEY || '';
|
|
108
|
+
var apiKeyType = (_c = envApiKey.split('-')) === null || _c === void 0 ? void 0 : _c[1];
|
|
109
|
+
var resolvedApiKey = finalApiKey;
|
|
110
|
+
var resolvedDevApiKey = finalDevApiKey;
|
|
111
|
+
if (apiKeyType === 'api') {
|
|
112
|
+
resolvedApiKey = envApiKey;
|
|
113
|
+
}
|
|
114
|
+
else if (apiKeyType === 'dev') {
|
|
115
|
+
resolvedDevApiKey = envApiKey;
|
|
116
|
+
}
|
|
117
|
+
if (finalRuntimeTranslation && !resolvedApiKey && !resolvedDevApiKey) {
|
|
118
|
+
console.error(APIKeyMissingError);
|
|
119
|
+
}
|
|
120
|
+
if (finalRuntimeUrl === defaultInitGTProps.runtimeUrl ||
|
|
121
|
+
finalCacheUrl === defaultInitGTProps.cacheUrl) {
|
|
122
|
+
var warningLocales = (finalLocales || defaultInitGTProps.locales).filter(function (locale) { return !getSupportedLocale(locale); });
|
|
123
|
+
if (warningLocales.length)
|
|
124
|
+
console.warn(createUnsupportedLocalesWarning(warningLocales));
|
|
125
|
+
}
|
|
126
|
+
// Store config params in environment variable to allow for global access (in some cases)
|
|
127
|
+
var I18NConfigParams = JSON.stringify(__assign({ remoteCache: finalRemoteCache, runtimeTranslation: finalRuntimeTranslation, apiKey: resolvedApiKey, devApiKey: resolvedDevApiKey, projectId: finalProjectId, runtimeUrl: finalRuntimeUrl, cacheUrl: finalCacheUrl, cacheExpiryTime: finalCacheExpiryTime, locales: finalLocales, defaultLocale: finalDefaultLocale, renderSettings: finalRenderSettings, maxConcurrentRequests: finalMaxConcurrentRequests, maxBatchSize: finalMaxBatchSize, batchInterval: finalBatchInterval }, restMetadata));
|
|
128
|
+
// Resolve i18n and dictionary paths
|
|
129
|
+
var resolvedI18NFilePath = typeof finalI18n === 'string' ? finalI18n : resolveConfigFilepath('i18n');
|
|
130
|
+
var resolvedDictionaryFilePath = typeof finalDictionary === 'string'
|
|
131
|
+
? finalDictionary
|
|
132
|
+
: resolveConfigFilepath('dictionary');
|
|
133
|
+
return function (nextConfig) {
|
|
134
|
+
if (nextConfig === void 0) { nextConfig = {}; }
|
|
135
|
+
return __assign(__assign({}, nextConfig), { env: __assign(__assign({}, nextConfig.env), { _GENERALTRANSLATION_I18N_CONFIG_PARAMS: I18NConfigParams }), webpack: function webpack() {
|
|
136
|
+
var _a = [];
|
|
137
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
138
|
+
_a[_i] = arguments[_i];
|
|
139
|
+
}
|
|
140
|
+
var webpackConfig = _a[0], options = _a[1];
|
|
141
|
+
if (resolvedI18NFilePath) {
|
|
142
|
+
webpackConfig.resolve.alias['gt-next/_request'] = path.resolve(webpackConfig.context, resolvedI18NFilePath);
|
|
143
|
+
}
|
|
144
|
+
if (resolvedDictionaryFilePath) {
|
|
145
|
+
webpackConfig.resolve.alias['gt-next/_dictionary'] = path.resolve(webpackConfig.context, resolvedDictionaryFilePath);
|
|
146
|
+
}
|
|
147
|
+
if (typeof (nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.webpack) === 'function') {
|
|
148
|
+
return nextConfig.webpack(webpackConfig, options);
|
|
149
|
+
}
|
|
150
|
+
return webpackConfig;
|
|
151
|
+
} });
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Resolves a configuration filepath for i18n or dictionary files.
|
|
156
|
+
*
|
|
157
|
+
* @param {string} fileName - The base name of the config file to look for.
|
|
158
|
+
* @param {string} [cwd] - An optional current working directory path.
|
|
159
|
+
* @returns {string|undefined} - The path if found; otherwise undefined.
|
|
160
|
+
*/
|
|
161
|
+
function resolveConfigFilepath(fileName, cwd) {
|
|
162
|
+
function resolvePath(pathname) {
|
|
163
|
+
var parts = [];
|
|
164
|
+
if (cwd)
|
|
165
|
+
parts.push(cwd);
|
|
166
|
+
parts.push(pathname);
|
|
167
|
+
return path.resolve.apply(path, parts);
|
|
168
|
+
}
|
|
169
|
+
function pathExists(pathname) {
|
|
170
|
+
return fs.existsSync(resolvePath(pathname));
|
|
171
|
+
}
|
|
172
|
+
// Check for file existence in the root and src directories with supported extensions
|
|
173
|
+
for (var _i = 0, _a = __spreadArray(__spreadArray([], withExtensions("./".concat(fileName)), true), withExtensions("./src/".concat(fileName)), true); _i < _a.length; _i++) {
|
|
174
|
+
var candidate = _a[_i];
|
|
175
|
+
if (pathExists(candidate)) {
|
|
176
|
+
return candidate;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Return undefined if no file is found
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Helper function to handle multiple extensions.
|
|
184
|
+
*
|
|
185
|
+
* @param {string} localPath - The local path to which extensions will be appended.
|
|
186
|
+
* @returns {string[]} - Array of possible paths with supported TypeScript/JavaScript extensions.
|
|
187
|
+
*/
|
|
188
|
+
function withExtensions(localPath) {
|
|
189
|
+
return [
|
|
190
|
+
"".concat(localPath, ".ts"),
|
|
191
|
+
"".concat(localPath, ".tsx"),
|
|
192
|
+
"".concat(localPath, ".js"),
|
|
193
|
+
"".concat(localPath, ".jsx"),
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,kBAAkB,MAAM,mCAAmC,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,+BAA+B,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,MAAM,CAAC,EAmBY;;IAnBZ,mBAAA,EAAA,uBAmBY;IAlBjC,IAAA,cAA2B,EAA3B,MAAM,mBAAG,kBAAkB,KAAA,EAC3B,IAAI,UAAA,EACJ,UAAU,gBAAA,EACV,0BAA0D,EAA1D,kBAAkB,mBAAG,kBAAkB,CAAC,kBAAkB,KAAA,EAC1D,mBAA4C,EAA5C,WAAW,mBAAG,kBAAkB,CAAC,WAAW,KAAA,EAC5C,cAAkC,EAAlC,MAAM,mBAAG,kBAAkB,CAAC,MAAM,KAAA,EAClC,S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B,GAAY;IAEZ,SAAS,WAAW,CAAC,QAAgB;QACnC,IAAM,KAAK,GAAG,EAAE,CAAC;QACjB,IAAI,GAAG;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC,OAAO,OAAZ,IAAI,EAAY,KAAK,EAAE;IAChC,CAAC;IAED,SAAS,UAAU,CAAC,QAAgB;QAClC,OAAO,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,qFAAqF;IACrF,KAAwB,UAGvB,EAHuB,qCACnB,cAAc,CAAC,YAAK,QAAQ,CAAE,CAAC,SAC/B,cAAc,CAAC,gBAAS,QAAQ,CAAE,CAAC,OACvC,EAHuB,cAGvB,EAHuB,IAGvB,EAAE,CAAC;QAHC,IAAM,SAAS,SAAA;QAIlB,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1B,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,uCAAuC;IACvC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,SAAiB;IACvC,OAAO;QACL,UAAG,SAAS,QAAK;QACjB,UAAG,SAAS,SAAM;QAClB,UAAG,SAAS,QAAK;QACjB,UAAG,SAAS,SAAM;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getDictionaryEntry as getEntry } from "gt-react/internal";
|
|
2
|
+
var dictionary;
|
|
3
|
+
export default function getDictionary() {
|
|
4
|
+
if (dictionary)
|
|
5
|
+
return dictionary;
|
|
6
|
+
try {
|
|
7
|
+
dictionary = require('gt-next/_dictionary').default;
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
dictionary = {};
|
|
11
|
+
}
|
|
12
|
+
return dictionary;
|
|
13
|
+
}
|
|
14
|
+
export function getDictionaryEntry(id) {
|
|
15
|
+
var obj = getDictionary();
|
|
16
|
+
return getEntry(obj, id);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=getDictionary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDictionary.js","sourceRoot":"","sources":["../../../src/dictionary/getDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,IAAI,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEnE,IAAI,UAA+B,CAAC;AAEpC,MAAM,CAAC,OAAO,UAAU,aAAa;IACjC,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC;IAClC,IAAI,CAAC;QACD,UAAU,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,UAAU,GAAG,EAAE,CAAC;IACpB,CAAC;IACD,OAAO,UAAU,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,EAAU;IACzC,IAAM,GAAG,GAAG,aAAa,EAAE,CAAC;IAC5B,OAAO,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// ---- ERRORS ---- //
|
|
2
|
+
import { getLocaleProperties } from "generaltranslation";
|
|
3
|
+
export var projectIdMissingError = 'General Translation: Project ID missing! Set projectId as GT_PROJECT_ID in the environment or by passing the projectId parameter to initGT(). Find your project ID: www.generaltranslation.com/dashboard.';
|
|
4
|
+
export var APIKeyMissingError = 'General Translation: API key is required for runtime translation! Create an API key: www.generaltranslation.com/dashboard/api-keys. (Or, turn off runtime translation by setting runtimeUrl to an empty string.)';
|
|
5
|
+
export var remoteTranslationsError = 'General Translation: Error fetching remote translation.';
|
|
6
|
+
export var renderingError = 'General Translation: Rendering error.';
|
|
7
|
+
export var createStringTranslationError = function (content, id) { return "gt-next string translation error. tx(\"".concat(content, "\")").concat(id ? " with id \"".concat(id, "\"") : '', " failed."); };
|
|
8
|
+
export var createRequiredPrefixError = function (id, requiredPrefix) {
|
|
9
|
+
return "You are using <GTProvider> with a provided prefix id: \"".concat(requiredPrefix, "\", but one of the children of <GTProvider> has the id \"").concat(id, "\". Change the <GTProvider> id prop or your dictionary structure to proceed.");
|
|
10
|
+
};
|
|
11
|
+
export var devApiKeyIncludedInProductionError = "General Translation: You are attempting a production build of your app with a developer API key (beginning \"gtx-dev-\"). Replace this API key with a production API key (beginning \"gtx-api-\") when you build your app for production.";
|
|
12
|
+
export var createDictionarySubsetError = function (id, functionName) {
|
|
13
|
+
return "General Translation: ".concat(functionName, " with id: \"").concat(id, "\". Invalid dictionary entry detected. Make sure you are navigating to the correct subroute of the dictionary with the ID you provide.");
|
|
14
|
+
};
|
|
15
|
+
// ---- WARNINGS ---- //
|
|
16
|
+
export var usingDefaultsWarning = 'General Translation: Unable to access gt-next configuration. Using defaults.';
|
|
17
|
+
export var createNoEntryWarning = function (id) { return "gt-next: No dictionary entry found for id: \"".concat(id, "\""); };
|
|
18
|
+
export var createUnsupportedLocalesWarning = function (locales) { return "General Translation: The following locales are currently unsupported by our service: ".concat(locales.map(function (locale) {
|
|
19
|
+
var name = getLocaleProperties(locale).name;
|
|
20
|
+
return "".concat(locale, " (").concat(name, ")");
|
|
21
|
+
}).join(', ')); };
|
|
22
|
+
//# sourceMappingURL=createErrors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createErrors.js","sourceRoot":"","sources":["../../../src/errors/createErrors.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,MAAM,CAAC,IAAM,qBAAqB,GAAG,2MAA2M,CAAA;AAEhP,MAAM,CAAC,IAAM,kBAAkB,GAAG,kNAAkN,CAAA;AAEpP,MAAM,CAAC,IAAM,uBAAuB,GAAG,yDAAyD,CAAA;AAEhG,MAAM,CAAC,IAAM,cAAc,GAAG,uCAAuC,CAAA;AAErE,MAAM,CAAC,IAAM,4BAA4B,GAAG,UAAC,OAAe,EAAE,EAAW,IAAK,OAAA,iDAAyC,OAAO,gBAAK,EAAE,CAAC,CAAC,CAAC,qBAAa,EAAE,OAAG,CAAC,CAAC,CAAC,EAAE,aAAW,EAA5F,CAA4F,CAAA;AAE1K,MAAM,CAAC,IAAM,yBAAyB,GAAG,UAAC,EAAU,EAAE,cAAsB;IACxE,OAAA,kEAA0D,cAAc,sEAA0D,EAAE,iFAA6E;AAAjN,CAAiN,CAAA;AAErN,MAAM,CAAC,IAAM,kCAAkC,GAAG,2OAAuO,CAAA;AAEzR,MAAM,CAAC,IAAM,2BAA2B,GAAG,UAAC,EAAU,EAAE,YAAoB;IACxE,OAAA,+BAAwB,YAAY,yBAAc,EAAE,2IAAuI;AAA3L,CAA2L,CAAA;AAE/L,wBAAwB;AAExB,MAAM,CAAC,IAAM,oBAAoB,GAAG,8EAA8E,CAAC;AAEnH,MAAM,CAAC,IAAM,oBAAoB,GAAG,UAAC,EAAU,IAAK,OAAA,uDAA+C,EAAE,OAAG,EAApD,CAAoD,CAAA;AAExG,MAAM,CAAC,IAAM,+BAA+B,GAAG,UAAC,OAAiB,IAAK,OAAA,+FAAwF,OAAO,CAAC,GAAG,CAAC,UAAA,MAAM;IACpK,IAAA,IAAI,GAAK,mBAAmB,CAAC,MAAM,CAAC,KAAhC,CAAiC;IAC7C,OAAO,UAAG,MAAM,eAAK,IAAI,MAAG,CAAA;AAChC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAE,EAHuD,CAGvD,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useElement, Var, Num, Currency, DateTime, T, Branch, Plural } from "gt-react";
|
|
2
|
+
function GTProvider(params) {
|
|
3
|
+
throw new Error("You're attempting to import <GTProvider> on the client. "
|
|
4
|
+
+ "Are you sure you want to do this? It's better to import <GTProvider> in a file not marked 'use client' so that it can fetch translations on the server. "
|
|
5
|
+
+ "If you really need to put <GTProvider> on the client, import <GTProvider> from 'gt-react' instead (discouraged in server-first apps).");
|
|
6
|
+
}
|
|
7
|
+
export { GTProvider, T, useElement, Var, Num, Currency, DateTime, Branch, Plural };
|
|
8
|
+
//# sourceMappingURL=index.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.client.js","sourceRoot":"","sources":["../../src/index.client.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAC9D,MAAM,UAAU,CAAC;AAElB,SAAS,UAAU,CAAC,MAGnB;IACG,MAAM,IAAI,KAAK,CACX,0DAA0D;UACxD,0JAA0J;UAC1J,uIAAuI,CAC5I,CAAA;AACL,CAAC;AAED,OAAO,EACH,UAAU,EAAE,CAAC,EAAE,UAAU,EACzB,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAC5B,MAAM,EAAE,MAAM,EACjB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Var from './variables/Var';
|
|
2
|
+
import Num from './variables/Num';
|
|
3
|
+
import Currency from './variables/Currency';
|
|
4
|
+
import DateTime from './variables/DateTime';
|
|
5
|
+
import { useElement } from './server/getGT';
|
|
6
|
+
import GTProvider from './provider/GTProvider';
|
|
7
|
+
import T from './server/inline/T';
|
|
8
|
+
import Branch from './branches/Branch';
|
|
9
|
+
import Plural from './branches/Plural';
|
|
10
|
+
export { GTProvider, T, useElement, Var, Num, Currency, DateTime, Branch, Plural };
|
|
11
|
+
//# sourceMappingURL=index.server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.server.js","sourceRoot":"","sources":["../../src/index.server.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,iBAAiB,CAAA;AACjC,OAAO,GAAG,MAAM,iBAAiB,CAAA;AACjC,OAAO,QAAQ,MAAM,sBAAsB,CAAA;AAC3C,OAAO,QAAQ,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,UAAU,MAAM,uBAAuB,CAAA;AAC9C,OAAO,CAAC,MAAM,mBAAmB,CAAA;AACjC,OAAO,MAAM,MAAM,mBAAmB,CAAA;AACtC,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,OAAO,EACH,UAAU,EAAE,CAAC,EAAE,UAAU,EACzB,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAC5B,MAAM,EAAE,MAAM,EACjB,CAAA"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { isValidLocale, determineLocale, standardizeLocale, isSameDialect } from "generaltranslation";
|
|
2
|
+
// import { ResponseCookies, RequestCookies } from "next/dist/compiled/@edge-runtime/cookies";
|
|
3
|
+
import { libraryDefaultLocale, localeCookieName, localeHeaderName } from 'generaltranslation/internal';
|
|
4
|
+
import { listSupportedLocales } from "@generaltranslation/supported-locales";
|
|
5
|
+
import { createUnsupportedLocalesWarning } from "../errors/createErrors";
|
|
6
|
+
import { NextResponse } from "next/server";
|
|
7
|
+
/**
|
|
8
|
+
* Extracts the locale from the given pathname.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} pathname - The pathname to extract from.
|
|
11
|
+
* @returns {string} The extracted locale.
|
|
12
|
+
*/
|
|
13
|
+
function extractLocale(pathname) {
|
|
14
|
+
var matches = pathname.match(/^\/([^\/]+)(?:\/|$)/);
|
|
15
|
+
return matches ? matches[1] : null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Middleware factory to create a Next.js middleware for i18n routing and locale detection.
|
|
19
|
+
*
|
|
20
|
+
* This middleware sets a cookie based on the locale derived from several sources
|
|
21
|
+
* such as the request pathname, referer, or 'Accept-Language' header.
|
|
22
|
+
* If locale routing is enabled, it redirects to the localized pathname and
|
|
23
|
+
* updates the locale cookie.
|
|
24
|
+
*
|
|
25
|
+
* @param {Object} config - Configuration object for the middleware.
|
|
26
|
+
* @param {string} [config.defaultLocale='en'] - The default locale to use if no locale is detected.
|
|
27
|
+
* @param {string[]} [config.locales] - Array of supported locales. If provided, the locale will be validated against this list.
|
|
28
|
+
* @param {boolean} [config.localeRouting=true] - Flag to enable or disable automatic locale-based routing.
|
|
29
|
+
* @returns {function} - A middleware function that processes the request and response.
|
|
30
|
+
*/
|
|
31
|
+
export default function createNextMiddleware(_a) {
|
|
32
|
+
var _b = _a === void 0 ? {
|
|
33
|
+
defaultLocale: libraryDefaultLocale, localeRouting: true, prefixDefaultLocale: false
|
|
34
|
+
} : _a, _c = _b.defaultLocale, defaultLocale = _c === void 0 ? libraryDefaultLocale : _c, _d = _b.locales, locales = _d === void 0 ? listSupportedLocales() : _d, _e = _b.localeRouting, localeRouting = _e === void 0 ? true : _e, _f = _b.prefixDefaultLocale, prefixDefaultLocale = _f === void 0 ? false : _f;
|
|
35
|
+
if (!isValidLocale(defaultLocale))
|
|
36
|
+
throw new Error("gt-next middleware: defaultLocale \"".concat(defaultLocale, "\" is not a valid locale."));
|
|
37
|
+
var warningLocales = locales.filter(function (locale) { return !isValidLocale(locale); });
|
|
38
|
+
if (warningLocales.length)
|
|
39
|
+
console.warn(createUnsupportedLocalesWarning(warningLocales));
|
|
40
|
+
var approvedLocales = locales;
|
|
41
|
+
/**
|
|
42
|
+
* Processes the incoming request to determine the user's locale and sets a locale cookie.
|
|
43
|
+
* Optionally redirects the user based on the locale if locale-based routing is enabled.
|
|
44
|
+
*
|
|
45
|
+
* - Checks if the request URL contains a locale.
|
|
46
|
+
* - Falls back to the referer URL for locale if needed.
|
|
47
|
+
* - If no locale is found in the URL or referer, it checks the 'Accept-Language' header.
|
|
48
|
+
* - Sets a cookie with the detected or default locale.
|
|
49
|
+
* - Redirects to the correct locale route if locale routing is enabled.
|
|
50
|
+
*
|
|
51
|
+
* @param {any} req - The incoming request object, containing URL and headers.
|
|
52
|
+
* @returns {NextResponse} - The Next.js response, either continuing the request or redirecting to the localized URL.
|
|
53
|
+
*/
|
|
54
|
+
function nextMiddleware(req) {
|
|
55
|
+
var _a;
|
|
56
|
+
var headerList = new Headers(req.headers);
|
|
57
|
+
var res = NextResponse.next();
|
|
58
|
+
var userLocale = standardizeLocale(defaultLocale);
|
|
59
|
+
if (localeRouting) {
|
|
60
|
+
// Check if there is any supported locale in the pathname
|
|
61
|
+
var pathname = req.nextUrl.pathname;
|
|
62
|
+
var locale = extractLocale(pathname);
|
|
63
|
+
if (locale && isValidLocale(locale)) {
|
|
64
|
+
var approvedLocale = determineLocale(locale, approvedLocales);
|
|
65
|
+
if (approvedLocale) {
|
|
66
|
+
userLocale = standardizeLocale(approvedLocale);
|
|
67
|
+
res.headers.set(localeHeaderName, userLocale);
|
|
68
|
+
res.cookies.set(localeCookieName, userLocale);
|
|
69
|
+
return res;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// If there's no locale, try to get one from the referer
|
|
73
|
+
var referer = headerList.get('referer');
|
|
74
|
+
if (referer && typeof referer === 'string') {
|
|
75
|
+
var refererLocale = extractLocale((_a = (new URL(referer))) === null || _a === void 0 ? void 0 : _a.pathname);
|
|
76
|
+
if (refererLocale) {
|
|
77
|
+
var approvedLocale = determineLocale(refererLocale, approvedLocales);
|
|
78
|
+
if (approvedLocale) {
|
|
79
|
+
userLocale = standardizeLocale(approvedLocale);
|
|
80
|
+
req.nextUrl.pathname = "/".concat(userLocale, "/").concat(pathname);
|
|
81
|
+
return NextResponse.redirect(req.nextUrl);
|
|
82
|
+
}
|
|
83
|
+
;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
userLocale = (function () {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
/* Removed until preloading can be accurately detected
|
|
90
|
+
const cookieLocale = req.cookies.get(localeCookieName);
|
|
91
|
+
if (cookieLocale?.value) {
|
|
92
|
+
if (isValidLocale(cookieLocale.value))
|
|
93
|
+
return standardizeLocale(cookieLocale.value)
|
|
94
|
+
}*/
|
|
95
|
+
var acceptedLocales = (_b = (_a = headerList.get('accept-language')) === null || _a === void 0 ? void 0 : _a.split(',').map(function (item) { var _a; return (_a = item.split(';')) === null || _a === void 0 ? void 0 : _a[0].trim(); })) === null || _b === void 0 ? void 0 : _b.filter(function (code) { return isValidLocale(code); });
|
|
96
|
+
if (acceptedLocales && acceptedLocales.length > 0) {
|
|
97
|
+
var approvedLocale = determineLocale(acceptedLocales, approvedLocales);
|
|
98
|
+
if (approvedLocale) {
|
|
99
|
+
userLocale = standardizeLocale(approvedLocale);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return userLocale;
|
|
103
|
+
})();
|
|
104
|
+
res.cookies.set(localeCookieName, userLocale);
|
|
105
|
+
res.headers.set(localeHeaderName, userLocale);
|
|
106
|
+
if (localeRouting) {
|
|
107
|
+
var pathname = req.nextUrl.pathname;
|
|
108
|
+
var originalUrl = req.nextUrl;
|
|
109
|
+
// Construct new URL with original search parameters
|
|
110
|
+
var newUrl = new URL("/".concat(userLocale).concat(pathname), originalUrl);
|
|
111
|
+
newUrl.search = originalUrl.search; // keep the query parameters
|
|
112
|
+
if (!prefixDefaultLocale && isSameDialect(userLocale, defaultLocale)) {
|
|
113
|
+
var rewrittenRes = NextResponse.rewrite(newUrl, req.nextUrl);
|
|
114
|
+
rewrittenRes.cookies.set(localeCookieName, userLocale);
|
|
115
|
+
rewrittenRes.headers.set(localeHeaderName, userLocale);
|
|
116
|
+
return rewrittenRes;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
req.nextUrl.pathname = "/".concat(userLocale).concat(pathname);
|
|
120
|
+
return NextResponse.redirect(newUrl);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return res;
|
|
124
|
+
}
|
|
125
|
+
return nextMiddleware;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=createNextMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createNextMiddleware.js","sourceRoot":"","sources":["../../../src/middleware/createNextMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACtG,8FAA8F;AAC9F,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACtG,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;GAKG;AACH,SAAS,aAAa,CAAC,QAAgB;IACnC,IAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACtD,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,EAS5C;QAT4C,qBAO3C;QACE,aAAa,EAAE,oBAAoB,EAAE,aAAa,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK;KACvF,KAAA,EARG,qBAAoC,EAApC,aAAa,mBAAG,oBAAoB,KAAA,EACpC,eAAgC,EAAhC,OAAO,mBAAG,oBAAoB,EAAE,KAAA,EAChC,qBAAoB,EAApB,aAAa,mBAAG,IAAI,KAAA,EAAE,2BAA2B,EAA3B,mBAAmB,mBAAG,KAAK,KAAA;IAOjD,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,8CAAsC,aAAa,8BAA0B,CAAC,CAAA;IAEjI,IAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAA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gBAAgB,EAAE,UAAU,CAAC,CAAC;QAE9C,IAAI,aAAa,EAAE,CAAC;YACR,IAAA,QAAQ,GAAK,GAAG,CAAC,OAAO,SAAhB,CAAiB;YACjC,IAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC;YAChC,oDAAoD;YACpD,IAAM,MAAM,GAAG,IAAI,GAAG,CAAC,WAAI,UAAU,SAAG,QAAQ,CAAE,EAAE,WAAW,CAAC,CAAC;YACjE,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,4BAA4B;YAChE,IAAI,CAAC,mBAAmB,IAAI,aAAa,CAAC,UAAU,EAAE,aAAa,CAAC,EAAE,CAAC;gBACnE,IAAM,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC/D,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;gBACvD,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;gBACvD,OAAO,YAAY,CAAC;YACxB,CAAC;iBAAM,CAAC;gBACJ,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,WAAI,UAAU,SAAG,QAAQ,CAAE,CAAA;gBAClD,OAAO,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACzC,CAAC;QACL,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAED,OAAO,cAAc,CAAC;AAE1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,EACH,oBAAoB,EACvB,CAAC"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
'use client';
|
|
3
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -36,45 +34,27 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
35
|
}
|
|
38
36
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
case 2:
|
|
62
|
-
error_1 = _a.sent();
|
|
63
|
-
console.error(createErrors_1.renderingError, error_1);
|
|
64
|
-
setHasError(true);
|
|
65
|
-
return [3 /*break*/, 3];
|
|
66
|
-
case 3: return [2 /*return*/];
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}); })();
|
|
70
|
-
}, [promise]);
|
|
71
|
-
if (hasError) {
|
|
72
|
-
return errorFallback;
|
|
73
|
-
}
|
|
74
|
-
if (typeof translationData !== 'undefined') {
|
|
75
|
-
return ((0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: errorFallback, children: renderTranslation(translationData) }));
|
|
76
|
-
}
|
|
77
|
-
// the <Suspense> here is to prevent hydration errors
|
|
78
|
-
return ((0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: loadingFallback, children: loadingFallback }));
|
|
37
|
+
import { headers } from "next/headers";
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the 'host' header from the headers list.
|
|
40
|
+
* If the 'next/headers' module is not available, it attempts to load it. If the
|
|
41
|
+
* headers function is available, it returns the value of the 'host' header.
|
|
42
|
+
* If the headers function or 'host' header is not available, returns null.
|
|
43
|
+
*
|
|
44
|
+
* @returns {string | null} A promise that resolves to the value of the 'host' header,
|
|
45
|
+
* or null if not available.
|
|
46
|
+
*/
|
|
47
|
+
export function getNextDomain() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
+
var headerList;
|
|
50
|
+
return __generator(this, function (_a) {
|
|
51
|
+
switch (_a.label) {
|
|
52
|
+
case 0: return [4 /*yield*/, headers()];
|
|
53
|
+
case 1:
|
|
54
|
+
headerList = _a.sent();
|
|
55
|
+
return [2 /*return*/, headerList.get('host') || null];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
79
59
|
}
|
|
80
|
-
//# sourceMappingURL=
|
|
60
|
+
//# sourceMappingURL=getNextDomain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getNextDomain.js","sourceRoot":"","sources":["../../../src/next/getNextDomain.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;;;;;GAQG;AACH,MAAM,UAAgB,aAAa;;;;;wBACZ,qBAAM,OAAO,EAAE,EAAA;;oBAA5B,UAAU,GAAG,SAAe;oBAClC,sBAAO,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,EAAC;;;;CACzC"}
|