@lokalise/polyglot-sdk 15.0.0 → 16.0.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/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/sdk/helpers/nonTranslatableContentHelper.d.ts +26 -0
- package/dist/sdk/helpers/nonTranslatableContentHelper.js +57 -0
- package/dist/sdk/helpers/nonTranslatableContentHelper.js.map +1 -0
- package/dist/sdk/helpers/nonTranslatableContentWrappers.d.ts +10 -0
- package/dist/sdk/helpers/nonTranslatableContentWrappers.js +52 -0
- package/dist/sdk/helpers/nonTranslatableContentWrappers.js.map +1 -0
- package/dist/sdk/schemas/translation/generateVariantsV1.d.ts +6 -6
- package/dist/sdk/schemas/translation/sharedSchemas.d.ts +74 -0
- package/dist/sdk/schemas/translation/sharedSchemas.js +23 -2
- package/dist/sdk/schemas/translation/sharedSchemas.js.map +1 -1
- package/dist/sdk/schemas/translation/textRewritingSchemas.d.ts +976 -1
- package/dist/sdk/schemas/translation/textRewritingSchemas.js +49 -2
- package/dist/sdk/schemas/translation/textRewritingSchemas.js.map +1 -1
- package/dist/sdk/validation/isSegmentUnderLengthLimit.d.ts +2 -1
- package/dist/sdk/validation/isSegmentUnderLengthLimit.js +6 -6
- package/dist/sdk/validation/isSegmentUnderLengthLimit.js.map +1 -1
- package/dist/sdk/validation/requestSizeLimit.d.ts +1 -1
- package/dist/sdk/validation/requestSizeLimit.js +3 -4
- package/dist/sdk/validation/requestSizeLimit.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -17,3 +17,5 @@ export * from './sdk/schemas/translation/translateAsyncSchemas';
|
|
|
17
17
|
export * from './sdk/schemas/translation/sharedSchemas';
|
|
18
18
|
export { isSegmentUnderLengthLimit, isSegmentUnderLengthLimit as isSegmentExceedingLengthLimit, } from './sdk/validation/isSegmentUnderLengthLimit';
|
|
19
19
|
export { getRequestSizeLimit, isRequestSizeUnderLimit } from './sdk/validation/requestSizeLimit';
|
|
20
|
+
export * from './sdk/helpers/nonTranslatableContentHelper';
|
|
21
|
+
export * from './sdk/helpers/nonTranslatableContentWrappers';
|
package/dist/index.js
CHANGED
|
@@ -28,4 +28,6 @@ Object.defineProperty(exports, "isSegmentExceedingLengthLimit", { enumerable: tr
|
|
|
28
28
|
var requestSizeLimit_1 = require("./sdk/validation/requestSizeLimit");
|
|
29
29
|
Object.defineProperty(exports, "getRequestSizeLimit", { enumerable: true, get: function () { return requestSizeLimit_1.getRequestSizeLimit; } });
|
|
30
30
|
Object.defineProperty(exports, "isRequestSizeUnderLimit", { enumerable: true, get: function () { return requestSizeLimit_1.isRequestSizeUnderLimit; } });
|
|
31
|
+
tslib_1.__exportStar(require("./sdk/helpers/nonTranslatableContentHelper"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./sdk/helpers/nonTranslatableContentWrappers"), exports);
|
|
31
33
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,uDAAqD;AAA5C,gHAAA,cAAc,OAAA;AACvB,4DAA0D;AAAjD,8GAAA,aAAa,OAAA;AAGtB,mFAAwD;AAExD,6EAAkD;AAClD,4EAAiD;AACjD,4FAGuD;AAFrD,uIAAA,0BAA0B,OAAA;AAC1B,mIAAA,sBAAsB,OAAA;AASxB,iEAAsE;AAA7D,qHAAA,oBAAoB,OAAA;AAC7B,4EAAiD;AACjD,6EAAkD;AAClD,+EAAoD;AACpD,uFAA4D;AAC5D,yFAA8D;AAC9D,yFAA8D;AAC9D,0FAA+D;AAC/D,kFAAuD;AAEvD,wFAGmD;AAFjD,sIAAA,yBAAyB,OAAA;AACzB,0IAAA,yBAAyB,OAAiC;AAE5D,sEAAgG;AAAvF,uHAAA,mBAAmB,OAAA;AAAE,2HAAA,uBAAuB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,uDAAqD;AAA5C,gHAAA,cAAc,OAAA;AACvB,4DAA0D;AAAjD,8GAAA,aAAa,OAAA;AAGtB,mFAAwD;AAExD,6EAAkD;AAClD,4EAAiD;AACjD,4FAGuD;AAFrD,uIAAA,0BAA0B,OAAA;AAC1B,mIAAA,sBAAsB,OAAA;AASxB,iEAAsE;AAA7D,qHAAA,oBAAoB,OAAA;AAC7B,4EAAiD;AACjD,6EAAkD;AAClD,+EAAoD;AACpD,uFAA4D;AAC5D,yFAA8D;AAC9D,yFAA8D;AAC9D,0FAA+D;AAC/D,kFAAuD;AAEvD,wFAGmD;AAFjD,sIAAA,yBAAyB,OAAA;AACzB,0IAAA,yBAAyB,OAAiC;AAE5D,sEAAgG;AAAvF,uHAAA,mBAAmB,OAAA;AAAE,2HAAA,uBAAuB,OAAA;AAErD,qFAA0D;AAC1D,uFAA4D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IntegrationEngineEnum } from '../schemas/common/commonSchemas';
|
|
2
|
+
export type TextWithNonTranslatableRegions = {
|
|
3
|
+
wrappedText: string;
|
|
4
|
+
nonTranslatableRegions: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare const NON_TRANSLATABLE_REGION_REGEX: RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* Extracts matches from a string using a regular expression
|
|
9
|
+
*/
|
|
10
|
+
export declare const extractTextWithRegexp: (text: string, regex: RegExp) => string[];
|
|
11
|
+
/**
|
|
12
|
+
* Takes a string with zero or more non-translatable regions (text wrapped within \uE101 and \uE102 characters) and
|
|
13
|
+
* returns it with regions re-wrapped into tags with an attribute indicating a position of
|
|
14
|
+
* such region. Also returns a list of detected non-translatable regions ordered in the same way.
|
|
15
|
+
*
|
|
16
|
+
* You can use that to reinsert original regions back into a translated version of such string
|
|
17
|
+
*
|
|
18
|
+
* @returns {TextWithNonTranslatableRegions} An object containing a segment with non-translatable regions wrapped into tags
|
|
19
|
+
* and an array of detected non-translatable regions for future reinsertion
|
|
20
|
+
*/
|
|
21
|
+
export declare const wrapSegmentAndExtractNonTranslatableRegions: (segment: string, integration?: IntegrationEngineEnum) => TextWithNonTranslatableRegions;
|
|
22
|
+
/**
|
|
23
|
+
* Takes a string with zero or more non-translatable regions (text wrapped within \uE101 and \uE102 characters) and
|
|
24
|
+
* returns it with regions re-wrapped into ordered XML `<lok-nt>` tags
|
|
25
|
+
*/
|
|
26
|
+
export declare const wrapNonTranslatableRegions: (segment: string, integration?: IntegrationEngineEnum) => string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapNonTranslatableRegions = exports.wrapSegmentAndExtractNonTranslatableRegions = exports.extractTextWithRegexp = exports.NON_TRANSLATABLE_REGION_REGEX = void 0;
|
|
4
|
+
const non_translatable_markup_1 = require("@lokalise/non-translatable-markup");
|
|
5
|
+
const nonTranslatableContentWrappers_1 = require("./nonTranslatableContentWrappers");
|
|
6
|
+
exports.NON_TRANSLATABLE_REGION_REGEX = new RegExp(String.raw `${non_translatable_markup_1.NON_TRANSLATABLE_START_TAG}[\s\S]*?${non_translatable_markup_1.NON_TRANSLATABLE_END_TAG}`, 'g');
|
|
7
|
+
/**
|
|
8
|
+
* Extracts matches from a string using a regular expression
|
|
9
|
+
*/
|
|
10
|
+
const extractTextWithRegexp = (text, regex) => {
|
|
11
|
+
const pieces = [];
|
|
12
|
+
const matches = text.matchAll(regex);
|
|
13
|
+
for (const match of matches) {
|
|
14
|
+
for (const [i, group] of match.entries()) {
|
|
15
|
+
if (i === 0)
|
|
16
|
+
pieces.push(group);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return pieces;
|
|
20
|
+
};
|
|
21
|
+
exports.extractTextWithRegexp = extractTextWithRegexp;
|
|
22
|
+
/**
|
|
23
|
+
* Takes a string with zero or more non-translatable regions (text wrapped within \uE101 and \uE102 characters) and
|
|
24
|
+
* returns it with regions re-wrapped into tags with an attribute indicating a position of
|
|
25
|
+
* such region. Also returns a list of detected non-translatable regions ordered in the same way.
|
|
26
|
+
*
|
|
27
|
+
* You can use that to reinsert original regions back into a translated version of such string
|
|
28
|
+
*
|
|
29
|
+
* @returns {TextWithNonTranslatableRegions} An object containing a segment with non-translatable regions wrapped into tags
|
|
30
|
+
* and an array of detected non-translatable regions for future reinsertion
|
|
31
|
+
*/
|
|
32
|
+
const wrapSegmentAndExtractNonTranslatableRegions = (segment, integration) => {
|
|
33
|
+
let wrappedText = segment;
|
|
34
|
+
const wrapperFormat = (0, nonTranslatableContentWrappers_1.getFormatByIntegration)(integration);
|
|
35
|
+
const nonTranslatableRegions = (0, exports.extractTextWithRegexp)(segment, exports.NON_TRANSLATABLE_REGION_REGEX);
|
|
36
|
+
let index = 0;
|
|
37
|
+
for (const region of nonTranslatableRegions) {
|
|
38
|
+
const replacement = nonTranslatableContentWrappers_1.WRAPPER_FORMATS[wrapperFormat].wrap(region.slice(1, -1), index);
|
|
39
|
+
wrappedText = wrappedText.replace(region, replacement);
|
|
40
|
+
index++;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
wrappedText,
|
|
44
|
+
nonTranslatableRegions,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
exports.wrapSegmentAndExtractNonTranslatableRegions = wrapSegmentAndExtractNonTranslatableRegions;
|
|
48
|
+
/**
|
|
49
|
+
* Takes a string with zero or more non-translatable regions (text wrapped within \uE101 and \uE102 characters) and
|
|
50
|
+
* returns it with regions re-wrapped into ordered XML `<lok-nt>` tags
|
|
51
|
+
*/
|
|
52
|
+
const wrapNonTranslatableRegions = (segment, integration) => {
|
|
53
|
+
const { wrappedText } = (0, exports.wrapSegmentAndExtractNonTranslatableRegions)(segment, integration);
|
|
54
|
+
return wrappedText;
|
|
55
|
+
};
|
|
56
|
+
exports.wrapNonTranslatableRegions = wrapNonTranslatableRegions;
|
|
57
|
+
//# sourceMappingURL=nonTranslatableContentHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonTranslatableContentHelper.js","sourceRoot":"","sources":["../../../src/sdk/helpers/nonTranslatableContentHelper.ts"],"names":[],"mappings":";;;AAAA,+EAG0C;AAE1C,qFAA0F;AAO7E,QAAA,6BAA6B,GAAG,IAAI,MAAM,CACrD,MAAM,CAAC,GAAG,CAAA,GAAG,oDAA0B,WAAW,kDAAwB,EAAE,EAC5E,GAAG,CACJ,CAAA;AAED;;GAEG;AACI,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAE,KAAa,EAAY,EAAE;IAC7E,MAAM,MAAM,GAAG,EAAE,CAAA;IACjB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAEpC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YACzC,IAAI,CAAC,KAAK,CAAC;gBAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACjC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAXY,QAAA,qBAAqB,yBAWjC;AAED;;;;;;;;;GASG;AACI,MAAM,2CAA2C,GAAG,CACzD,OAAe,EACf,WAAmC,EACH,EAAE;IAClC,IAAI,WAAW,GAAG,OAAO,CAAA;IACzB,MAAM,aAAa,GAAG,IAAA,uDAAsB,EAAC,WAAW,CAAC,CAAA;IACzD,MAAM,sBAAsB,GAAG,IAAA,6BAAqB,EAAC,OAAO,EAAE,qCAA6B,CAAC,CAAA;IAE5F,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,MAAM,MAAM,IAAI,sBAAsB,EAAE,CAAC;QAC5C,MAAM,WAAW,GAAG,gDAAe,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;QACnF,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;QACtD,KAAK,EAAE,CAAA;IACT,CAAC;IAED,OAAO;QACL,WAAW;QACX,sBAAsB;KACvB,CAAA;AACH,CAAC,CAAA;AAnBY,QAAA,2CAA2C,+CAmBvD;AAED;;;GAGG;AACI,MAAM,0BAA0B,GAAG,CACxC,OAAe,EACf,WAAmC,EAC3B,EAAE;IACV,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,mDAA2C,EAAC,OAAO,EAAE,WAAW,CAAC,CAAA;IAEzF,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA;AAPY,QAAA,0BAA0B,8BAOtC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IntegrationEngineEnum } from '../schemas/common/commonSchemas';
|
|
2
|
+
export declare const WRAPPER_FORMATS: Record<string, WrapperDefinition>;
|
|
3
|
+
export type WrapperDefinition = {
|
|
4
|
+
wrap: (content: string, id: number) => string;
|
|
5
|
+
regexp: RegExp;
|
|
6
|
+
cleanupRegexp: RegExp | null;
|
|
7
|
+
};
|
|
8
|
+
export type WrapperFormat = keyof typeof WRAPPER_FORMATS;
|
|
9
|
+
export declare const DEFAULT_WRAPPER_FORMAT: WrapperFormat;
|
|
10
|
+
export declare function getFormatByIntegration(integration?: IntegrationEngineEnum): WrapperFormat;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_WRAPPER_FORMAT = exports.WRAPPER_FORMATS = void 0;
|
|
4
|
+
exports.getFormatByIntegration = getFormatByIntegration;
|
|
5
|
+
const commonSchemas_1 = require("../schemas/common/commonSchemas");
|
|
6
|
+
const createWrapperMatchingRegexp = (tagWithAttributes) => {
|
|
7
|
+
const tag = tagWithAttributes.trim().split(' ').shift();
|
|
8
|
+
return new RegExp(String.raw `<${tagWithAttributes} id=\\*["'](\d+)\\*["']>([\s\S]*?)</${tag}>`, 'g');
|
|
9
|
+
};
|
|
10
|
+
const createBBWrapperMatchingRegexp = (tagWithAttributes) => {
|
|
11
|
+
const tag = tagWithAttributes.trim().split(' ').shift();
|
|
12
|
+
return new RegExp(String.raw `\[${tagWithAttributes}=(\d+)\]([\s\S]*?)\[/${tag}\]`, 'g');
|
|
13
|
+
};
|
|
14
|
+
const createCleanupRegexp = (tag) => {
|
|
15
|
+
return new RegExp(String.raw `[<\[]/?${tag}[\s\S]*?[>\]]`, 'g');
|
|
16
|
+
};
|
|
17
|
+
exports.WRAPPER_FORMATS = {
|
|
18
|
+
BBCode: {
|
|
19
|
+
wrap: (content, id) => `[nt=${id}]${content}[/nt]`,
|
|
20
|
+
regexp: createBBWrapperMatchingRegexp('nt'),
|
|
21
|
+
cleanupRegexp: createCleanupRegexp('nt'),
|
|
22
|
+
},
|
|
23
|
+
XML: {
|
|
24
|
+
wrap: (content, id) => `<lok-nt id="${id}">${content}</lok-nt>`,
|
|
25
|
+
regexp: createWrapperMatchingRegexp('lok-nt'),
|
|
26
|
+
cleanupRegexp: createCleanupRegexp('lok-nt'),
|
|
27
|
+
},
|
|
28
|
+
GOOGLE_TRANSLATE_HTML: {
|
|
29
|
+
wrap: (content, id) => `<span translate="no" id="${id}">${content}</span>`,
|
|
30
|
+
regexp: createWrapperMatchingRegexp('span translate="no"'),
|
|
31
|
+
cleanupRegexp: null,
|
|
32
|
+
},
|
|
33
|
+
MS_TRANSLATOR_HTML: {
|
|
34
|
+
wrap: (content, id) => `<div class="notranslate" id="${id}">${content}</div>`,
|
|
35
|
+
regexp: createWrapperMatchingRegexp('div class="notranslate"'),
|
|
36
|
+
cleanupRegexp: null,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
exports.DEFAULT_WRAPPER_FORMAT = 'BBCode';
|
|
40
|
+
function getFormatByIntegration(integration) {
|
|
41
|
+
switch (integration) {
|
|
42
|
+
case commonSchemas_1.IntegrationEngineEnum.GOOGLE_TRANSLATE:
|
|
43
|
+
return 'GOOGLE_TRANSLATE_HTML';
|
|
44
|
+
case commonSchemas_1.IntegrationEngineEnum.MICROSOFT_TRANSLATOR:
|
|
45
|
+
return 'MS_TRANSLATOR_HTML';
|
|
46
|
+
case commonSchemas_1.IntegrationEngineEnum.DEEPL:
|
|
47
|
+
return 'XML';
|
|
48
|
+
default:
|
|
49
|
+
return exports.DEFAULT_WRAPPER_FORMAT;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=nonTranslatableContentWrappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonTranslatableContentWrappers.js","sourceRoot":"","sources":["../../../src/sdk/helpers/nonTranslatableContentWrappers.ts"],"names":[],"mappings":";;;AAsDA,wDAWC;AAjED,mEAAuE;AAEvE,MAAM,2BAA2B,GAAG,CAAC,iBAAyB,EAAU,EAAE;IACxE,MAAM,GAAG,GAAG,iBAAiB,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAA;IACvD,OAAO,IAAI,MAAM,CACf,MAAM,CAAC,GAAG,CAAA,IAAI,iBAAiB,uCAAuC,GAAG,GAAG,EAC5E,GAAG,CACJ,CAAA;AACH,CAAC,CAAA;AAED,MAAM,6BAA6B,GAAG,CAAC,iBAAyB,EAAU,EAAE;IAC1E,MAAM,GAAG,GAAG,iBAAiB,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAA;IACvD,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAA,KAAK,iBAAiB,wBAAwB,GAAG,IAAI,EAAE,GAAG,CAAC,CAAA;AACzF,CAAC,CAAA;AAED,MAAM,mBAAm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AAC,KAAK;YAC9B,OAAO,KAAK,CAAA;QACd;YACE,OAAO,8BAAsB,CAAA;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -174,8 +174,8 @@ export declare const GENERATE_VARIANTS_V1_BODY_SCHEMA: z.ZodEffects<z.ZodEffects
|
|
|
174
174
|
}>>;
|
|
175
175
|
}, "strip", z.ZodTypeAny, {
|
|
176
176
|
sourceValue: string;
|
|
177
|
-
sourceLocale: string;
|
|
178
177
|
mode: "REPHRASE" | "SHORTEN";
|
|
178
|
+
sourceLocale: string;
|
|
179
179
|
targetLocale: string;
|
|
180
180
|
targetValue: string;
|
|
181
181
|
integration?: "Claude" | "ChatGPT-4" | "Gemini" | undefined;
|
|
@@ -209,8 +209,8 @@ export declare const GENERATE_VARIANTS_V1_BODY_SCHEMA: z.ZodEffects<z.ZodEffects
|
|
|
209
209
|
}[] | undefined;
|
|
210
210
|
}, {
|
|
211
211
|
sourceValue: string;
|
|
212
|
-
sourceLocale: string;
|
|
213
212
|
mode: string;
|
|
213
|
+
sourceLocale: string;
|
|
214
214
|
targetLocale: string;
|
|
215
215
|
targetValue: string;
|
|
216
216
|
integration?: "Claude" | "ChatGPT-4" | "Gemini" | undefined;
|
|
@@ -244,8 +244,8 @@ export declare const GENERATE_VARIANTS_V1_BODY_SCHEMA: z.ZodEffects<z.ZodEffects
|
|
|
244
244
|
}[] | undefined;
|
|
245
245
|
}>, {
|
|
246
246
|
sourceValue: string;
|
|
247
|
-
sourceLocale: string;
|
|
248
247
|
mode: "REPHRASE" | "SHORTEN";
|
|
248
|
+
sourceLocale: string;
|
|
249
249
|
targetLocale: string;
|
|
250
250
|
targetValue: string;
|
|
251
251
|
integration?: "Claude" | "ChatGPT-4" | "Gemini" | undefined;
|
|
@@ -279,8 +279,8 @@ export declare const GENERATE_VARIANTS_V1_BODY_SCHEMA: z.ZodEffects<z.ZodEffects
|
|
|
279
279
|
}[] | undefined;
|
|
280
280
|
}, {
|
|
281
281
|
sourceValue: string;
|
|
282
|
-
sourceLocale: string;
|
|
283
282
|
mode: string;
|
|
283
|
+
sourceLocale: string;
|
|
284
284
|
targetLocale: string;
|
|
285
285
|
targetValue: string;
|
|
286
286
|
integration?: "Claude" | "ChatGPT-4" | "Gemini" | undefined;
|
|
@@ -314,8 +314,8 @@ export declare const GENERATE_VARIANTS_V1_BODY_SCHEMA: z.ZodEffects<z.ZodEffects
|
|
|
314
314
|
}[] | undefined;
|
|
315
315
|
}>, {
|
|
316
316
|
sourceValue: string;
|
|
317
|
-
sourceLocale: string;
|
|
318
317
|
mode: "REPHRASE" | "SHORTEN";
|
|
318
|
+
sourceLocale: string;
|
|
319
319
|
targetLocale: string;
|
|
320
320
|
targetValue: string;
|
|
321
321
|
integration?: "Claude" | "ChatGPT-4" | "Gemini" | undefined;
|
|
@@ -349,8 +349,8 @@ export declare const GENERATE_VARIANTS_V1_BODY_SCHEMA: z.ZodEffects<z.ZodEffects
|
|
|
349
349
|
}[] | undefined;
|
|
350
350
|
}, {
|
|
351
351
|
sourceValue: string;
|
|
352
|
-
sourceLocale: string;
|
|
353
352
|
mode: string;
|
|
353
|
+
sourceLocale: string;
|
|
354
354
|
targetLocale: string;
|
|
355
355
|
targetValue: string;
|
|
356
356
|
integration?: "Claude" | "ChatGPT-4" | "Gemini" | undefined;
|
|
@@ -186,6 +186,80 @@ export declare const TRANSLATE_CONTENT_UNIT_SCHEMA: z.ZodObject<{
|
|
|
186
186
|
}>;
|
|
187
187
|
export type TranslateSegment = z.infer<typeof TRANSLATE_SEGMENT_SCHEMA>;
|
|
188
188
|
export type TranslateContentUnit = z.infer<typeof TRANSLATE_CONTENT_UNIT_SCHEMA>;
|
|
189
|
+
/**
|
|
190
|
+
* Text rewriting schemas
|
|
191
|
+
*/
|
|
192
|
+
export declare const REWRITE_SEGMENT_SCHEMA: z.ZodObject<{
|
|
193
|
+
id: z.ZodString;
|
|
194
|
+
value: z.ZodString;
|
|
195
|
+
}, "strip", z.ZodTypeAny, {
|
|
196
|
+
value: string;
|
|
197
|
+
id: string;
|
|
198
|
+
}, {
|
|
199
|
+
value: string;
|
|
200
|
+
id: string;
|
|
201
|
+
}>;
|
|
202
|
+
export declare const REWRITE_CONTENT_UNIT_SCHEMA: z.ZodObject<{
|
|
203
|
+
id: z.ZodString;
|
|
204
|
+
context: z.ZodOptional<z.ZodObject<{
|
|
205
|
+
description: z.ZodString;
|
|
206
|
+
}, "strip", z.ZodTypeAny, {
|
|
207
|
+
description: string;
|
|
208
|
+
}, {
|
|
209
|
+
description: string;
|
|
210
|
+
}>>;
|
|
211
|
+
characterLimit: z.ZodOptional<z.ZodNumber>;
|
|
212
|
+
segments: z.ZodEffects<z.ZodArray<z.ZodObject<{
|
|
213
|
+
id: z.ZodString;
|
|
214
|
+
value: z.ZodString;
|
|
215
|
+
}, "strip", z.ZodTypeAny, {
|
|
216
|
+
value: string;
|
|
217
|
+
id: string;
|
|
218
|
+
}, {
|
|
219
|
+
value: string;
|
|
220
|
+
id: string;
|
|
221
|
+
}>, "atleastone">, [{
|
|
222
|
+
value: string;
|
|
223
|
+
id: string;
|
|
224
|
+
}, ...{
|
|
225
|
+
value: string;
|
|
226
|
+
id: string;
|
|
227
|
+
}[]], [{
|
|
228
|
+
value: string;
|
|
229
|
+
id: string;
|
|
230
|
+
}, ...{
|
|
231
|
+
value: string;
|
|
232
|
+
id: string;
|
|
233
|
+
}[]]>;
|
|
234
|
+
}, "strip", z.ZodTypeAny, {
|
|
235
|
+
id: string;
|
|
236
|
+
segments: [{
|
|
237
|
+
value: string;
|
|
238
|
+
id: string;
|
|
239
|
+
}, ...{
|
|
240
|
+
value: string;
|
|
241
|
+
id: string;
|
|
242
|
+
}[]];
|
|
243
|
+
context?: {
|
|
244
|
+
description: string;
|
|
245
|
+
} | undefined;
|
|
246
|
+
characterLimit?: number | undefined;
|
|
247
|
+
}, {
|
|
248
|
+
id: string;
|
|
249
|
+
segments: [{
|
|
250
|
+
value: string;
|
|
251
|
+
id: string;
|
|
252
|
+
}, ...{
|
|
253
|
+
value: string;
|
|
254
|
+
id: string;
|
|
255
|
+
}[]];
|
|
256
|
+
context?: {
|
|
257
|
+
description: string;
|
|
258
|
+
} | undefined;
|
|
259
|
+
characterLimit?: number | undefined;
|
|
260
|
+
}>;
|
|
261
|
+
export type RewriteSegment = z.infer<typeof REWRITE_SEGMENT_SCHEMA>;
|
|
262
|
+
export type RewriteContentUnit = z.infer<typeof REWRITE_CONTENT_UNIT_SCHEMA>;
|
|
189
263
|
/**
|
|
190
264
|
* Variant generation
|
|
191
265
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HISTORY_REQUEST_SCHEMA = exports.VariantsModeEnum = exports.TRANSLATE_CONTENT_UNIT_SCHEMA = exports.TRANSLATE_SEGMENT_SCHEMA = exports.CONTENT_ID_PROP_SCHEMA = exports.SEGMENT_WARNINGS_SCHEMA = exports.SEGMENT_TRANSLATION_WARNING_SCHEMA = exports.TRANSLATION_QUALITY_WARNING_KINDS = exports.refineUniqueIds = exports.refineRequestSizeLimit = exports.refineSingleSegmentSizeLimit = exports.refineDifferentSourceAndTargetLang = void 0;
|
|
3
|
+
exports.HISTORY_REQUEST_SCHEMA = exports.VariantsModeEnum = exports.REWRITE_CONTENT_UNIT_SCHEMA = exports.REWRITE_SEGMENT_SCHEMA = exports.TRANSLATE_CONTENT_UNIT_SCHEMA = exports.TRANSLATE_SEGMENT_SCHEMA = exports.CONTENT_ID_PROP_SCHEMA = exports.SEGMENT_WARNINGS_SCHEMA = exports.SEGMENT_TRANSLATION_WARNING_SCHEMA = exports.TRANSLATION_QUALITY_WARNING_KINDS = exports.refineUniqueIds = exports.refineRequestSizeLimit = exports.refineSingleSegmentSizeLimit = exports.refineDifferentSourceAndTargetLang = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const zod_1 = tslib_1.__importDefault(require("zod"));
|
|
6
6
|
const isSegmentUnderLengthLimit_1 = require("../../validation/isSegmentUnderLengthLimit");
|
|
@@ -13,7 +13,7 @@ exports.refineDifferentSourceAndTargetLang = [
|
|
|
13
13
|
'The sourceLocale and targetLocale must be different.',
|
|
14
14
|
];
|
|
15
15
|
exports.refineSingleSegmentSizeLimit = [
|
|
16
|
-
(data) => (0, isSegmentUnderLengthLimit_1.isSegmentUnderLengthLimit)(data.value ?? data.sourceValue ?? '',
|
|
16
|
+
(data) => (0, isSegmentUnderLengthLimit_1.isSegmentUnderLengthLimit)(data.value ?? data.sourceValue ?? '', data.integration),
|
|
17
17
|
(data) => ({
|
|
18
18
|
message: `Text value is too large, max length is ${(0, requestSizeLimit_1.getRequestSizeLimit)(data.integration)} characters`,
|
|
19
19
|
}),
|
|
@@ -62,6 +62,27 @@ exports.TRANSLATE_CONTENT_UNIT_SCHEMA = zod_1.default.object({
|
|
|
62
62
|
.max(CONTENT_UNIT_SEGMENTS_MAX_LENGTH)
|
|
63
63
|
.refine(...exports.refineUniqueIds),
|
|
64
64
|
});
|
|
65
|
+
/**
|
|
66
|
+
* Text rewriting schemas
|
|
67
|
+
*/
|
|
68
|
+
exports.REWRITE_SEGMENT_SCHEMA = zod_1.default.object({
|
|
69
|
+
id: exports.CONTENT_ID_PROP_SCHEMA,
|
|
70
|
+
value: zod_1.default.string().min(1),
|
|
71
|
+
});
|
|
72
|
+
exports.REWRITE_CONTENT_UNIT_SCHEMA = zod_1.default.object({
|
|
73
|
+
id: exports.CONTENT_ID_PROP_SCHEMA,
|
|
74
|
+
context: zod_1.default
|
|
75
|
+
.object({
|
|
76
|
+
description: zod_1.default.string().min(1).max(CONTENT_UNIT_DESCRIPTION_MAX_LENGTH),
|
|
77
|
+
})
|
|
78
|
+
.optional(),
|
|
79
|
+
characterLimit: zod_1.default.number().optional(),
|
|
80
|
+
segments: zod_1.default
|
|
81
|
+
.array(exports.REWRITE_SEGMENT_SCHEMA)
|
|
82
|
+
.nonempty()
|
|
83
|
+
.max(CONTENT_UNIT_SEGMENTS_MAX_LENGTH)
|
|
84
|
+
.refine(...exports.refineUniqueIds),
|
|
85
|
+
});
|
|
65
86
|
/**
|
|
66
87
|
* Variant generation
|
|
67
88
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedSchemas.js","sourceRoot":"","sources":["../../../../src/sdk/schemas/translation/sharedSchemas.ts"],"names":[],"mappings":";;;;AAAA,sDAAmB;AAEnB,0FAAsF;AACtF,wEAAgG;AAChG,2DAAqF;AAMxE,QAAA,kCAAkC,GAAG;IAChD,CAAC,IAAoD,EAAE,EAAE;QACvD,OAAO,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,YAAY,CAAA;IAChD,CAAC;IACD,sDAAsD;CAC9C,CAAA;AAEG,QAAA,4BAA4B,GAAG;IAC1C,CAAC,IAAmF,EAAE,EAAE,CACtF,IAAA,qDAAyB,
|
|
1
|
+
{"version":3,"file":"sharedSchemas.js","sourceRoot":"","sources":["../../../../src/sdk/schemas/translation/sharedSchemas.ts"],"names":[],"mappings":";;;;AAAA,sDAAmB;AAEnB,0FAAsF;AACtF,wEAAgG;AAChG,2DAAqF;AAMxE,QAAA,kCAAkC,GAAG;IAChD,CAAC,IAAoD,EAAE,EAAE;QACvD,OAAO,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,YAAY,CAAA;IAChD,CAAC;IACD,sDAAsD;CAC9C,CAAA;AAEG,QAAA,4BAA4B,GAAG;IAC1C,CAAC,IAAmF,EAAE,EAAE,CACtF,IAAA,qDAAyB,EAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,WAAW,IAAI,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC;IACnF,CAAC,IAA6C,EAAE,EAAE,CAAC,CAAC;QAClD,OAAO,EAAE,0CAA0C,IAAA,sCAAmB,EAAC,IAAI,CAAC,WAAW,CAAC,aAAa;KACtG,CAAC;CACM,CAAA;AAEG,QAAA,sBAAsB,GAAG;IACpC,CAAC,IAA8E,EAAE,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