@diplodoc/cli 4.6.3 → 4.6.5
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/build/app.client.css +65 -53
- package/build/app.client.js +1 -1
- package/build/index.js +60 -30
- package/build/index.js.map +3 -3
- package/package.json +14 -25
- package/src/cmd/translate/index.ts +77 -34
- package/src/steps/publishFilesToS3.ts +0 -51
package/build/index.js
CHANGED
|
@@ -3905,7 +3905,8 @@ var translate = {
|
|
|
3905
3905
|
};
|
|
3906
3906
|
var MD_GLOB3 = "**/*.md";
|
|
3907
3907
|
var REQUESTS_LIMIT = 20;
|
|
3908
|
-
var
|
|
3908
|
+
var BYTES_LIMIT = 1e4;
|
|
3909
|
+
var RETRY_LIMIT = 3;
|
|
3909
3910
|
var MTRANS_LOCALE = "MTRANS";
|
|
3910
3911
|
function builder6(argv) {
|
|
3911
3912
|
return argv.option("source-language", {
|
|
@@ -3986,6 +3987,20 @@ function translator(params) {
|
|
|
3986
3987
|
} = params;
|
|
3987
3988
|
const session = new import_session.Session({ oauthToken });
|
|
3988
3989
|
const client3 = session.client(import_service_clients.TranslationServiceClient);
|
|
3990
|
+
const request = (texts) => () => client3.translate(
|
|
3991
|
+
import_translation_service.TranslateRequest.fromPartial({
|
|
3992
|
+
texts,
|
|
3993
|
+
folderId,
|
|
3994
|
+
sourceLanguageCode: sourceLanguage,
|
|
3995
|
+
targetLanguageCode: targetLanguage,
|
|
3996
|
+
glossaryConfig: {
|
|
3997
|
+
glossaryData: {
|
|
3998
|
+
glossaryPairs: yandexCloudTranslateGlossaryPairs
|
|
3999
|
+
}
|
|
4000
|
+
},
|
|
4001
|
+
format: import_translation_service.TranslateRequest_Format.PLAIN_TEXT
|
|
4002
|
+
})
|
|
4003
|
+
).then((results) => results.translations.map(({ text }) => text));
|
|
3989
4004
|
return (mdPath) => __async(this, null, function* () {
|
|
3990
4005
|
try {
|
|
3991
4006
|
logger.info(mdPath, "translating");
|
|
@@ -4004,40 +4019,44 @@ function translator(params) {
|
|
|
4004
4019
|
skeletonPath: ""
|
|
4005
4020
|
});
|
|
4006
4021
|
const texts = parseSourcesFromXLIFF(xlf);
|
|
4007
|
-
const
|
|
4008
|
-
texts
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4022
|
+
const parts = yield Promise.all(
|
|
4023
|
+
texts.reduce(
|
|
4024
|
+
({
|
|
4025
|
+
promises,
|
|
4026
|
+
buffer,
|
|
4027
|
+
bufferSize
|
|
4028
|
+
}, text, index) => {
|
|
4029
|
+
if (text.length >= BYTES_LIMIT) {
|
|
4030
|
+
logger.warn(
|
|
4031
|
+
mdPath,
|
|
4032
|
+
"Skip document part for translation. Part is too big."
|
|
4033
|
+
);
|
|
4034
|
+
promises.push(Promise.resolve([text]));
|
|
4035
|
+
return { promises, buffer, bufferSize };
|
|
4036
|
+
}
|
|
4037
|
+
if (bufferSize + text.length > BYTES_LIMIT || index === texts.length - 1) {
|
|
4038
|
+
promises.push(backoff(request(buffer)));
|
|
4039
|
+
buffer = [];
|
|
4040
|
+
bufferSize = 0;
|
|
4041
|
+
}
|
|
4042
|
+
buffer.push(text);
|
|
4043
|
+
bufferSize += text.length;
|
|
4044
|
+
return { promises, buffer, bufferSize };
|
|
4045
|
+
},
|
|
4046
|
+
{
|
|
4047
|
+
promises: [],
|
|
4048
|
+
buffer: [],
|
|
4049
|
+
bufferSize: 0
|
|
4024
4050
|
}
|
|
4025
|
-
|
|
4026
|
-
(0, import_async5.asyncify)(
|
|
4027
|
-
() => __async(this, null, function* () {
|
|
4028
|
-
return yield client3.translate(machineTranslateParams).then(
|
|
4029
|
-
(results) => results.translations.map(({ text }) => text)
|
|
4030
|
-
);
|
|
4031
|
-
})
|
|
4032
|
-
)
|
|
4051
|
+
).promises
|
|
4033
4052
|
);
|
|
4034
|
-
const
|
|
4053
|
+
const translations = [].concat(...parts);
|
|
4054
|
+
const translatedXLIFF = createXLIFFDocument({
|
|
4035
4055
|
sourceLanguage: sourceLanguage + "-" + MTRANS_LOCALE,
|
|
4036
4056
|
targetLanguage: targetLanguage + "-" + MTRANS_LOCALE,
|
|
4037
4057
|
sources: texts,
|
|
4038
4058
|
targets: translations
|
|
4039
|
-
};
|
|
4040
|
-
const translatedXLIFF = createXLIFFDocument(createXLIFFDocumentParams);
|
|
4059
|
+
});
|
|
4041
4060
|
const composed = yield import_markdown_translation3.default.compose({
|
|
4042
4061
|
xlf: translatedXLIFF,
|
|
4043
4062
|
skeleton
|
|
@@ -4053,6 +4072,17 @@ function translator(params) {
|
|
|
4053
4072
|
}
|
|
4054
4073
|
});
|
|
4055
4074
|
}
|
|
4075
|
+
function backoff(action) {
|
|
4076
|
+
return (0, import_async5.retry)(
|
|
4077
|
+
{
|
|
4078
|
+
times: RETRY_LIMIT,
|
|
4079
|
+
interval: (count) => {
|
|
4080
|
+
return (1 << count) * 1e3;
|
|
4081
|
+
}
|
|
4082
|
+
},
|
|
4083
|
+
(0, import_async5.asyncify)(action)
|
|
4084
|
+
);
|
|
4085
|
+
}
|
|
4056
4086
|
function parseSourcesFromXLIFF(xliff2) {
|
|
4057
4087
|
var _a, _b, _c, _d;
|
|
4058
4088
|
const parser = new import_fast_xml_parser.XMLParser();
|
|
@@ -4095,7 +4125,7 @@ import_yargs.default.command(build).command(publish).command(xliff).command(tran
|
|
|
4095
4125
|
default: false,
|
|
4096
4126
|
describe: "Run in quiet mode. Don't write logs to stdout",
|
|
4097
4127
|
type: "boolean"
|
|
4098
|
-
}).group(["config", "strict", "quiet", "help", "version"], "Common options:").version(true ? "4.6.
|
|
4128
|
+
}).group(["config", "strict", "quiet", "help", "version"], "Common options:").version(true ? "4.6.5" : "").help().parse((0, import_helpers.hideBin)(process.argv), {}, (err, { strict }, output) => {
|
|
4099
4129
|
console.timeEnd(MAIN_TIMER_ID);
|
|
4100
4130
|
if (err) {
|
|
4101
4131
|
console.error(err);
|