gt-next 0.0.1
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 +21 -0
- package/dist/_dictionary.d.ts +3 -0
- package/dist/_dictionary.d.ts.map +1 -0
- package/dist/_dictionary.js +6 -0
- package/dist/_dictionary.js.map +1 -0
- package/dist/_request.d.ts +6 -0
- package/dist/_request.d.ts.map +1 -0
- package/dist/_request.js +8 -0
- package/dist/_request.js.map +1 -0
- package/dist/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +11 -0
- package/dist/client.js.map +1 -0
- package/dist/config/I18NConfiguration.d.ts +107 -0
- package/dist/config/I18NConfiguration.d.ts.map +1 -0
- package/dist/config/I18NConfiguration.js +337 -0
- package/dist/config/I18NConfiguration.js.map +1 -0
- package/dist/config/RemoteTranslationsManager.d.ts +66 -0
- package/dist/config/RemoteTranslationsManager.d.ts.map +1 -0
- package/dist/config/RemoteTranslationsManager.js +187 -0
- package/dist/config/RemoteTranslationsManager.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +111 -0
- package/dist/config.js.map +1 -0
- package/dist/dictionary/getDictionary.d.ts +3 -0
- package/dist/dictionary/getDictionary.d.ts.map +1 -0
- package/dist/dictionary/getDictionary.js +22 -0
- package/dist/dictionary/getDictionary.js.map +1 -0
- package/dist/index.client.d.ts +4 -0
- package/dist/index.client.d.ts.map +1 -0
- package/dist/index.client.js +30 -0
- package/dist/index.client.js.map +1 -0
- package/dist/index.server.d.ts +10 -0
- package/dist/index.server.d.ts.map +1 -0
- package/dist/index.server.js +25 -0
- package/dist/index.server.js.map +1 -0
- package/dist/middleware/createNextMiddleware.d.ts +11 -0
- package/dist/middleware/createNextMiddleware.d.ts.map +1 -0
- package/dist/middleware/createNextMiddleware.js +129 -0
- package/dist/middleware/createNextMiddleware.js.map +1 -0
- package/dist/middleware.d.ts +3 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +9 -0
- package/dist/middleware.js.map +1 -0
- package/dist/next/getNextDomain.d.ts +11 -0
- package/dist/next/getNextDomain.d.ts.map +1 -0
- package/dist/next/getNextDomain.js +18 -0
- package/dist/next/getNextDomain.js.map +1 -0
- package/dist/next/getNextLocale.d.ts +11 -0
- package/dist/next/getNextLocale.d.ts.map +1 -0
- package/dist/next/getNextLocale.js +34 -0
- package/dist/next/getNextLocale.js.map +1 -0
- package/dist/primitives/InitGTProps.d.ts +24 -0
- package/dist/primitives/InitGTProps.d.ts.map +1 -0
- package/dist/primitives/InitGTProps.js +3 -0
- package/dist/primitives/InitGTProps.js.map +1 -0
- package/dist/primitives/defaultInitGTProps.d.ts +19 -0
- package/dist/primitives/defaultInitGTProps.d.ts.map +1 -0
- package/dist/primitives/defaultInitGTProps.js +25 -0
- package/dist/primitives/defaultInitGTProps.js.map +1 -0
- package/dist/provider/ClientResolver.d.ts +2 -0
- package/dist/provider/ClientResolver.d.ts.map +1 -0
- package/dist/provider/ClientResolver.js +71 -0
- package/dist/provider/ClientResolver.js.map +1 -0
- package/dist/provider/GTServerProvider.d.ts +6 -0
- package/dist/provider/GTServerProvider.d.ts.map +1 -0
- package/dist/provider/GTServerProvider.js +182 -0
- package/dist/provider/GTServerProvider.js.map +1 -0
- package/dist/provider/_ClientProvider.d.ts +9 -0
- package/dist/provider/_ClientProvider.d.ts.map +1 -0
- package/dist/provider/_ClientProvider.js +113 -0
- package/dist/provider/_ClientProvider.js.map +1 -0
- package/dist/request/getLocale.d.ts +2 -0
- package/dist/request/getLocale.d.ts.map +1 -0
- package/dist/request/getLocale.js +30 -0
- package/dist/request/getLocale.js.map +1 -0
- package/dist/request/getMetadata.d.ts +2 -0
- package/dist/request/getMetadata.d.ts.map +1 -0
- package/dist/request/getMetadata.js +27 -0
- package/dist/request/getMetadata.js.map +1 -0
- package/dist/server/createServerTFunction.d.ts +3 -0
- package/dist/server/createServerTFunction.d.ts.map +1 -0
- package/dist/server/createServerTFunction.js +59 -0
- package/dist/server/createServerTFunction.js.map +1 -0
- package/dist/server/getGT.d.ts +2 -0
- package/dist/server/getGT.d.ts.map +1 -0
- package/dist/server/getGT.js +11 -0
- package/dist/server/getGT.js.map +1 -0
- package/dist/server/inline/Resolver.d.ts +5 -0
- package/dist/server/inline/Resolver.d.ts.map +1 -0
- package/dist/server/inline/Resolver.js +59 -0
- package/dist/server/inline/Resolver.js.map +1 -0
- package/dist/server/inline/T.d.ts +16 -0
- package/dist/server/inline/T.d.ts.map +1 -0
- package/dist/server/inline/T.js +196 -0
- package/dist/server/inline/T.js.map +1 -0
- package/dist/server/rendering/renderDefaultChildren.d.ts +7 -0
- package/dist/server/rendering/renderDefaultChildren.d.ts.map +1 -0
- package/dist/server/rendering/renderDefaultChildren.js +48 -0
- package/dist/server/rendering/renderDefaultChildren.js.map +1 -0
- package/dist/server/rendering/renderTranslatedChildren.d.ts +15 -0
- package/dist/server/rendering/renderTranslatedChildren.d.ts.map +1 -0
- package/dist/server/rendering/renderTranslatedChildren.js +141 -0
- package/dist/server/rendering/renderTranslatedChildren.js.map +1 -0
- package/dist/server/strings/translate.d.ts +9 -0
- package/dist/server/strings/translate.d.ts.map +1 -0
- package/dist/server/strings/translate.js +105 -0
- package/dist/server/strings/translate.js.map +1 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +11 -0
- package/dist/server.js.map +1 -0
- package/dist/utils/getDefaultFromEnv.d.ts +12 -0
- package/dist/utils/getDefaultFromEnv.d.ts.map +1 -0
- package/dist/utils/getDefaultFromEnv.js +21 -0
- package/dist/utils/getDefaultFromEnv.js.map +1 -0
- package/dist/utils/getGTProp.d.ts +5 -0
- package/dist/utils/getGTProp.d.ts.map +1 -0
- package/dist/utils/getGTProp.js +11 -0
- package/dist/utils/getGTProp.js.map +1 -0
- package/dist/utils/getI18NConfig.d.ts +3 -0
- package/dist/utils/getI18NConfig.d.ts.map +1 -0
- package/dist/utils/getI18NConfig.js +7 -0
- package/dist/utils/getI18NConfig.js.map +1 -0
- package/dist/variables/Currency.d.ts +14 -0
- package/dist/variables/Currency.d.ts.map +1 -0
- package/dist/variables/Currency.js +48 -0
- package/dist/variables/Currency.js.map +1 -0
- package/dist/variables/DateTime.d.ts +12 -0
- package/dist/variables/DateTime.d.ts.map +1 -0
- package/dist/variables/DateTime.js +53 -0
- package/dist/variables/DateTime.js.map +1 -0
- package/dist/variables/Num.d.ts +13 -0
- package/dist/variables/Num.d.ts.map +1 -0
- package/dist/variables/Num.js +35 -0
- package/dist/variables/Num.js.map +1 -0
- package/dist/variables/Var.d.ts +12 -0
- package/dist/variables/Var.d.ts.map +1 -0
- package/dist/variables/Var.js +24 -0
- package/dist/variables/Var.js.map +1 -0
- package/package.json +115 -0
- package/scratchpad.js +19 -0
- package/tsconfig.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# gt-next
|
|
2
|
+
|
|
3
|
+
An extension of the `gt-react` library for automatic internationalization in Next.js. Works with client and server components.
|
|
4
|
+
|
|
5
|
+
See [gt-react](https://github.com/General-Translation/gt-next) for the pure React version of this library.
|
|
6
|
+
|
|
7
|
+
See [gt-update](https://github.com/General-Translation/gt-update) for the CLI tool that lets you push your dictionaries for translation.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm i gt-next
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Docs
|
|
16
|
+
|
|
17
|
+
<a href="https://docs.generaltranslation.com/gt-next">docs.generaltranslation.com</a>
|
|
18
|
+
|
|
19
|
+
## Cloud
|
|
20
|
+
|
|
21
|
+
<a href="https://www.generaltranslation.com">www.generaltranslation.com</a>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dictionary.d.ts","sourceRoot":"","sources":["../src/_dictionary.ts"],"names":[],"mappings":";AAEA,wBAAkB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// hidden internal route
|
|
4
|
+
throw new Error("Something has gone seriously wrong if you're seeing this error message. Check docs.generaltranslation.com for the latest documentation and make sure you've got the library configured properly.");
|
|
5
|
+
exports.default = {};
|
|
6
|
+
//# sourceMappingURL=_dictionary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dictionary.js","sourceRoot":"","sources":["../src/_dictionary.ts"],"names":[],"mappings":";;AAAA,wBAAwB;AACxB,MAAM,IAAI,KAAK,CAAC,kMAAkM,CAAC,CAAA;AACnN,kBAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_request.d.ts","sourceRoot":"","sources":["../src/_request.ts"],"names":[],"mappings":";;;;AACA,wBAGC"}
|
package/dist/_request.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// hidden internal route
|
|
4
|
+
exports.default = {
|
|
5
|
+
getLocale: function () { throw new Error("Unable to import custom getLocale(). Check docs.generaltranslation.com for the latest documentation."); },
|
|
6
|
+
getMetadata: function () { throw new Error("Unable to import custom getLocale(). Check docs.generaltranslation.com for the latest documentation."); }
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=_request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_request.js","sourceRoot":"","sources":["../src/_request.ts"],"names":[],"mappings":";;AAAA,wBAAwB;AACxB,kBAAe;IACX,SAAS,EAAE,cAAQ,MAAM,IAAI,KAAK,CAAC,sGAAsG,CAAC,CAAA,CAAC,CAAC;IAC5I,WAAW,EAAE,cAAQ,MAAM,IAAI,KAAK,CAAC,sGAAsG,CAAC,CAAA,CAAC,CAAC;CACjJ,CAAA"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EACL,gBAAgB,EAAE,SAAS,EAC3B,UAAU,IAAI,gBAAgB,EACjC,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EACH,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAClC,gBAAgB,EAAE,gBAAgB,EACrC,CAAA"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GTClientProvider = exports.useBrowserLocale = exports.useLocale = exports.useDefaultLocale = exports.useGT = void 0;
|
|
4
|
+
var gt_react_1 = require("gt-react");
|
|
5
|
+
Object.defineProperty(exports, "useGT", { enumerable: true, get: function () { return gt_react_1.useGT; } });
|
|
6
|
+
Object.defineProperty(exports, "useDefaultLocale", { enumerable: true, get: function () { return gt_react_1.useDefaultLocale; } });
|
|
7
|
+
Object.defineProperty(exports, "useLocale", { enumerable: true, get: function () { return gt_react_1.useLocale; } });
|
|
8
|
+
Object.defineProperty(exports, "GTClientProvider", { enumerable: true, get: function () { return gt_react_1.GTProvider; } });
|
|
9
|
+
var client_1 = require("gt-react/client");
|
|
10
|
+
Object.defineProperty(exports, "useBrowserLocale", { enumerable: true, get: function () { return client_1.useBrowserLocale; } });
|
|
11
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,qCAIkB;AAGd,sFANA,gBAAK,OAMA;AAAE,iGALP,2BAAgB,OAKO;AAAE,0FALP,oBAAS,OAKO;AAChB,iGALJ,qBAAgB,OAKI;AAHtC,0CAAkD;AAG9C,iGAHK,yBAAgB,OAGL"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import GT from "generaltranslation";
|
|
2
|
+
type I18NConfigurationParams = {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
projectID: string;
|
|
5
|
+
cacheURL: string;
|
|
6
|
+
baseURL: string;
|
|
7
|
+
defaultLocale: string;
|
|
8
|
+
locales?: string[];
|
|
9
|
+
renderSettings: {
|
|
10
|
+
fallbackToPrevious: boolean;
|
|
11
|
+
method: "skeleton" | "replace" | "hang" | "subtle";
|
|
12
|
+
timeout: number | null;
|
|
13
|
+
};
|
|
14
|
+
dictionaryName: string;
|
|
15
|
+
translations?: Record<string, () => Promise<Record<string, any>>>;
|
|
16
|
+
maxConcurrentRequests: number;
|
|
17
|
+
batchInterval: number;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
20
|
+
export default class I18NConfiguration {
|
|
21
|
+
baseURL: string;
|
|
22
|
+
projectID: string;
|
|
23
|
+
defaultLocale: string;
|
|
24
|
+
locales: string[] | undefined;
|
|
25
|
+
renderSettings: {
|
|
26
|
+
fallbackToPrevious: boolean;
|
|
27
|
+
method: "skeleton" | "replace" | "hang" | "subtle";
|
|
28
|
+
timeout: number | null;
|
|
29
|
+
};
|
|
30
|
+
dictionaryName: string;
|
|
31
|
+
private _remoteTranslationsManager;
|
|
32
|
+
gt: GT;
|
|
33
|
+
metadata: Record<string, any>;
|
|
34
|
+
maxConcurrentRequests: number;
|
|
35
|
+
batchInterval: number;
|
|
36
|
+
private _queue;
|
|
37
|
+
private _activeRequests;
|
|
38
|
+
private _translationCache;
|
|
39
|
+
constructor({ apiKey, projectID, baseURL, cacheURL, defaultLocale, locales, renderSettings, dictionary, dictionaryName, maxConcurrentRequests, batchInterval, ...metadata }: I18NConfigurationParams);
|
|
40
|
+
/**
|
|
41
|
+
* Gets the application's default locale
|
|
42
|
+
* @returns {string} A BCP-47 language tag
|
|
43
|
+
*/
|
|
44
|
+
getDefaultLocale(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the list of approved locales for this app
|
|
47
|
+
* @returns {string[] | undefined} A list of BCP-47 language tags, or undefined if none were provided
|
|
48
|
+
*/
|
|
49
|
+
getLocales(): string[] | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the name of the current dictionary
|
|
52
|
+
* @returns {string} A BCP-47 language tag
|
|
53
|
+
*/
|
|
54
|
+
getDictionaryName(): string;
|
|
55
|
+
/**
|
|
56
|
+
* @returns A boolean indicating whether automatic translation is enabled or disabled for this config
|
|
57
|
+
*/
|
|
58
|
+
translationEnabled(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Get the rendering instructions
|
|
61
|
+
* @returns An object containing the current method and timeout.
|
|
62
|
+
* As of 7/31/24: method is "skeleton", "replace", "hang", "subtle".
|
|
63
|
+
* Timeout is a number or null, representing no assigned timeout.
|
|
64
|
+
* fallbackToPrevious determines whether a non-matching previous entry should be rendered while the new translation loads.
|
|
65
|
+
*/
|
|
66
|
+
getRenderSettings(): {
|
|
67
|
+
method: "skeleton" | "replace" | "hang" | "subtle";
|
|
68
|
+
timeout: number | null;
|
|
69
|
+
fallbackToPrevious: boolean;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Check if translation is required based on the user's locale
|
|
73
|
+
* @param locale - The user's locale
|
|
74
|
+
* @returns True if translation is required, otherwise false
|
|
75
|
+
*/
|
|
76
|
+
translationRequired(locale: string): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Get the translation dictionaries for this user's locale, if they exist
|
|
79
|
+
* @param locale - The language set by the user
|
|
80
|
+
* @param dictionaryName - User-defined dictionary name, for distinguishing between multiple translation dictionaries for a single language.
|
|
81
|
+
* @returns A promise that resolves to the translations.
|
|
82
|
+
*/
|
|
83
|
+
getTranslations(locale: string, dictionaryName?: string): Promise<Record<string, any>>;
|
|
84
|
+
/**
|
|
85
|
+
* Translate content into language
|
|
86
|
+
* @param params - Parameters for translation
|
|
87
|
+
* @returns Translated string
|
|
88
|
+
*/
|
|
89
|
+
translate(params: any): Promise<string>;
|
|
90
|
+
/**
|
|
91
|
+
* Translate the children components
|
|
92
|
+
* @param params - Parameters for translation
|
|
93
|
+
* @returns A promise that resolves when translation is complete
|
|
94
|
+
*/
|
|
95
|
+
translateChildren(params: any): Promise<any>;
|
|
96
|
+
/**
|
|
97
|
+
* Send a batch request for React translation
|
|
98
|
+
* @param batch - The batch of requests to be sent
|
|
99
|
+
*/
|
|
100
|
+
private _sendBatchRequest;
|
|
101
|
+
/**
|
|
102
|
+
* Start the batching process with a set interval
|
|
103
|
+
*/
|
|
104
|
+
private _startBatching;
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=I18NConfiguration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"I18NConfiguration.d.ts","sourceRoot":"","sources":["../../src/config/I18NConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,MAAM,oBAAoB,CAAC;AAGxD,KAAK,uBAAuB,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,EAAE;QACZ,kBAAkB,EAAE,OAAO,CAAC;QAC5B,MAAM,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;QACnD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;KACzB,CAAA;IACD,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAClE,qBAAqB,EAAE,MAAM,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAA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C9B;IAID;;;;OAIG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAO5C;;;;;MAKE;IACI,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,GAAE,MAA4B,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAIjH;;;;OAIG;IACG,SAAS,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAyB7C;;;;MAIE;IACI,iBAAiB,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAwBlD;;;OAGG;YACW,iBAAiB;IAgC/B;;MAEE;IACF,OAAO,CAAC,cAAc;CASzB"}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
+
function step(op) {
|
|
50
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
52
|
+
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;
|
|
53
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
+
switch (op[0]) {
|
|
55
|
+
case 0: case 1: t = op; break;
|
|
56
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
+
default:
|
|
60
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
+
if (t[2]) _.ops.pop();
|
|
65
|
+
_.trys.pop(); continue;
|
|
66
|
+
}
|
|
67
|
+
op = body.call(thisArg, _);
|
|
68
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
73
|
+
var t = {};
|
|
74
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
75
|
+
t[p] = s[p];
|
|
76
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
77
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
78
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
79
|
+
t[p[i]] = s[p[i]];
|
|
80
|
+
}
|
|
81
|
+
return t;
|
|
82
|
+
};
|
|
83
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
84
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
85
|
+
};
|
|
86
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
87
|
+
var generaltranslation_1 = __importStar(require("generaltranslation"));
|
|
88
|
+
var RemoteTranslationsManager_1 = __importDefault(require("./RemoteTranslationsManager"));
|
|
89
|
+
var I18NConfiguration = /** @class */ (function () {
|
|
90
|
+
function I18NConfiguration(_a) {
|
|
91
|
+
var
|
|
92
|
+
// Cloud integration
|
|
93
|
+
apiKey = _a.apiKey, projectID = _a.projectID, baseURL = _a.baseURL, cacheURL = _a.cacheURL,
|
|
94
|
+
// Locale info
|
|
95
|
+
defaultLocale = _a.defaultLocale, locales = _a.locales,
|
|
96
|
+
// Render method
|
|
97
|
+
renderSettings = _a.renderSettings,
|
|
98
|
+
// Dictionaries
|
|
99
|
+
dictionary = _a.dictionary, dictionaryName = _a.dictionaryName,
|
|
100
|
+
// Batching config
|
|
101
|
+
maxConcurrentRequests = _a.maxConcurrentRequests, batchInterval = _a.batchInterval,
|
|
102
|
+
// Other metadata
|
|
103
|
+
metadata = __rest(_a, ["apiKey", "projectID", "baseURL", "cacheURL", "defaultLocale", "locales", "renderSettings", "dictionary", "dictionaryName", "maxConcurrentRequests", "batchInterval"]);
|
|
104
|
+
// Cloud integration
|
|
105
|
+
this.projectID = projectID;
|
|
106
|
+
this.baseURL = baseURL;
|
|
107
|
+
// Locales
|
|
108
|
+
this.defaultLocale = defaultLocale;
|
|
109
|
+
this.locales = locales;
|
|
110
|
+
// Render method
|
|
111
|
+
this.renderSettings = renderSettings;
|
|
112
|
+
// Dictionaries
|
|
113
|
+
this.dictionaryName = dictionaryName;
|
|
114
|
+
// GT
|
|
115
|
+
this.gt = new generaltranslation_1.default({ projectID: projectID, apiKey: apiKey, defaultLanguage: defaultLocale, baseURL: baseURL });
|
|
116
|
+
// Other metadata
|
|
117
|
+
this.metadata = __assign(__assign({ projectID: this.projectID, defaultLanguage: this.defaultLocale, dictionaryName: dictionaryName }, (this.renderSettings.timeout && { timeout: this.renderSettings.timeout - batchInterval })), metadata);
|
|
118
|
+
// Dictionary managers
|
|
119
|
+
if (cacheURL && projectID) {
|
|
120
|
+
this._remoteTranslationsManager = RemoteTranslationsManager_1.default;
|
|
121
|
+
this._remoteTranslationsManager.setConfig({
|
|
122
|
+
cacheURL: cacheURL,
|
|
123
|
+
projectID: projectID
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// Batching
|
|
127
|
+
this.maxConcurrentRequests = maxConcurrentRequests;
|
|
128
|
+
this.batchInterval = batchInterval;
|
|
129
|
+
this._queue = [];
|
|
130
|
+
this._activeRequests = 0;
|
|
131
|
+
this._translationCache = new Map(); // cache for ongoing promises, so things aren't translated twice
|
|
132
|
+
this._startBatching();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Gets the application's default locale
|
|
136
|
+
* @returns {string} A BCP-47 language tag
|
|
137
|
+
*/
|
|
138
|
+
I18NConfiguration.prototype.getDefaultLocale = function () {
|
|
139
|
+
return this.defaultLocale;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Gets the list of approved locales for this app
|
|
143
|
+
* @returns {string[] | undefined} A list of BCP-47 language tags, or undefined if none were provided
|
|
144
|
+
*/
|
|
145
|
+
I18NConfiguration.prototype.getLocales = function () {
|
|
146
|
+
return this.locales;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Gets the name of the current dictionary
|
|
150
|
+
* @returns {string} A BCP-47 language tag
|
|
151
|
+
*/
|
|
152
|
+
I18NConfiguration.prototype.getDictionaryName = function () {
|
|
153
|
+
return this.dictionaryName;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* @returns A boolean indicating whether automatic translation is enabled or disabled for this config
|
|
157
|
+
*/
|
|
158
|
+
I18NConfiguration.prototype.translationEnabled = function () {
|
|
159
|
+
return (this.baseURL && this.projectID) ? true : false;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Get the rendering instructions
|
|
163
|
+
* @returns An object containing the current method and timeout.
|
|
164
|
+
* As of 7/31/24: method is "skeleton", "replace", "hang", "subtle".
|
|
165
|
+
* Timeout is a number or null, representing no assigned timeout.
|
|
166
|
+
* fallbackToPrevious determines whether a non-matching previous entry should be rendered while the new translation loads.
|
|
167
|
+
*/
|
|
168
|
+
I18NConfiguration.prototype.getRenderSettings = function () {
|
|
169
|
+
return this.renderSettings;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Check if translation is required based on the user's locale
|
|
173
|
+
* @param locale - The user's locale
|
|
174
|
+
* @returns True if translation is required, otherwise false
|
|
175
|
+
*/
|
|
176
|
+
I18NConfiguration.prototype.translationRequired = function (locale) {
|
|
177
|
+
if (!locale)
|
|
178
|
+
return false;
|
|
179
|
+
if (this.locales && !this.locales.some(function (approvedLocale) { return (0, generaltranslation_1.isSameLanguage)(locale, approvedLocale); }))
|
|
180
|
+
return false;
|
|
181
|
+
if ((0, generaltranslation_1.isSameLanguage)(locale, this.defaultLocale))
|
|
182
|
+
return false;
|
|
183
|
+
return true;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Get the translation dictionaries for this user's locale, if they exist
|
|
187
|
+
* @param locale - The language set by the user
|
|
188
|
+
* @param dictionaryName - User-defined dictionary name, for distinguishing between multiple translation dictionaries for a single language.
|
|
189
|
+
* @returns A promise that resolves to the translations.
|
|
190
|
+
*/
|
|
191
|
+
I18NConfiguration.prototype.getTranslations = function (locale_1) {
|
|
192
|
+
return __awaiter(this, arguments, void 0, function (locale, dictionaryName) {
|
|
193
|
+
var _a;
|
|
194
|
+
if (dictionaryName === void 0) { dictionaryName = this.dictionaryName; }
|
|
195
|
+
return __generator(this, function (_b) {
|
|
196
|
+
switch (_b.label) {
|
|
197
|
+
case 0: return [4 /*yield*/, ((_a = this._remoteTranslationsManager) === null || _a === void 0 ? void 0 : _a.getTranslations(locale, dictionaryName))];
|
|
198
|
+
case 1: return [2 /*return*/, (_b.sent()) || {}];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Translate content into language
|
|
205
|
+
* @param params - Parameters for translation
|
|
206
|
+
* @returns Translated string
|
|
207
|
+
*/
|
|
208
|
+
I18NConfiguration.prototype.translate = function (params) {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
210
|
+
var cacheKey, content, targetLanguage, options, dictionaryName, translationPromise;
|
|
211
|
+
var _this = this;
|
|
212
|
+
var _a;
|
|
213
|
+
return __generator(this, function (_b) {
|
|
214
|
+
cacheKey = JSON.stringify(params);
|
|
215
|
+
if (this._translationCache.has(cacheKey)) {
|
|
216
|
+
return [2 /*return*/, this._translationCache.get(cacheKey)];
|
|
217
|
+
}
|
|
218
|
+
content = params.content, targetLanguage = params.targetLanguage, options = params.options;
|
|
219
|
+
dictionaryName = ((_a = params.options) === null || _a === void 0 ? void 0 : _a.dictionaryName) || this.dictionaryName;
|
|
220
|
+
translationPromise = new Promise(function (resolve, reject) {
|
|
221
|
+
_this._queue.push({
|
|
222
|
+
type: "string",
|
|
223
|
+
data: {
|
|
224
|
+
content: content,
|
|
225
|
+
targetLanguage: targetLanguage,
|
|
226
|
+
projectID: _this.projectID,
|
|
227
|
+
metadata: __assign(__assign({}, _this.metadata), options)
|
|
228
|
+
},
|
|
229
|
+
revalidate: (_this._remoteTranslationsManager) ? _this._remoteTranslationsManager.getTranslationRequested(targetLanguage, dictionaryName) : false,
|
|
230
|
+
resolve: resolve,
|
|
231
|
+
reject: reject
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
this._translationCache.set(cacheKey, translationPromise);
|
|
235
|
+
return [2 /*return*/, translationPromise.finally(function () { return _this._translationCache.delete(cacheKey); })];
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* Translate the children components
|
|
241
|
+
* @param params - Parameters for translation
|
|
242
|
+
* @returns A promise that resolves when translation is complete
|
|
243
|
+
*/
|
|
244
|
+
I18NConfiguration.prototype.translateChildren = function (params) {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
246
|
+
var cacheKey, children, targetLanguage, metadata, dictionaryName, translationPromise;
|
|
247
|
+
var _this = this;
|
|
248
|
+
var _a;
|
|
249
|
+
return __generator(this, function (_b) {
|
|
250
|
+
cacheKey = JSON.stringify(params);
|
|
251
|
+
if (this._translationCache.has(cacheKey)) {
|
|
252
|
+
return [2 /*return*/, this._translationCache.get(cacheKey)];
|
|
253
|
+
}
|
|
254
|
+
children = params.children, targetLanguage = params.targetLanguage, metadata = params.metadata;
|
|
255
|
+
dictionaryName = ((_a = params.options) === null || _a === void 0 ? void 0 : _a.dictionaryName) || this.dictionaryName;
|
|
256
|
+
translationPromise = new Promise(function (resolve, reject) {
|
|
257
|
+
_this._queue.push({
|
|
258
|
+
type: "react",
|
|
259
|
+
data: {
|
|
260
|
+
children: children,
|
|
261
|
+
targetLanguage: targetLanguage,
|
|
262
|
+
metadata: __assign(__assign({}, _this.metadata), metadata)
|
|
263
|
+
},
|
|
264
|
+
revalidate: (_this._remoteTranslationsManager) ? _this._remoteTranslationsManager.getTranslationRequested(targetLanguage, dictionaryName) : false,
|
|
265
|
+
resolve: resolve,
|
|
266
|
+
reject: reject
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
this._translationCache.set(cacheKey, translationPromise);
|
|
270
|
+
return [2 /*return*/, translationPromise.finally(function () { return _this._translationCache.delete(cacheKey); })];
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Send a batch request for React translation
|
|
276
|
+
* @param batch - The batch of requests to be sent
|
|
277
|
+
*/
|
|
278
|
+
I18NConfiguration.prototype._sendBatchRequest = function (batch) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
280
|
+
var bundlePromise, results_1, error_1;
|
|
281
|
+
var _this = this;
|
|
282
|
+
return __generator(this, function (_a) {
|
|
283
|
+
switch (_a.label) {
|
|
284
|
+
case 0:
|
|
285
|
+
this._activeRequests++;
|
|
286
|
+
_a.label = 1;
|
|
287
|
+
case 1:
|
|
288
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
289
|
+
bundlePromise = this.gt.translateBundle(batch);
|
|
290
|
+
batch.forEach(function (item) {
|
|
291
|
+
if (_this._remoteTranslationsManager && item.cache)
|
|
292
|
+
_this._remoteTranslationsManager.setTranslationRequested(item.data.targetLanguage, item.data.metadata.dictionaryName);
|
|
293
|
+
});
|
|
294
|
+
return [4 /*yield*/, bundlePromise];
|
|
295
|
+
case 2:
|
|
296
|
+
results_1 = _a.sent();
|
|
297
|
+
batch.forEach(function (item, index) {
|
|
298
|
+
var result = results_1[index];
|
|
299
|
+
if (!result)
|
|
300
|
+
return item.reject('Translation failed.');
|
|
301
|
+
if (result && typeof result === 'object') {
|
|
302
|
+
item.resolve(result.translation);
|
|
303
|
+
if (result.translation && result.language && result.reference && _this._remoteTranslationsManager) {
|
|
304
|
+
_this._remoteTranslationsManager.setTranslations(result.language, result.reference.dictionaryName, result.reference.key, result.reference.id, result.translation);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
return [3 /*break*/, 5];
|
|
309
|
+
case 3:
|
|
310
|
+
error_1 = _a.sent();
|
|
311
|
+
console.error(error_1);
|
|
312
|
+
batch.forEach(function (item) { return item.reject(error_1); });
|
|
313
|
+
return [3 /*break*/, 5];
|
|
314
|
+
case 4:
|
|
315
|
+
this._activeRequests--;
|
|
316
|
+
return [7 /*endfinally*/];
|
|
317
|
+
case 5: return [2 /*return*/];
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Start the batching process with a set interval
|
|
324
|
+
*/
|
|
325
|
+
I18NConfiguration.prototype._startBatching = function () {
|
|
326
|
+
var _this = this;
|
|
327
|
+
setInterval(function () {
|
|
328
|
+
if (_this._queue.length > 0 && _this._activeRequests < _this.maxConcurrentRequests) {
|
|
329
|
+
_this._sendBatchRequest(_this._queue);
|
|
330
|
+
_this._queue = [];
|
|
331
|
+
}
|
|
332
|
+
}, this.batchInterval);
|
|
333
|
+
};
|
|
334
|
+
return I18NConfiguration;
|
|
335
|
+
}());
|
|
336
|
+
exports.default = I18NConfiguration;
|
|
337
|
+
//# sourceMappingURL=I18NConfiguration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"I18NConfiguration.js","sourceRoot":"","sources":["../../src/config/I18NConfiguration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uEAAwD;AACxD,0FAAmG;AAqBnG;IA4BI,2BAAY,EAec;QAbtB;QADA,oBAAoB;QACpB,MAAM,YAAA,EAAE,SAAS,eAAA,EACjB,OAAO,aAAA,EAAE,QAAQ,cAAA;QACjB,cAAc;QACd,aAAa,mBAAA,EACb,OAAO,aAAA;QACP,gBAAgB;QAChB,cAAc,oBAAA;QACd,eAAe;QACf,UAAU,gBAAA,EAAE,cAAc,oBAAA;QAC1B,kBAAkB;QAClB,qBAAqB,2BAAA,EAAE,aAAa,mBAAA;QACpC,iBAAiB;QACd,QAAQ,cAdH,sKAeX,CADc;QAEX,oBAAoB;QACpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,UAAU;QACV,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,gBAAgB;QAChB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,eAAe;QACf,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,KAAK;QACL,IAAI,CAAC,EAAE,GAAG,IA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gBACpC,KAAI,CAAC,MAAM,GAAG,EAAE,CAAC;YACrB,CAAC;QACL,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC3B,CAAC;IAEL,wBAAC;AAAD,CAAC,AA/PD,IA+PC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a dictionary reference string from locale and dictionary name.
|
|
3
|
+
* @param {string} locale - The locale of the dictionary.
|
|
4
|
+
* @param {string} dictionaryName - The name of the dictionary.
|
|
5
|
+
* @returns {string} The encoded dictionary reference.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getDictionaryReference(locale: string, dictionaryName: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Configuration type for RemoteTranslationsManager.
|
|
10
|
+
*/
|
|
11
|
+
type RemoteTranslationsConfig = {
|
|
12
|
+
cacheURL: string;
|
|
13
|
+
projectID: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Manages remote dictionaries for translation purposes.
|
|
17
|
+
*/
|
|
18
|
+
export declare class RemoteTranslationsManager {
|
|
19
|
+
private config;
|
|
20
|
+
private dictionaryMap;
|
|
21
|
+
private fetchPromises;
|
|
22
|
+
private requestedTranslations;
|
|
23
|
+
/**
|
|
24
|
+
* Creates an instance of RemoteTranslationsManager.
|
|
25
|
+
*/
|
|
26
|
+
constructor();
|
|
27
|
+
/**
|
|
28
|
+
* Sets the configuration for the RemoteDictionaryManager.
|
|
29
|
+
* @param {Partial<RemoteDictionaryConfig>} newConfig - The new configuration to apply.
|
|
30
|
+
*/
|
|
31
|
+
setConfig(newConfig: Partial<RemoteTranslationsConfig>): void;
|
|
32
|
+
/**
|
|
33
|
+
* Fetches a dictionary from the remote cache.
|
|
34
|
+
* @param {string} reference - The dictionary reference.
|
|
35
|
+
* @returns {Promise<Record<string, any> | null>} The fetched dictionary or null if not found.
|
|
36
|
+
*/
|
|
37
|
+
private _fetchDictionary;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves a dictionary based on locale and dictionary name.
|
|
40
|
+
* @param {string} locale - The locale of the dictionary.
|
|
41
|
+
* @param {string} dictionaryName - The name of the dictionary.
|
|
42
|
+
* @returns {Promise<Record<string, any> | null>} The dictionary data or null if not found.
|
|
43
|
+
*/
|
|
44
|
+
getTranslations(locale: string, dictionaryName: string): Promise<Record<string, any> | null>;
|
|
45
|
+
/**
|
|
46
|
+
* Sets a new entry in the specified dictionary.
|
|
47
|
+
* @param {string} locale - The locale of the dictionary.
|
|
48
|
+
* @param {string} dictionaryName - The name of the dictionary.
|
|
49
|
+
* @param {string} key - The key for the new entry.
|
|
50
|
+
* @param {string} [id=key] - The id for the new entry, defaults to key if not provided.
|
|
51
|
+
* @param {any} translation - The translation value.
|
|
52
|
+
* @returns {boolean} True if the entry was set successfully, false otherwise.
|
|
53
|
+
*/
|
|
54
|
+
setTranslations(locale: string, dictionaryName: string, key: string, id: string | undefined, translation: any): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Marks a translation as requested for a given locale and dictionary
|
|
57
|
+
*/
|
|
58
|
+
setTranslationRequested(locale: string, dictionaryName: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a translation has been requested for a given locale and dictionary
|
|
61
|
+
*/
|
|
62
|
+
getTranslationRequested(locale: string, dictionaryName: string): boolean;
|
|
63
|
+
}
|
|
64
|
+
declare const remoteDictionaryManager: RemoteTranslationsManager;
|
|
65
|
+
export default remoteDictionaryManager;
|
|
66
|
+
//# sourceMappingURL=RemoteTranslationsManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteTranslationsManager.d.ts","sourceRoot":"","sources":["../../src/config/RemoteTranslationsManager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAErF;AAED;;GAEG;AACH,KAAK,wBAAwB,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACrB,CAAA;AAED;;GAEG;AACH,qBAAa,yBAAyB;IAClC,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,aAAa,CAAmC;IACxD,OAAO,CAAC,aAAa,CAAmD;IACxE,OAAO,CAAC,qBAAqB,CAAuB;IAEpD;;OAEG;;IAWH;;;OAGG;IACH,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,IAAI;IAI7D;;;;OAIG;YACW,gBAAgB;IAa9B;;;;;OAKG;IACG,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAqBlG;;;;;;;;OAQG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,YAAM,EAAE,WAAW,EAAE,GAAG,GAAG,OAAO;IAUjH;;OAEG;IACH,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAK9D;;OAEG;IACH,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO;CAK3E;AAED,QAAA,MAAM,uBAAuB,2BAAkC,CAAC;AAChE,eAAe,uBAAuB,CAAC"}
|