@l10nmonster/helpers-translated 3.0.0-alpha.6 → 3.0.0-alpha.8
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/laraProvider.js +6 -6
- package/mmtProvider.js +1 -1
- package/package.json +1 -1
package/laraProvider.js
CHANGED
|
@@ -6,7 +6,8 @@ import { Credentials, Translator } from '@translated/lara';
|
|
|
6
6
|
* @extends ChunkedRemoteTranslationProviderOptions
|
|
7
7
|
* @property {string} keyId - The Lara API key id. This is required.
|
|
8
8
|
* @property {Promise<string>|string} [keySecret] - The Lara API key secret. Optional, but often needed for authentication.
|
|
9
|
-
* @property {string|Array<string>} [adaptTo] - An optional single translation memory ID or an array of IDs to adapt translations to.
|
|
9
|
+
* @property {string | Array<string>} [adaptTo] - An optional single translation memory ID or an array of IDs to adapt translations to.
|
|
10
|
+
* @property {string | Array<string>} [glossaries] - Glossaries to include in the request.
|
|
10
11
|
* @property {number} [maxChunkSize=60] - Maximum number of text segments (strings) allowed in a single API request chunk. Defaults to 60 if not provided.
|
|
11
12
|
*/
|
|
12
13
|
|
|
@@ -16,28 +17,27 @@ import { Credentials, Translator } from '@translated/lara';
|
|
|
16
17
|
export class LaraProvider extends providers.ChunkedRemoteTranslationProvider {
|
|
17
18
|
#keyId;
|
|
18
19
|
#keySecret;
|
|
19
|
-
#adaptTo;
|
|
20
20
|
#translateOptions;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Initializes a new instance of the LaraProvider class.
|
|
24
24
|
* @param {LaraProviderOptions} options - Configuration options for the provider.
|
|
25
25
|
*/
|
|
26
|
-
constructor({ keyId, keySecret, adaptTo, ...options }) {
|
|
26
|
+
constructor({ keyId, keySecret, adaptTo, glossaries, ...options }) {
|
|
27
27
|
super({ maxChunkSize: 60, ...options }); // maximum number of strings sent to Lara is 128 including notes
|
|
28
28
|
this.#keyId = keyId;
|
|
29
29
|
this.#keySecret = keySecret;
|
|
30
|
-
this.#adaptTo = adaptTo && (Array.isArray(adaptTo) ? adaptTo : adaptTo.split(','));
|
|
31
30
|
this.#translateOptions = {
|
|
32
31
|
contentType: 'text/plain',
|
|
33
32
|
instructions: [],
|
|
34
33
|
};
|
|
35
|
-
|
|
34
|
+
adaptTo && (this.#translateOptions.adaptTo = Array.isArray(adaptTo) ? adaptTo : adaptTo.split(','));
|
|
35
|
+
glossaries && (this.#translateOptions.glossaries = Array.isArray(glossaries) ? glossaries : glossaries.split(','));
|
|
36
36
|
this.defaultInstructions && this.#translateOptions.instructions.push(this.defaultInstructions);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
async #getLara() {
|
|
40
|
-
const credentials = new Credentials(this.#keyId, await this.#keySecret);
|
|
40
|
+
const credentials = new Credentials(this.#keyId, await (typeof this.#keySecret === 'function' ? this.#keySecret() : this.#keySecret));
|
|
41
41
|
return new Translator(credentials);
|
|
42
42
|
}
|
|
43
43
|
|
package/mmtProvider.js
CHANGED
|
@@ -67,7 +67,7 @@ export class MMTProvider extends providers.ChunkedRemoteTranslationProvider {
|
|
|
67
67
|
async startTranslateChunk(args) {
|
|
68
68
|
const { sourceLang, targetLang, q, hints, contextVector, options, webhook, batchOptions } = args;
|
|
69
69
|
try {
|
|
70
|
-
const mmt = new MMTClient(await this.#apiKey, 'l10n.monster/MMT', '3.0');
|
|
70
|
+
const mmt = new MMTClient(await (typeof this.#apiKey === 'function' ? this.#apiKey() : this.#apiKey), 'l10n.monster/MMT', '3.0');
|
|
71
71
|
if (webhook) {
|
|
72
72
|
const response = await mmt.batchTranslate(webhook, sourceLang, targetLang, q, hints, contextVector, batchOptions);
|
|
73
73
|
return { enqueued: response };
|