gt-react 2.0.120
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/README.md +7 -0
- package/dist/client/ClientProvider.d.ts +11 -0
- package/dist/client/ClientProvider.d.ts.map +1 -0
- package/dist/client/ClientProvider.js +17 -0
- package/dist/client/ClientProvider.js.map +1 -0
- package/dist/client/GTProvider.d.ts +12 -0
- package/dist/client/GTProvider.d.ts.map +1 -0
- package/dist/client/GTProvider.js +56 -0
- package/dist/client/GTProvider.js.map +1 -0
- package/dist/client/t.d.ts +2 -0
- package/dist/client/t.d.ts.map +1 -0
- package/dist/client/t.js +14 -0
- package/dist/client/t.js.map +1 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +17 -0
- package/dist/client.js.map +1 -0
- package/dist/config/I18NConfig.d.ts +90 -0
- package/dist/config/I18NConfig.d.ts.map +1 -0
- package/dist/config/I18NConfig.js +219 -0
- package/dist/config/I18NConfig.js.map +1 -0
- package/dist/config/PageManager.d.ts +16 -0
- package/dist/config/PageManager.d.ts.map +1 -0
- package/dist/config/PageManager.js +66 -0
- package/dist/config/PageManager.js.map +1 -0
- package/dist/config/local/getConfigData.d.ts +8 -0
- package/dist/config/local/getConfigData.d.ts.map +1 -0
- package/dist/config/local/getConfigData.js +29 -0
- package/dist/config/local/getConfigData.js.map +1 -0
- package/dist/config/local/getDefaultFromEnv.d.ts +12 -0
- package/dist/config/local/getDefaultFromEnv.d.ts.map +1 -0
- package/dist/config/local/getDefaultFromEnv.js +21 -0
- package/dist/config/local/getDefaultFromEnv.js.map +1 -0
- package/dist/config/local/getI18NPage.d.ts +10 -0
- package/dist/config/local/getI18NPage.d.ts.map +1 -0
- package/dist/config/local/getI18NPage.js +34 -0
- package/dist/config/local/getI18NPage.js.map +1 -0
- package/dist/config/placeholderCache.d.ts +8 -0
- package/dist/config/placeholderCache.d.ts.map +1 -0
- package/dist/config/placeholderCache.js +71 -0
- package/dist/config/placeholderCache.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/intl/intl.d.ts +14 -0
- package/dist/intl/intl.d.ts.map +1 -0
- package/dist/intl/intl.js +38 -0
- package/dist/intl/intl.js.map +1 -0
- package/dist/next/NextGTProvider.d.ts +15 -0
- package/dist/next/NextGTProvider.d.ts.map +1 -0
- package/dist/next/NextGTProvider.js +48 -0
- package/dist/next/NextGTProvider.js.map +1 -0
- package/dist/next/NextI18N.d.ts +15 -0
- package/dist/next/NextI18N.d.ts.map +1 -0
- package/dist/next/NextI18N.js +48 -0
- package/dist/next/NextI18N.js.map +1 -0
- package/dist/next/headerFunctions.d.ts +21 -0
- package/dist/next/headerFunctions.d.ts.map +1 -0
- package/dist/next/headerFunctions.js +77 -0
- package/dist/next/headerFunctions.js.map +1 -0
- package/dist/next/intl.d.ts +8 -0
- package/dist/next/intl.d.ts.map +1 -0
- package/dist/next/intl.js +47 -0
- package/dist/next/intl.js.map +1 -0
- package/dist/next.d.ts +9 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +21 -0
- package/dist/next.js.map +1 -0
- package/dist/primitives/numeric/Numeric.d.ts +23 -0
- package/dist/primitives/numeric/Numeric.d.ts.map +1 -0
- package/dist/primitives/numeric/Numeric.js +42 -0
- package/dist/primitives/numeric/Numeric.js.map +1 -0
- package/dist/primitives/numeric/client/ClientNumeric.d.ts +23 -0
- package/dist/primitives/numeric/client/ClientNumeric.d.ts.map +1 -0
- package/dist/primitives/numeric/client/ClientNumeric.js +43 -0
- package/dist/primitives/numeric/client/ClientNumeric.js.map +1 -0
- package/dist/primitives/numeric/getNumericBranch.d.ts +14 -0
- package/dist/primitives/numeric/getNumericBranch.d.ts.map +1 -0
- package/dist/primitives/numeric/getNumericBranch.js +84 -0
- package/dist/primitives/numeric/getNumericBranch.js.map +1 -0
- package/dist/primitives/private/Private.d.ts +19 -0
- package/dist/primitives/private/Private.d.ts.map +1 -0
- package/dist/primitives/private/Private.js +29 -0
- package/dist/primitives/private/Private.js.map +1 -0
- package/dist/primitives/value/Value.d.ts +21 -0
- package/dist/primitives/value/Value.d.ts.map +1 -0
- package/dist/primitives/value/Value.js +42 -0
- package/dist/primitives/value/Value.js.map +1 -0
- package/dist/primitives/value/client/ClientValue.d.ts +21 -0
- package/dist/primitives/value/client/ClientValue.d.ts.map +1 -0
- package/dist/primitives/value/client/ClientValue.js +43 -0
- package/dist/primitives/value/client/ClientValue.js.map +1 -0
- package/dist/primitives/value/client/renderClientVariable.d.ts +9 -0
- package/dist/primitives/value/client/renderClientVariable.d.ts.map +1 -0
- package/dist/primitives/value/client/renderClientVariable.js +60 -0
- package/dist/primitives/value/client/renderClientVariable.js.map +1 -0
- package/dist/primitives/value/getValueBranch.d.ts +9 -0
- package/dist/primitives/value/getValueBranch.d.ts.map +1 -0
- package/dist/primitives/value/getValueBranch.js +64 -0
- package/dist/primitives/value/getValueBranch.js.map +1 -0
- package/dist/primitives/value/isValidReactNode.d.ts +15 -0
- package/dist/primitives/value/isValidReactNode.d.ts.map +1 -0
- package/dist/primitives/value/isValidReactNode.js +27 -0
- package/dist/primitives/value/isValidReactNode.js.map +1 -0
- package/dist/primitives/value/processBranches.d.ts +9 -0
- package/dist/primitives/value/processBranches.d.ts.map +1 -0
- package/dist/primitives/value/processBranches.js +44 -0
- package/dist/primitives/value/processBranches.js.map +1 -0
- package/dist/primitives/value/renderVariable.d.ts +8 -0
- package/dist/primitives/value/renderVariable.d.ts.map +1 -0
- package/dist/primitives/value/renderVariable.js +57 -0
- package/dist/primitives/value/renderVariable.js.map +1 -0
- package/dist/primitives/variable/Variable.d.ts +13 -0
- package/dist/primitives/variable/Variable.d.ts.map +1 -0
- package/dist/primitives/variable/Variable.js +24 -0
- package/dist/primitives/variable/Variable.js.map +1 -0
- package/dist/server/ServerI18N.d.ts +18 -0
- package/dist/server/ServerI18N.d.ts.map +1 -0
- package/dist/server/ServerI18N.js +81 -0
- package/dist/server/ServerI18N.js.map +1 -0
- package/dist/server/helpers/addGTIdentifier.d.ts +11 -0
- package/dist/server/helpers/addGTIdentifier.d.ts.map +1 -0
- package/dist/server/helpers/addGTIdentifier.js +152 -0
- package/dist/server/helpers/addGTIdentifier.js.map +1 -0
- package/dist/server/helpers/generateHash.d.ts +12 -0
- package/dist/server/helpers/generateHash.d.ts.map +1 -0
- package/dist/server/helpers/generateHash.js +34 -0
- package/dist/server/helpers/generateHash.js.map +1 -0
- package/dist/server/helpers/writeChildrenAsObjects.d.ts +11 -0
- package/dist/server/helpers/writeChildrenAsObjects.d.ts.map +1 -0
- package/dist/server/helpers/writeChildrenAsObjects.js +129 -0
- package/dist/server/helpers/writeChildrenAsObjects.js.map +1 -0
- package/dist/server/renderChildren.d.ts +19 -0
- package/dist/server/renderChildren.d.ts.map +1 -0
- package/dist/server/renderChildren.js +153 -0
- package/dist/server/renderChildren.js.map +1 -0
- package/dist/server/resolvers/I18NResolver.d.ts +13 -0
- package/dist/server/resolvers/I18NResolver.d.ts.map +1 -0
- package/dist/server/resolvers/I18NResolver.js +41 -0
- package/dist/server/resolvers/I18NResolver.js.map +1 -0
- package/dist/server/resolvers/renderResolvedChildren.d.ts +19 -0
- package/dist/server/resolvers/renderResolvedChildren.d.ts.map +1 -0
- package/dist/server/resolvers/renderResolvedChildren.js +157 -0
- package/dist/server/resolvers/renderResolvedChildren.js.map +1 -0
- package/package.json +39 -0
- package/scratchpad.js +33 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = getConfigData;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const getDefaultFromEnv_1 = __importDefault(require("./getDefaultFromEnv"));
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the configuration data from a specified file.
|
|
12
|
+
* The file path is determined by an environment variable, defaulting to 'gt_config.json'.
|
|
13
|
+
*
|
|
14
|
+
* @returns {Record<string, any>} The configuration data as an object.
|
|
15
|
+
*/
|
|
16
|
+
function getConfigData() {
|
|
17
|
+
const filename = (0, getDefaultFromEnv_1.default)("GT_CONFIG_FILEPATH") || 'gt_config.json';
|
|
18
|
+
const filepath = path_1.default.resolve(process.cwd(), filename);
|
|
19
|
+
let data = {};
|
|
20
|
+
try {
|
|
21
|
+
const file = fs_1.default.readFileSync(filepath, 'utf-8');
|
|
22
|
+
data = JSON.parse(file);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.warn('@generaltranslation/react: No I18N config readable. Defaulting to standard settings.');
|
|
26
|
+
}
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=getConfigData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getConfigData.js","sourceRoot":"","sources":["../../../src/config/local/getConfigData.ts"],"names":[],"mappings":";;;;;AAUA,gCAWC;AArBD,4CAAoB;AACpB,gDAAwB;AACxB,4EAAoD;AAEpD;;;;;GAKG;AACH,SAAwB,aAAa;IACjC,MAAM,QAAQ,GAAW,IAAA,2BAAiB,EAAC,oBAAoB,CAAC,IAAI,gBAAgB,CAAC;IACrF,MAAM,QAAQ,GAAW,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC/D,IAAI,IAAI,GAAwB,EAAE,CAAC;IACnC,IAAI,CAAC;QACD,MAAM,IAAI,GAAW,YAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,sFAAsF,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
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: string): string;
|
|
12
|
+
//# sourceMappingURL=getDefaultFromEnv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDefaultFromEnv.d.ts","sourceRoot":"","sources":["../../../src/config/local/getDefaultFromEnv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKlE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = getDefaultFromEnv;
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves the value of an environment variable as a string.
|
|
6
|
+
*
|
|
7
|
+
* This function checks if the `process` object is defined and if the specified environment
|
|
8
|
+
* variable is set. If both conditions are met, it returns the value of the environment
|
|
9
|
+
* variable. If not, it returns an empty string.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} VARIABLE - The name of the environment variable to retrieve.
|
|
12
|
+
* @returns {string} The value of the environment variable, or an empty string if the variable is not set.
|
|
13
|
+
*/
|
|
14
|
+
function getDefaultFromEnv(VARIABLE) {
|
|
15
|
+
var _a;
|
|
16
|
+
if (typeof process !== 'undefined' && ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a[VARIABLE])) {
|
|
17
|
+
return process.env[VARIABLE];
|
|
18
|
+
}
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=getDefaultFromEnv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDefaultFromEnv.js","sourceRoot":"","sources":["../../../src/config/local/getDefaultFromEnv.ts"],"names":[],"mappings":";;AAUA,oCAKC;AAfD;;;;;;;;;GASG;AACH,SAAwB,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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads and parses a JSON file located at the specified filepath.
|
|
3
|
+
* If the file does not exist or an error occurs during reading/parsing,
|
|
4
|
+
* the function logs the error and returns null.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} filepath - The path to the JSON file.
|
|
7
|
+
* @returns {Promise<object>} - The parsed JSON object or null if an error occurs.
|
|
8
|
+
*/
|
|
9
|
+
export default function getI18NPage(filepath: string): Promise<any>;
|
|
10
|
+
//# sourceMappingURL=getI18NPage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getI18NPage.d.ts","sourceRoot":"","sources":["../../../src/config/local/getI18NPage.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAA8B,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAQxE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.default = getI18NPage;
|
|
13
|
+
const fs_1 = require("fs");
|
|
14
|
+
/**
|
|
15
|
+
* Reads and parses a JSON file located at the specified filepath.
|
|
16
|
+
* If the file does not exist or an error occurs during reading/parsing,
|
|
17
|
+
* the function logs the error and returns null.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} filepath - The path to the JSON file.
|
|
20
|
+
* @returns {Promise<object>} - The parsed JSON object or null if an error occurs.
|
|
21
|
+
*/
|
|
22
|
+
function getI18NPage(filepath) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
try {
|
|
25
|
+
const file = yield fs_1.promises.readFile(filepath, 'utf-8');
|
|
26
|
+
return JSON.parse(file) || {};
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(error);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=getI18NPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getI18NPage.js","sourceRoot":"","sources":["../../../src/config/local/getI18NPage.ts"],"names":[],"mappings":";;;;;;;;;;;AAUA,8BAQC;AAlBD,2BAA8B;AAE9B;;;;;;;GAOG;AACH,SAA8B,WAAW,CAAC,QAAgB;;QACtD,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,aAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type CachedFunction<T extends (...args: any[]) => any> = {
|
|
2
|
+
(...args: Parameters<T>): Promise<ReturnType<T>>;
|
|
3
|
+
clear: (...args: Parameters<T>) => void;
|
|
4
|
+
clearAll: () => void;
|
|
5
|
+
};
|
|
6
|
+
export default function cache<T extends (...args: any[]) => any>(f: T): CachedFunction<T>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=placeholderCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholderCache.d.ts","sourceRoot":"","sources":["../../src/config/placeholderCache.ts"],"names":[],"mappings":"AAwCA,KAAK,cAAc,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI;IACrD,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACjD,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACxC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CA2BxF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This is intended as a placeholder until React's native cache is out of experimental phase
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.default = cache;
|
|
14
|
+
class PlaceholderCache {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.cache = new Map();
|
|
17
|
+
}
|
|
18
|
+
set(functionKey, argsKey, value) {
|
|
19
|
+
if (!this.cache.has(functionKey)) {
|
|
20
|
+
this.cache.set(functionKey, new Map());
|
|
21
|
+
}
|
|
22
|
+
this.cache.get(functionKey).set(argsKey, value);
|
|
23
|
+
}
|
|
24
|
+
get(functionKey, argsKey) {
|
|
25
|
+
var _a;
|
|
26
|
+
return (_a = this.cache.get(functionKey)) === null || _a === void 0 ? void 0 : _a.get(argsKey);
|
|
27
|
+
}
|
|
28
|
+
has(functionKey, argsKey) {
|
|
29
|
+
return this.cache.has(functionKey) && this.cache.get(functionKey).has(argsKey);
|
|
30
|
+
}
|
|
31
|
+
clear(functionKey, argsKey) {
|
|
32
|
+
if (this.cache.has(functionKey)) {
|
|
33
|
+
this.cache.get(functionKey).delete(argsKey);
|
|
34
|
+
if (this.cache.get(functionKey).size === 0) {
|
|
35
|
+
this.cache.delete(functionKey);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
clearAll() {
|
|
40
|
+
this.cache.clear();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const placeholderCache = new PlaceholderCache();
|
|
44
|
+
function cache(f) {
|
|
45
|
+
const functionKey = f.toString();
|
|
46
|
+
const cachedFunction = function (...args) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const argsKey = JSON.stringify(args);
|
|
49
|
+
if (!placeholderCache.has(functionKey, argsKey) || placeholderCache.get(functionKey, argsKey) === null) {
|
|
50
|
+
try {
|
|
51
|
+
const result = yield f(...args);
|
|
52
|
+
placeholderCache.set(functionKey, argsKey, result);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw new Error(`Error executing function: ${error}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return placeholderCache.get(functionKey, argsKey);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
cachedFunction.clear = function (...args) {
|
|
63
|
+
const argsKey = JSON.stringify(args);
|
|
64
|
+
placeholderCache.clear(functionKey, argsKey);
|
|
65
|
+
};
|
|
66
|
+
cachedFunction.clearAll = function () {
|
|
67
|
+
placeholderCache.clearAll();
|
|
68
|
+
};
|
|
69
|
+
return cachedFunction;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=placeholderCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholderCache.js","sourceRoot":"","sources":["../../src/config/placeholderCache.ts"],"names":[],"mappings":"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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ServerI18N from "./server/ServerI18N";
|
|
2
|
+
import Private from "./primitives/private/Private";
|
|
3
|
+
import Numeric from "./primitives/numeric/Numeric";
|
|
4
|
+
import Value from "./primitives/value/Value";
|
|
5
|
+
import Variable from "./primitives/variable/Variable";
|
|
6
|
+
import intl from "./intl/intl";
|
|
7
|
+
import GTProvider from "./client/GTProvider";
|
|
8
|
+
export { ServerI18N as I18N, intl, Private, Numeric, Value, Variable, GTProvider };
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,OAAO,MAAM,8BAA8B,CAAC;AACnD,OAAO,OAAO,MAAM,8BAA8B,CAAC;AACnD,OAAO,KAAK,MAAM,0BAA0B,CAAC;AAC7C,OAAO,QAAQ,MAAM,gCAAgC,CAAA;AACrD,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACH,UAAU,IAAI,IAAI,EAClB,IAAI,EACJ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EACjC,UAAU,EACb,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GTProvider = exports.Variable = exports.Value = exports.Numeric = exports.Private = exports.intl = exports.I18N = void 0;
|
|
7
|
+
const ServerI18N_1 = __importDefault(require("./server/ServerI18N"));
|
|
8
|
+
exports.I18N = ServerI18N_1.default;
|
|
9
|
+
const Private_1 = __importDefault(require("./primitives/private/Private"));
|
|
10
|
+
exports.Private = Private_1.default;
|
|
11
|
+
const Numeric_1 = __importDefault(require("./primitives/numeric/Numeric"));
|
|
12
|
+
exports.Numeric = Numeric_1.default;
|
|
13
|
+
const Value_1 = __importDefault(require("./primitives/value/Value"));
|
|
14
|
+
exports.Value = Value_1.default;
|
|
15
|
+
const Variable_1 = __importDefault(require("./primitives/variable/Variable"));
|
|
16
|
+
exports.Variable = Variable_1.default;
|
|
17
|
+
const intl_1 = __importDefault(require("./intl/intl"));
|
|
18
|
+
exports.intl = intl_1.default;
|
|
19
|
+
const GTProvider_1 = __importDefault(require("./client/GTProvider"));
|
|
20
|
+
exports.GTProvider = GTProvider_1.default;
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,qEAA6C;AAQ3B,eARX,oBAAU,CAQK;AAPtB,2EAAmD;AAS/C,kBATG,iBAAO,CASH;AARX,2EAAmD;AAQtC,kBARN,iBAAO,CAQM;AAPpB,qEAA6C;AAOvB,gBAPf,eAAK,CAOe;AAN3B,8EAAqD;AAMxB,mBANtB,kBAAQ,CAMsB;AALrC,uDAA+B;AAI3B,eAJG,cAAI,CAIH;AAHR,qEAA6C;AAKzC,qBALG,oBAAU,CAKH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches the translation of given content, or sends it to be translated if it doesn't exist already.
|
|
3
|
+
* @param {Content} content - The content to be translated.
|
|
4
|
+
* @param {string} targetLanguage - The target language for translation.
|
|
5
|
+
* @param {Record<string, any>} [metadata] - Optional metadata for translation.
|
|
6
|
+
* @returns {Promise<string>} The translated content.
|
|
7
|
+
*/
|
|
8
|
+
export default function intl(content: string, targetLanguage: string, metadata?: {
|
|
9
|
+
id?: string;
|
|
10
|
+
page?: string;
|
|
11
|
+
notes?: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}): Promise<string>;
|
|
14
|
+
//# sourceMappingURL=intl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl.d.ts","sourceRoot":"","sources":["../../src/intl/intl.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAA8B,IAAI,CAC9B,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,QAAQ,GAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAO,GAClF,OAAO,CAAC,MAAM,CAAC,CASjB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.default = intl;
|
|
16
|
+
const I18NConfig_1 = __importDefault(require("../config/I18NConfig"));
|
|
17
|
+
/**
|
|
18
|
+
* Fetches the translation of given content, or sends it to be translated if it doesn't exist already.
|
|
19
|
+
* @param {Content} content - The content to be translated.
|
|
20
|
+
* @param {string} targetLanguage - The target language for translation.
|
|
21
|
+
* @param {Record<string, any>} [metadata] - Optional metadata for translation.
|
|
22
|
+
* @returns {Promise<string>} The translated content.
|
|
23
|
+
*/
|
|
24
|
+
function intl(content_1, targetLanguage_1) {
|
|
25
|
+
return __awaiter(this, arguments, void 0, function* (content, targetLanguage, metadata = {}) {
|
|
26
|
+
if (!content || typeof content !== 'string' || !I18NConfig_1.default.translationRequired(targetLanguage))
|
|
27
|
+
return content;
|
|
28
|
+
const key = content;
|
|
29
|
+
const translation = yield I18NConfig_1.default.getI18NEntry(targetLanguage, key, metadata.id, metadata.page);
|
|
30
|
+
if (translation)
|
|
31
|
+
return translation;
|
|
32
|
+
if (I18NConfig_1.default.hasRemoteSource()) {
|
|
33
|
+
I18NConfig_1.default.intl({ content, targetLanguage, metadata });
|
|
34
|
+
}
|
|
35
|
+
return content;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=intl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl.js","sourceRoot":"","sources":["../../src/intl/intl.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AASA,uBAaC;AAtBD,sEAA8C;AAE9C;;;;;;GAMG;AACH,SAA8B,IAAI;yDAC9B,OAAe,EACf,cAAsB,EACtB,WAA+E,EAAE;QAEjF,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,oBAAU,CAAC,mBAAmB,CAAC,cAAc,CAAC;YAAE,OAAO,OAAO,CAAC;QAC/G,MAAM,GAAG,GAAG,OAAO,CAAC;QACpB,MAAM,WAAW,GAAG,MAAM,oBAAU,CAAC,YAAY,CAAC,cAAc,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QACnG,IAAI,WAAW;YAAE,OAAO,WAAW,CAAC;QACpC,IAAI,oBAAU,CAAC,eAAe,EAAE,EAAE,CAAC;YAC/B,oBAAU,CAAC,IAAI,CAAC,EAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAC,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
type NextI18NProps = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* NextI18N is an asynchronous server component that provides internationalization (i18n) support
|
|
8
|
+
* for Next.js applications. It retrieves the user's language with the built-in Next.js header functions.
|
|
9
|
+
*
|
|
10
|
+
* @param {NextI18NProps} props - The properties passed to the component, including children nodes and any additional metadata.
|
|
11
|
+
* @returns {Promise<any>} The JSX element wrapped with the ServerI18N component for i18n configuration.
|
|
12
|
+
*/
|
|
13
|
+
export default function NextGTProvider({ children, ...metadata }: NextI18NProps): Promise<any>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=NextGTProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextGTProvider.d.ts","sourceRoot":"","sources":["../../src/next/NextGTProvider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMzC,KAAK,aAAa,GAAG;IACjB,QAAQ,EAAE,SAAS,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAA;AAED;;;;;;GAMG;AACH,wBAA8B,cAAc,CAAC,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAanG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.default = NextGTProvider;
|
|
27
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
|
+
const headerFunctions_1 = require("./headerFunctions");
|
|
29
|
+
const I18NConfig_1 = __importDefault(require("../config/I18NConfig"));
|
|
30
|
+
const GTProvider_1 = __importDefault(require("../client/GTProvider"));
|
|
31
|
+
/**
|
|
32
|
+
* NextI18N is an asynchronous server component that provides internationalization (i18n) support
|
|
33
|
+
* for Next.js applications. It retrieves the user's language with the built-in Next.js header functions.
|
|
34
|
+
*
|
|
35
|
+
* @param {NextI18NProps} props - The properties passed to the component, including children nodes and any additional metadata.
|
|
36
|
+
* @returns {Promise<any>} The JSX element wrapped with the ServerI18N component for i18n configuration.
|
|
37
|
+
*/
|
|
38
|
+
function NextGTProvider(_a) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var { children } = _a, metadata = __rest(_a, ["children"]);
|
|
41
|
+
// Retrieve the user's language or use the default language from the configuration if not available
|
|
42
|
+
const userLanguage = (yield (0, headerFunctions_1.getUserLanguageNext)()) || I18NConfig_1.default.getDefaultLanguage();
|
|
43
|
+
// Retrieve the domain or use an empty string if not available
|
|
44
|
+
const domain = (yield (0, headerFunctions_1.getDomainNext)()) || "";
|
|
45
|
+
return ( /* @ts-expect-error Server Component */(0, jsx_runtime_1.jsx)(GTProvider_1.default, Object.assign({ userLanguage: userLanguage, domain: domain }, metadata, { children: children })));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=NextGTProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextGTProvider.js","sourceRoot":"","sources":["../../src/next/NextGTProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,iCAaC;;AA7BD,uDAAuE;AACvE,sEAA8C;AAC9C,sEAA8C;AAO9C;;;;;;GAMG;AACH,SAA8B,cAAc,CAAC,EAAwC;;YAAxC,EAAE,QAAQ,OAA8B,EAAzB,QAAQ,cAAvB,YAAyB,CAAF;QAEhE,mGAAmG;QACnG,MAAM,YAAY,GAAW,CAAC,MAAM,IAAA,qCAAmB,GAAE,CAAC,IAAI,oBAAU,CAAC,kBAAkB,EAAE,CAAC;QAE9F,8DAA8D;QAC9D,MAAM,MAAM,GAAW,CAAC,MAAM,IAAA,+BAAa,GAAE,CAAC,IAAI,EAAE,CAAC;QAErD,OAAO,EAAE,uCACL,uBAAC,oBAAU,kBAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,IAAM,QAAQ,cAC/D,QAAQ,IACA,CAChB,CAAC;IACN,CAAC;CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
type NextI18NProps = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* NextI18N is an asynchronous server component that provides internationalization (i18n) support
|
|
8
|
+
* for Next.js applications. It retrieves the user's language with the built-in Next.js header functions.
|
|
9
|
+
*
|
|
10
|
+
* @param {NextI18NProps} props - The properties passed to the component, including children nodes and any additional metadata.
|
|
11
|
+
* @returns {Promise<any>} The JSX element wrapped with the ServerI18N component for i18n configuration.
|
|
12
|
+
*/
|
|
13
|
+
export default function NextI18N({ children, ...metadata }: NextI18NProps): Promise<any>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=NextI18N.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextI18N.d.ts","sourceRoot":"","sources":["../../src/next/NextI18N.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMzC,KAAK,aAAa,GAAG;IACjB,QAAQ,EAAE,SAAS,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAA;AAED;;;;;;GAMG;AACH,wBAA8B,QAAQ,CAAC,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAa7F"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.default = NextI18N;
|
|
27
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
|
+
const headerFunctions_1 = require("./headerFunctions");
|
|
29
|
+
const ServerI18N_1 = __importDefault(require("../server/ServerI18N"));
|
|
30
|
+
const I18NConfig_1 = __importDefault(require("../config/I18NConfig"));
|
|
31
|
+
/**
|
|
32
|
+
* NextI18N is an asynchronous server component that provides internationalization (i18n) support
|
|
33
|
+
* for Next.js applications. It retrieves the user's language with the built-in Next.js header functions.
|
|
34
|
+
*
|
|
35
|
+
* @param {NextI18NProps} props - The properties passed to the component, including children nodes and any additional metadata.
|
|
36
|
+
* @returns {Promise<any>} The JSX element wrapped with the ServerI18N component for i18n configuration.
|
|
37
|
+
*/
|
|
38
|
+
function NextI18N(_a) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var { children } = _a, metadata = __rest(_a, ["children"]);
|
|
41
|
+
// Retrieve the user's language or use the default language from the configuration if not available
|
|
42
|
+
const userLanguage = (yield (0, headerFunctions_1.getUserLanguageNext)()) || I18NConfig_1.default.getDefaultLanguage();
|
|
43
|
+
// Retrieve the domain or use an empty string if not available
|
|
44
|
+
const domain = (yield (0, headerFunctions_1.getDomainNext)()) || "";
|
|
45
|
+
return ( /* @ts-expect-error Server Component */(0, jsx_runtime_1.jsx)(ServerI18N_1.default, Object.assign({ userLanguage: userLanguage, domain: domain }, metadata, { children: children })));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=NextI18N.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextI18N.js","sourceRoot":"","sources":["../../src/next/NextI18N.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,2BAaC;;AA7BD,uDAAuE;AACvE,sEAA8C;AAC9C,sEAA8C;AAO9C;;;;;;GAMG;AACH,SAA8B,QAAQ,CAAC,EAAwC;;YAAxC,EAAE,QAAQ,OAA8B,EAAzB,QAAQ,cAAvB,YAAyB,CAAF;QAE1D,mGAAmG;QACnG,MAAM,YAAY,GAAW,CAAC,MAAM,IAAA,qCAAmB,GAAE,CAAC,IAAI,oBAAU,CAAC,kBAAkB,EAAE,CAAC;QAE9F,8DAA8D;QAC9D,MAAM,MAAM,GAAW,CAAC,MAAM,IAAA,+BAAa,GAAE,CAAC,IAAI,EAAE,CAAC;QAErD,OAAO,EAAE,uCACL,uBAAC,oBAAU,kBAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,IAAM,QAAQ,cAC/D,QAAQ,IACA,CAChB,CAAC;IACN,CAAC;CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronously retrieves the 'accept-language' header from the headers list.
|
|
3
|
+
* If the 'next/headers' module is not available, it attempts to load it. If the
|
|
4
|
+
* headers function is available, it returns the primary language from the 'accept-language'
|
|
5
|
+
* header. If the headers function or 'accept-language' header is not available, returns null.
|
|
6
|
+
*
|
|
7
|
+
* @returns {Promise<string | null>} A promise that resolves to the primary language from the
|
|
8
|
+
* 'accept-language' header, or null if not available.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getUserLanguageNext(): Promise<string | null>;
|
|
11
|
+
/**
|
|
12
|
+
* Asynchronously retrieves the 'host' header from the headers list.
|
|
13
|
+
* If the 'next/headers' module is not available, it attempts to load it. If the
|
|
14
|
+
* headers function is available, it returns the value of the 'host' header.
|
|
15
|
+
* If the headers function or 'host' header is not available, returns null.
|
|
16
|
+
*
|
|
17
|
+
* @returns {Promise<string | null>} A promise that resolves to the value of the 'host' header,
|
|
18
|
+
* or null if not available.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getDomainNext(): Promise<string | null>;
|
|
21
|
+
//# sourceMappingURL=headerFunctions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headerFunctions.d.ts","sourceRoot":"","sources":["../../src/next/headerFunctions.ts"],"names":[],"mappings":"AAiBA;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASlE;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQ5D"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getUserLanguageNext = getUserLanguageNext;
|
|
13
|
+
exports.getDomainNext = getDomainNext;
|
|
14
|
+
let headers = null;
|
|
15
|
+
/**
|
|
16
|
+
* Asynchronously loads the 'next/headers' module and sets the 'headers' variable
|
|
17
|
+
* to a function that returns the headers if the module is available. If the module
|
|
18
|
+
* is not available, logs a warning message and sets 'headers' to null.
|
|
19
|
+
*/
|
|
20
|
+
function loadNextHeaders() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
try {
|
|
23
|
+
const nextHeaders = require('next/headers');
|
|
24
|
+
headers = nextHeaders.headers;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.warn('next/headers is not available. Running in non-Next.js environment.');
|
|
28
|
+
headers = null;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Asynchronously retrieves the 'accept-language' header from the headers list.
|
|
34
|
+
* If the 'next/headers' module is not available, it attempts to load it. If the
|
|
35
|
+
* headers function is available, it returns the primary language from the 'accept-language'
|
|
36
|
+
* header. If the headers function or 'accept-language' header is not available, returns null.
|
|
37
|
+
*
|
|
38
|
+
* @returns {Promise<string | null>} A promise that resolves to the primary language from the
|
|
39
|
+
* 'accept-language' header, or null if not available.
|
|
40
|
+
*/
|
|
41
|
+
function getUserLanguageNext() {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
if (!headers)
|
|
44
|
+
yield loadNextHeaders();
|
|
45
|
+
if (headers) {
|
|
46
|
+
const headerList = headers();
|
|
47
|
+
const acceptLanguage = headerList.get('accept-language');
|
|
48
|
+
return (acceptLanguage === null || acceptLanguage === void 0 ? void 0 : acceptLanguage.split('/')[0].split(',')[0]) || null;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Asynchronously retrieves the 'host' header from the headers list.
|
|
57
|
+
* If the 'next/headers' module is not available, it attempts to load it. If the
|
|
58
|
+
* headers function is available, it returns the value of the 'host' header.
|
|
59
|
+
* If the headers function or 'host' header is not available, returns null.
|
|
60
|
+
*
|
|
61
|
+
* @returns {Promise<string | null>} A promise that resolves to the value of the 'host' header,
|
|
62
|
+
* or null if not available.
|
|
63
|
+
*/
|
|
64
|
+
function getDomainNext() {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
if (!headers)
|
|
67
|
+
yield loadNextHeaders();
|
|
68
|
+
if (headers) {
|
|
69
|
+
const headerList = headers();
|
|
70
|
+
return headerList.get('host') || null;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=headerFunctions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headerFunctions.js","sourceRoot":"","sources":["../../src/next/headerFunctions.ts"],"names":[],"mappings":";;;;;;;;;;;AA0BA,kDASC;AAWD,sCAQC;AAtDD,IAAI,OAAO,GAA2B,IAAI,CAAC;AAE3C;;;;GAIG;AACH,SAAe,eAAe;;QAC1B,IAAI,CAAC;YACD,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;YAC5C,OAAO,GAAG,WAAW,CAAC,OAA0B,CAAC;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,oEAAoE,CAAC,CAAC;YACnF,OAAO,GAAG,IAAI,CAAC;QACnB,CAAC;IACL,CAAC;CAAA;AAED;;;;;;;;GAQG;AACH,SAAsB,mBAAmB;;QACrC,IAAI,CAAC,OAAO;YAAE,MAAM,eAAe,EAAE,CAAC;QACtC,IAAI,OAAO,EAAE,CAAC;YACV,MAAM,UAAU,GAAG,OAAO,EAAE,CAAC;YAC7B,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;YACzD,OAAO,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,KAAI,IAAI,CAAC;QAC/D,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;CAAA;AAED;;;;;;;;GAQG;AACH,SAAsB,aAAa;;QAC/B,IAAI,CAAC,OAAO;YAAE,MAAM,eAAe,EAAE,CAAC;QACtC,IAAI,OAAO,EAAE,CAAC;YACV,MAAM,UAAU,GAAG,OAAO,EAAE,CAAC;YAC7B,OAAO,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC;QAC1C,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl.d.ts","sourceRoot":"","sources":["../../src/next/intl.ts"],"names":[],"mappings":"AAIA,wBAA8B,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,mBAmBnJ"}
|