gt-next 2.0.7 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/I18NConfiguration.d.ts +3 -3
- package/dist/config/I18NConfiguration.js +9 -9
- package/dist/config/RemoteTranslationsManager.d.ts +1 -1
- package/dist/config/RemoteTranslationsManager.js +2 -2
- package/dist/config/getI18NConfig.js +4 -4
- package/dist/config/props/InitGTProps.d.ts +1 -1
- package/dist/config/props/defaultInitGTProps.d.ts +1 -1
- package/dist/config/props/defaultInitGTProps.js +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.js +7 -7
- package/dist/errors/createErrors.d.ts +1 -1
- package/dist/errors/createErrors.js +2 -2
- package/package.json +4 -4
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import GT from 'generaltranslation';
|
|
2
2
|
type I18NConfigurationParams = {
|
|
3
3
|
apiKey: string;
|
|
4
|
-
|
|
4
|
+
projectId: string;
|
|
5
5
|
cacheURL: string;
|
|
6
6
|
baseURL: string;
|
|
7
7
|
defaultLocale: string;
|
|
@@ -18,7 +18,7 @@ type I18NConfigurationParams = {
|
|
|
18
18
|
};
|
|
19
19
|
export default class I18NConfiguration {
|
|
20
20
|
baseURL: string;
|
|
21
|
-
|
|
21
|
+
projectId: string;
|
|
22
22
|
defaultLocale: string;
|
|
23
23
|
locales: string[] | undefined;
|
|
24
24
|
renderSettings: {
|
|
@@ -36,7 +36,7 @@ export default class I18NConfiguration {
|
|
|
36
36
|
private _translationCache;
|
|
37
37
|
private _taggedDictionary;
|
|
38
38
|
private _template;
|
|
39
|
-
constructor({ apiKey,
|
|
39
|
+
constructor({ apiKey, projectId, baseURL, cacheURL, defaultLocale, locales, renderSettings, dictionary, maxConcurrentRequests, batchInterval, env, ...metadata }: I18NConfigurationParams);
|
|
40
40
|
/**
|
|
41
41
|
* Gets the application's default locale
|
|
42
42
|
* @returns {string} A BCP-47 locale tag
|
|
@@ -92,7 +92,7 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
92
92
|
function I18NConfiguration(_a) {
|
|
93
93
|
var
|
|
94
94
|
// Cloud integration
|
|
95
|
-
apiKey = _a.apiKey,
|
|
95
|
+
apiKey = _a.apiKey, projectId = _a.projectId, baseURL = _a.baseURL, cacheURL = _a.cacheURL,
|
|
96
96
|
// Locale info
|
|
97
97
|
defaultLocale = _a.defaultLocale, locales = _a.locales,
|
|
98
98
|
// Render method
|
|
@@ -104,9 +104,9 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
104
104
|
// Environment
|
|
105
105
|
env = _a.env,
|
|
106
106
|
// Other metadata
|
|
107
|
-
metadata = __rest(_a, ["apiKey", "
|
|
107
|
+
metadata = __rest(_a, ["apiKey", "projectId", "baseURL", "cacheURL", "defaultLocale", "locales", "renderSettings", "dictionary", "maxConcurrentRequests", "batchInterval", "env"]);
|
|
108
108
|
// Cloud integration
|
|
109
|
-
this.
|
|
109
|
+
this.projectId = projectId;
|
|
110
110
|
this.baseURL = baseURL;
|
|
111
111
|
// Locales
|
|
112
112
|
this.defaultLocale = defaultLocale;
|
|
@@ -115,7 +115,7 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
115
115
|
this.renderSettings = renderSettings;
|
|
116
116
|
// GT
|
|
117
117
|
this.gt = new generaltranslation_1.default({
|
|
118
|
-
|
|
118
|
+
projectId: projectId,
|
|
119
119
|
apiKey: apiKey,
|
|
120
120
|
defaultLocale: defaultLocale,
|
|
121
121
|
baseURL: baseURL,
|
|
@@ -125,13 +125,13 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
125
125
|
// Other metadata
|
|
126
126
|
this.metadata = __assign(__assign(__assign({ env: this.env, defaultLocale: this.defaultLocale }, (this.renderSettings.timeout && {
|
|
127
127
|
timeout: this.renderSettings.timeout - batchInterval,
|
|
128
|
-
})), {
|
|
128
|
+
})), { projectId: this.projectId }), metadata);
|
|
129
129
|
// Dictionary managers
|
|
130
|
-
if (cacheURL &&
|
|
130
|
+
if (cacheURL && projectId) {
|
|
131
131
|
this._remoteTranslationsManager = RemoteTranslationsManager_1.default;
|
|
132
132
|
this._remoteTranslationsManager.setConfig({
|
|
133
133
|
cacheURL: cacheURL,
|
|
134
|
-
|
|
134
|
+
projectId: projectId,
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
// Cache of hashes to speed up <GTProvider>
|
|
@@ -164,7 +164,7 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
164
164
|
*/
|
|
165
165
|
I18NConfiguration.prototype.translationEnabled = function () {
|
|
166
166
|
return this.baseURL &&
|
|
167
|
-
this.
|
|
167
|
+
this.projectId &&
|
|
168
168
|
(this.baseURL === defaultInitGTProps_1.default.baseURL ? this.gt.apiKey : true)
|
|
169
169
|
? true
|
|
170
170
|
: false;
|
|
@@ -261,7 +261,7 @@ var I18NConfiguration = /** @class */ (function () {
|
|
|
261
261
|
data: {
|
|
262
262
|
content: content,
|
|
263
263
|
targetLocale: targetLocale,
|
|
264
|
-
metadata: __assign(__assign(__assign({}, _this.metadata), {
|
|
264
|
+
metadata: __assign(__assign(__assign({}, _this.metadata), { projectId: _this.projectId }), options),
|
|
265
265
|
},
|
|
266
266
|
revalidate: _this._remoteTranslationsManager
|
|
267
267
|
? _this._remoteTranslationsManager.getTranslationRequested(targetLocale)
|
|
@@ -60,7 +60,7 @@ var RemoteTranslationsManager = /** @class */ (function () {
|
|
|
60
60
|
function RemoteTranslationsManager() {
|
|
61
61
|
this.config = {
|
|
62
62
|
cacheURL: 'https://cache.gtx.dev',
|
|
63
|
-
|
|
63
|
+
projectId: '',
|
|
64
64
|
};
|
|
65
65
|
this.translationsMap = new Map();
|
|
66
66
|
this.fetchPromises = new Map();
|
|
@@ -85,7 +85,7 @@ var RemoteTranslationsManager = /** @class */ (function () {
|
|
|
85
85
|
switch (_a.label) {
|
|
86
86
|
case 0:
|
|
87
87
|
_a.trys.push([0, 3, , 4]);
|
|
88
|
-
return [4 /*yield*/, fetch("".concat(this.config.cacheURL, "/").concat(this.config.
|
|
88
|
+
return [4 /*yield*/, fetch("".concat(this.config.cacheURL, "/").concat(this.config.projectId, "/").concat(reference))];
|
|
89
89
|
case 1:
|
|
90
90
|
response = _a.sent();
|
|
91
91
|
return [4 /*yield*/, response.json()];
|
|
@@ -31,13 +31,13 @@ function getI18NConfig() {
|
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
console.warn(createErrors_1.usingDefaultsWarning);
|
|
34
|
-
var
|
|
35
|
-
if (!
|
|
36
|
-
console.error(createErrors_1.
|
|
34
|
+
var projectId = process.env.GT_PROJECT_ID || '';
|
|
35
|
+
if (!projectId)
|
|
36
|
+
console.error(createErrors_1.projectIdMissingError);
|
|
37
37
|
var apiKey = process.env.GT_API_KEY || '';
|
|
38
38
|
if (!apiKey)
|
|
39
39
|
console.error(createErrors_1.APIKeyMissingError);
|
|
40
|
-
globalObj._GENERALTRANSLATION_I18N_CONFIG_INSTANCE = new I18NConfiguration_1.default(__assign(__assign({}, defaultInitGTProps_1.default), { maxConcurrentRequests: defaultInitGTProps_1.default._maxConcurrectRequests, batchInterval: defaultInitGTProps_1.default._batchInterval, apiKey: apiKey,
|
|
40
|
+
globalObj._GENERALTRANSLATION_I18N_CONFIG_INSTANCE = new I18NConfiguration_1.default(__assign(__assign({}, defaultInitGTProps_1.default), { maxConcurrentRequests: defaultInitGTProps_1.default._maxConcurrectRequests, batchInterval: defaultInitGTProps_1.default._batchInterval, apiKey: apiKey, projectId: projectId, env: env }));
|
|
41
41
|
}
|
|
42
42
|
return globalObj._GENERALTRANSLATION_I18N_CONFIG_INSTANCE;
|
|
43
43
|
}
|
|
@@ -43,7 +43,7 @@ var internal_1 = require("generaltranslation/internal");
|
|
|
43
43
|
var getDefaultFromEnv_1 = __importDefault(require("../../utils/getDefaultFromEnv"));
|
|
44
44
|
exports.default = {
|
|
45
45
|
apiKey: (0, getDefaultFromEnv_1.default)('GT_API_KEY'),
|
|
46
|
-
|
|
46
|
+
projectId: (0, getDefaultFromEnv_1.default)('GT_PROJECT_ID'),
|
|
47
47
|
baseURL: 'https://prod.gtx.dev',
|
|
48
48
|
cacheURL: internal_1.defaultCacheURL,
|
|
49
49
|
defaultLocale: internal_1.libraryDefaultLocale,
|
package/dist/config.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import InitGTProps from './config/props/InitGTProps';
|
|
|
10
10
|
* import { initGT } from 'gt-next/config';
|
|
11
11
|
*
|
|
12
12
|
* const withGT = initGT({
|
|
13
|
-
*
|
|
13
|
+
* projectId: 'abc-123',
|
|
14
14
|
* locales: ['en', 'es', 'fr'],
|
|
15
15
|
* defaultLocale: 'en'
|
|
16
16
|
* });
|
|
@@ -20,7 +20,7 @@ import InitGTProps from './config/props/InitGTProps';
|
|
|
20
20
|
* @param {string|undefined} i18n - Optional i18n configuration file path. If a string is provided, it will be used as a path.
|
|
21
21
|
* @param {string|undefined} dictionary - Optional dictionary configuration file path. If a string is provided, it will be used as a path.
|
|
22
22
|
* @param {string} [apiKey=defaultInitGTProps.apiKey] - API key for the GeneralTranslation service. Required if using the default GT base URL.
|
|
23
|
-
* @param {string} [
|
|
23
|
+
* @param {string} [projectId=defaultInitGTProps.projectId] - Project ID for the GeneralTranslation service. Required for most functionality.
|
|
24
24
|
* @param {string} [baseURL=defaultInitGTProps.baseURL] - The base URL for the GT API. Set to an empty string to disable automatic translations.
|
|
25
25
|
* @param {string} [cacheURL=defaultInitGTProps.cacheURL] - The URL for cached translations.
|
|
26
26
|
* @param {string[]} [locales] - List of supported locales for the application. Defaults to the first locale or the default locale if not provided.
|
|
@@ -35,5 +35,5 @@ import InitGTProps from './config/props/InitGTProps';
|
|
|
35
35
|
* @throws {Error} If the project ID is missing and default URLs are used, or if the API key is required and missing.
|
|
36
36
|
*
|
|
37
37
|
*/
|
|
38
|
-
export declare function initGT({ i18n, dictionary, apiKey,
|
|
38
|
+
export declare function initGT({ i18n, dictionary, apiKey, projectId, baseURL, cacheURL, locales, defaultLocale, renderSettings, _maxConcurrentRequests, _batchInterval, ...metadata }?: InitGTProps): (config?: NextConfig) => NextConfig;
|
|
39
39
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.js
CHANGED
|
@@ -48,7 +48,7 @@ var createErrors_1 = require("./errors/createErrors");
|
|
|
48
48
|
* import { initGT } from 'gt-next/config';
|
|
49
49
|
*
|
|
50
50
|
* const withGT = initGT({
|
|
51
|
-
*
|
|
51
|
+
* projectId: 'abc-123',
|
|
52
52
|
* locales: ['en', 'es', 'fr'],
|
|
53
53
|
* defaultLocale: 'en'
|
|
54
54
|
* });
|
|
@@ -58,7 +58,7 @@ var createErrors_1 = require("./errors/createErrors");
|
|
|
58
58
|
* @param {string|undefined} i18n - Optional i18n configuration file path. If a string is provided, it will be used as a path.
|
|
59
59
|
* @param {string|undefined} dictionary - Optional dictionary configuration file path. If a string is provided, it will be used as a path.
|
|
60
60
|
* @param {string} [apiKey=defaultInitGTProps.apiKey] - API key for the GeneralTranslation service. Required if using the default GT base URL.
|
|
61
|
-
* @param {string} [
|
|
61
|
+
* @param {string} [projectId=defaultInitGTProps.projectId] - Project ID for the GeneralTranslation service. Required for most functionality.
|
|
62
62
|
* @param {string} [baseURL=defaultInitGTProps.baseURL] - The base URL for the GT API. Set to an empty string to disable automatic translations.
|
|
63
63
|
* @param {string} [cacheURL=defaultInitGTProps.cacheURL] - The URL for cached translations.
|
|
64
64
|
* @param {string[]} [locales] - List of supported locales for the application. Defaults to the first locale or the default locale if not provided.
|
|
@@ -75,17 +75,17 @@ var createErrors_1 = require("./errors/createErrors");
|
|
|
75
75
|
*/
|
|
76
76
|
function initGT(_a) {
|
|
77
77
|
if (_a === void 0) { _a = defaultInitGTProps_1.default; }
|
|
78
|
-
var i18n = _a.i18n, dictionary = _a.dictionary, _b = _a.apiKey, apiKey = _b === void 0 ? defaultInitGTProps_1.default.apiKey : _b, _c = _a.
|
|
78
|
+
var i18n = _a.i18n, dictionary = _a.dictionary, _b = _a.apiKey, apiKey = _b === void 0 ? defaultInitGTProps_1.default.apiKey : _b, _c = _a.projectId, projectId = _c === void 0 ? defaultInitGTProps_1.default.projectId : _c, _d = _a.baseURL, baseURL = _d === void 0 ? defaultInitGTProps_1.default.baseURL : _d, _e = _a.cacheURL, cacheURL = _e === void 0 ? defaultInitGTProps_1.default.cacheURL : _e, locales = _a.locales, _f = _a.defaultLocale, defaultLocale = _f === void 0 ? (locales === null || locales === void 0 ? void 0 : locales[0]) || defaultInitGTProps_1.default.defaultLocale : _f, _g = _a.renderSettings, renderSettings = _g === void 0 ? defaultInitGTProps_1.default.renderSettings : _g, _h = _a._maxConcurrentRequests, _maxConcurrentRequests = _h === void 0 ? defaultInitGTProps_1.default._maxConcurrectRequests : _h, _j = _a._batchInterval, _batchInterval = _j === void 0 ? defaultInitGTProps_1.default._batchInterval : _j, metadata = __rest(_a, ["i18n", "dictionary", "apiKey", "projectId", "baseURL", "cacheURL", "locales", "defaultLocale", "renderSettings", "_maxConcurrentRequests", "_batchInterval"]);
|
|
79
79
|
// Error checks
|
|
80
|
-
if (!
|
|
80
|
+
if (!projectId &&
|
|
81
81
|
(cacheURL === defaultInitGTProps_1.default.cacheURL ||
|
|
82
82
|
baseURL === defaultInitGTProps_1.default.baseURL))
|
|
83
|
-
console.error(createErrors_1.
|
|
84
|
-
if ((!apiKey || !
|
|
83
|
+
console.error(createErrors_1.projectIdMissingError);
|
|
84
|
+
if ((!apiKey || !projectId) && baseURL === defaultInitGTProps_1.default.baseURL) {
|
|
85
85
|
console.error(createErrors_1.APIKeyMissingError);
|
|
86
86
|
}
|
|
87
87
|
// Store config params in environment variable to allow for global access (in some cases)
|
|
88
|
-
var I18NConfigParams = JSON.stringify(__assign({ apiKey: apiKey,
|
|
88
|
+
var I18NConfigParams = JSON.stringify(__assign({ apiKey: apiKey, projectId: projectId, baseURL: baseURL, cacheURL: cacheURL, locales: locales, defaultLocale: defaultLocale, renderSettings: renderSettings, maxConcurrentRequests: _maxConcurrentRequests, batchInterval: _batchInterval }, metadata));
|
|
89
89
|
// Use i18n and dictionary values as file paths if they are provided as such
|
|
90
90
|
var resolvedI18NFilePath = typeof i18n === 'string' ? i18n : resolveConfigFilepath('i18n');
|
|
91
91
|
var resolvedDictionaryFilePath = typeof dictionary === 'string'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const 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.";
|
|
2
2
|
export declare const APIKeyMissingError = "General Translation: API key is required for automatic translation! Create an API key: www.generaltranslation.com/dashboard/api-keys. (Or, turn off automatic translation by setting baseURL to an empty string.)";
|
|
3
3
|
export declare const remoteTranslationsError = "General Translation: Error fetching remote translation.";
|
|
4
4
|
export declare const renderingError = "General Translation: Rendering error.";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ---- ERRORS ---- //
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.createNoEntryWarning = exports.usingDefaultsWarning = exports.createAdvancedFunctionsError = exports.createRequiredPrefixError = exports.createStringTranslationError = exports.renderingError = exports.remoteTranslationsError = exports.APIKeyMissingError = exports.
|
|
5
|
-
exports.
|
|
4
|
+
exports.createNoEntryWarning = exports.usingDefaultsWarning = exports.createAdvancedFunctionsError = exports.createRequiredPrefixError = exports.createStringTranslationError = exports.renderingError = exports.remoteTranslationsError = exports.APIKeyMissingError = exports.projectIdMissingError = void 0;
|
|
5
|
+
exports.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.';
|
|
6
6
|
exports.APIKeyMissingError = 'General Translation: API key is required for automatic translation! Create an API key: www.generaltranslation.com/dashboard/api-keys. (Or, turn off automatic translation by setting baseURL to an empty string.)';
|
|
7
7
|
exports.remoteTranslationsError = 'General Translation: Error fetching remote translation.';
|
|
8
8
|
exports.renderingError = 'General Translation: Rendering error.';
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt-next",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A Next.js library for automatic internationalization.",
|
|
5
5
|
"main": "dist/index.server.js",
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"generaltranslation": "^4.0
|
|
8
|
-
"gt-react-cli": "^0.
|
|
7
|
+
"generaltranslation": "^4.1.0",
|
|
8
|
+
"gt-react-cli": "^0.2.0",
|
|
9
9
|
"next": ">=13.0.0",
|
|
10
10
|
"react": ">=16.8.0 || >=19.0.0-rc",
|
|
11
11
|
"react-dom": ">=16.8.0 || >=19.0.0-rc"
|
|
@@ -121,6 +121,6 @@
|
|
|
121
121
|
"i18n"
|
|
122
122
|
],
|
|
123
123
|
"dependencies": {
|
|
124
|
-
"gt-react": "^6.0
|
|
124
|
+
"gt-react": "^6.1.0"
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/_dictionary.ts","./src/_request.ts","./src/client.ts","./src/config.ts","./src/index.client.ts","./src/index.server.ts","./src/middleware.ts","./src/server.ts","./src/branches/branch.tsx","./src/branches/plural.tsx","./src/config/i18nconfiguration.ts","./src/config/remotetranslationsmanager.ts","./src/config/geti18nconfig.ts","./src/config/props/initgtprops.ts","./src/config/props/defaultinitgtprops.ts","./src/dictionary/getdictionary.ts","./src/errors/createerrors.ts","./src/middleware/createnextmiddleware.ts","./src/next/getnextdomain.ts","./src/next/getnextlocale.ts","./src/provider/clientprovider.tsx","./src/provider/clientresolver.tsx","./src/provider/gtprovider.tsx","./src/provider/types.ts","./src/request/getlocale.ts","./src/request/getmetadata.ts","./src/server/getgt.tsx","./src/server/inline/resolver.tsx","./src/server/inline/t.tsx","./src/server/rendering/rendervariable.tsx","./src/server/strings/tx.ts","./src/utils/getdefaultfromenv.ts","./src/utils/getgtprop.ts","./src/variables/currency.tsx","./src/variables/datetime.tsx","./src/variables/num.tsx","./src/variables/var.tsx"],"errors":true,"version":"5.6.2"}
|