@lokalise/polyglot-sdk 15.1.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.js +1 -1
- package/dist/sdk/schemas/translation/sharedSchemas.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/hel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E,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,mBAAmB,GAAG,CAAC,GAAW,EAAU,EAAE;IAClD,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAA,UAAU,GAAG,eAAe,EAAE,GAAG,CAAC,CAAA;AAChE,CAAC,CAAA;AAEY,QAAA,eAAe,GAAsC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ffects
|
|
|
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;
|
|
@@ -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
|
}),
|
|
@@ -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,2DAA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AgB,CAAC,CAAC;SACpC,QAAQ,CAAC,iCAAiC,CAAC;CAC/C,CAAC,CAAA"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { IntegrationEngineEnum } from '../schemas/common/commonSchemas';
|
|
2
|
+
export declare const isSegmentUnderLengthLimit: (value: string, integration?: IntegrationEngineEnum) => boolean;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isSegmentUnderLengthLimit = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const isSegmentUnderLengthLimit = (value,
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
return length <= limit;
|
|
4
|
+
const nonTranslatableContentHelper_1 = require("../helpers/nonTranslatableContentHelper");
|
|
5
|
+
const requestSizeLimit_1 = require("./requestSizeLimit");
|
|
6
|
+
const isSegmentUnderLengthLimit = (value, integration) => {
|
|
7
|
+
const limit = (0, requestSizeLimit_1.getRequestSizeLimit)(integration);
|
|
8
|
+
const ntcWrapped = (0, nonTranslatableContentHelper_1.wrapNonTranslatableRegions)(value, integration);
|
|
9
|
+
return ntcWrapped.length <= limit;
|
|
10
10
|
};
|
|
11
11
|
exports.isSegmentUnderLengthLimit = isSegmentUnderLengthLimit;
|
|
12
12
|
//# sourceMappingURL=isSegmentUnderLengthLimit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isSegmentUnderLengthLimit.js","sourceRoot":"","sources":["../../../src/sdk/validation/isSegmentUnderLengthLimit.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"isSegmentUnderLengthLimit.js","sourceRoot":"","sources":["../../../src/sdk/validation/isSegmentUnderLengthLimit.ts"],"names":[],"mappings":";;;AAAA,0FAAoF;AAEpF,yDAAwD;AAEjD,MAAM,yBAAyB,GAAG,CACvC,KAAa,EACb,WAAmC,EAC1B,EAAE;IACX,MAAM,KAAK,GAAG,IAAA,sCAAmB,EAAC,WAAW,CAAC,CAAA;IAC9C,MAAM,UAAU,GAAG,IAAA,yDAA0B,EAAC,KAAK,EAAE,WAAW,CAAC,CAAA;IACjE,OAAO,UAAU,CAAC,MAAM,IAAI,KAAK,CAAA;AACnC,CAAC,CAAA;AAPY,QAAA,yBAAyB,6BAOrC"}
|
|
@@ -3,7 +3,7 @@ import type { ContentUnitLike } from '../schemas/translation/sharedSchemas';
|
|
|
3
3
|
/**
|
|
4
4
|
* Checks if every segment in the content unit is under the size limit.
|
|
5
5
|
*/
|
|
6
|
-
export declare const isContentUnitSizeUnderLimit: (segments: ContentUnitLike["segments"],
|
|
6
|
+
export declare const isContentUnitSizeUnderLimit: (segments: ContentUnitLike["segments"], forcedIntegration?: IntegrationEngineEnum) => boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Checks if every content unit in the request is under the size limit.
|
|
9
9
|
*/
|
|
@@ -6,16 +6,15 @@ const isSegmentUnderLengthLimit_1 = require("./isSegmentUnderLengthLimit");
|
|
|
6
6
|
/**
|
|
7
7
|
* Checks if every segment in the content unit is under the size limit.
|
|
8
8
|
*/
|
|
9
|
-
const isContentUnitSizeUnderLimit = (segments,
|
|
10
|
-
return segments.every(({ value }) => (0, isSegmentUnderLengthLimit_1.isSegmentUnderLengthLimit)(value,
|
|
9
|
+
const isContentUnitSizeUnderLimit = (segments, forcedIntegration) => {
|
|
10
|
+
return segments.every(({ value }) => (0, isSegmentUnderLengthLimit_1.isSegmentUnderLengthLimit)(value, forcedIntegration));
|
|
11
11
|
};
|
|
12
12
|
exports.isContentUnitSizeUnderLimit = isContentUnitSizeUnderLimit;
|
|
13
13
|
/**
|
|
14
14
|
* Checks if every content unit in the request is under the size limit.
|
|
15
15
|
*/
|
|
16
16
|
const isRequestSizeUnderLimit = (contentUnits, forcedIntegration) => {
|
|
17
|
-
|
|
18
|
-
return contentUnits.every((contentUnit) => (0, exports.isContentUnitSizeUnderLimit)(contentUnit.segments, limit));
|
|
17
|
+
return contentUnits.every((contentUnit) => (0, exports.isContentUnitSizeUnderLimit)(contentUnit.segments, forcedIntegration));
|
|
19
18
|
};
|
|
20
19
|
exports.isRequestSizeUnderLimit = isRequestSizeUnderLimit;
|
|
21
20
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestSizeLimit.js","sourceRoot":"","sources":["../../../src/sdk/validation/requestSizeLimit.ts"],"names":[],"mappings":";;;AAAA,mEAIwC;AAExC,2EAAuE;AAEvE;;GAEG;AACI,MAAM,2BAA2B,GAAG,CACzC,QAAqC,EACrC,
|
|
1
|
+
{"version":3,"file":"requestSizeLimit.js","sourceRoot":"","sources":["../../../src/sdk/validation/requestSizeLimit.ts"],"names":[],"mappings":";;;AAAA,mEAIwC;AAExC,2EAAuE;AAEvE;;GAEG;AACI,MAAM,2BAA2B,GAAG,CACzC,QAAqC,EACrC,iBAAyC,EAChC,EAAE;IACX,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,IAAA,qDAAyB,EAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAA;AAC3F,CAAC,CAAA;AALY,QAAA,2BAA2B,+BAKvC;AAED;;GAEG;AACI,MAAM,uBAAuB,GAAG,CACrC,YAA+B,EAC/B,iBAAyC,EAChC,EAAE;IACX,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,EAAE,CACxC,IAAA,mCAA2B,EAAC,WAAW,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CACrE,CAAA;AACH,CAAC,CAAA;AAPY,QAAA,uBAAuB,2BAOnC;AAED;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,WAAmC,EAAU,EAAE;IACjF,IAAI,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,sCAAsB,EAAE,WAAW,CAAC,EAAE,CAAC;QACtE,OAAO,sCAAsB,CAAC,WAAW,CAAC,CAAA;IAC5C,CAAC;IAED,OAAO,gDAAgC,CAAA;AACzC,CAAC,CAAA;AANY,QAAA,mBAAmB,uBAM/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lokalise/polyglot-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Lokalise",
|
|
6
6
|
"url": "https://lokalise.com/"
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"mockttp": "^3.15.5",
|
|
57
57
|
"shx": "^0.3.4",
|
|
58
58
|
"ts-deepmerge": "^7.0.1",
|
|
59
|
-
"typescript": "5.7.
|
|
59
|
+
"typescript": "5.7.3",
|
|
60
60
|
"vitest": "^2.0.4"
|
|
61
61
|
}
|
|
62
62
|
}
|