langsys-js-typescript 0.2.0 → 0.2.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/CHANGELOG.md +10 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +36 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -91,7 +91,18 @@ var LangsysAppAPIClass = class {
|
|
|
91
91
|
return await this.get("authorize-project/[projectid]");
|
|
92
92
|
}
|
|
93
93
|
async getTranslations(locale) {
|
|
94
|
-
return await this.get("
|
|
94
|
+
return await this.get("translations", { project_id: this.config.projectid, locale });
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Register phrases and/or content blocks via the current unified endpoint.
|
|
98
|
+
* Each item carries `type: 'phrase' | 'content_block'`. Replaces the
|
|
99
|
+
* deprecated `projects/{id}/tokens` and `projects/{id}/content-blocks` routes.
|
|
100
|
+
*/
|
|
101
|
+
async createTranslatableItems(items) {
|
|
102
|
+
return await this.post("translatable-items", {
|
|
103
|
+
project_id: this.config.projectid,
|
|
104
|
+
translatable_items: items
|
|
105
|
+
});
|
|
95
106
|
}
|
|
96
107
|
async post(path, data = {}) {
|
|
97
108
|
return await this.send("POST", path, data);
|
|
@@ -478,20 +489,23 @@ var Translations = class {
|
|
|
478
489
|
if (!this.missingTokens.length) return false;
|
|
479
490
|
this.debug.log("CREATE MISSING TOKENS", this.missingTokens);
|
|
480
491
|
try {
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
|
|
492
|
+
const phraseItems = this.missingTokens.map((tokenObj) => ({
|
|
493
|
+
type: "phrase",
|
|
494
|
+
phrase: tokenObj.token,
|
|
484
495
|
category: tokenObj.category || null
|
|
485
496
|
}));
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
497
|
+
const BATCH_SIZE = 200;
|
|
498
|
+
for (let offset = 0; offset < phraseItems.length; offset += BATCH_SIZE) {
|
|
499
|
+
const response = await LangsysAppAPI.createTranslatableItems(
|
|
500
|
+
phraseItems.slice(offset, offset + BATCH_SIZE)
|
|
501
|
+
);
|
|
502
|
+
if (!response.status) {
|
|
503
|
+
if (response.errors) {
|
|
504
|
+
this.debug.log("TOKEN UPDATE FAIL", this.missingTokens);
|
|
505
|
+
this.debug.error("Error updating project tokens", response.errors);
|
|
506
|
+
}
|
|
507
|
+
return false;
|
|
493
508
|
}
|
|
494
|
-
return false;
|
|
495
509
|
}
|
|
496
510
|
this.missingTokens.forEach((tokenObj) => {
|
|
497
511
|
const lookupCat = tokenObj.category || "__uncategorized__";
|
|
@@ -1046,10 +1060,16 @@ async function registerContentBlock(contentBlock) {
|
|
|
1046
1060
|
return { status: true };
|
|
1047
1061
|
}
|
|
1048
1062
|
try {
|
|
1049
|
-
const response = await LangsysAppAPI.
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1063
|
+
const response = await LangsysAppAPI.createTranslatableItems([
|
|
1064
|
+
{
|
|
1065
|
+
type: "content_block",
|
|
1066
|
+
custom_id: contentBlock.custom_id,
|
|
1067
|
+
category: contentBlock.category,
|
|
1068
|
+
content: contentBlock.content,
|
|
1069
|
+
label: contentBlock.label,
|
|
1070
|
+
phrases: contentBlock.tokens.map((phrase) => ({ phrase }))
|
|
1071
|
+
}
|
|
1072
|
+
]);
|
|
1053
1073
|
if (!response.status) {
|
|
1054
1074
|
logger.error("Could not save content block", response.errors);
|
|
1055
1075
|
return { status: false, errors: response.errors };
|