gptrans 2.0.0 ā 2.0.2
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/index.js +14 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -215,15 +215,15 @@ class GPTrans {
|
|
|
215
215
|
const textsToTranslate = batch.map(([_, text]) => text).join(`\n${this.divider}\n`);
|
|
216
216
|
try {
|
|
217
217
|
const translations = await this._translate(textsToTranslate, batch, batchReferences, this.preloadBaseLanguage);
|
|
218
|
-
|
|
218
|
+
|
|
219
219
|
// Try different split strategies to be more robust
|
|
220
220
|
let translatedTexts = translations.split(`\n${this.divider}\n`);
|
|
221
|
-
|
|
221
|
+
|
|
222
222
|
// If split doesn't match batch size, try alternative separators
|
|
223
223
|
if (translatedTexts.length !== batch.length) {
|
|
224
224
|
// Try without newlines around divider
|
|
225
225
|
translatedTexts = translations.split(this.divider);
|
|
226
|
-
|
|
226
|
+
|
|
227
227
|
// If still doesn't match, try with just newline
|
|
228
228
|
if (translatedTexts.length !== batch.length) {
|
|
229
229
|
translatedTexts = translations.split(/\n{2,}/); // Split by multiple newlines
|
|
@@ -231,7 +231,7 @@ class GPTrans {
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
const contextHash = this._hash(context);
|
|
234
|
-
|
|
234
|
+
|
|
235
235
|
// Validate we have the right number of translations
|
|
236
236
|
if (translatedTexts.length !== batch.length) {
|
|
237
237
|
console.error(`ā Translation count mismatch:`);
|
|
@@ -239,7 +239,7 @@ class GPTrans {
|
|
|
239
239
|
console.error(` Received: ${translatedTexts.length} translations`);
|
|
240
240
|
console.error(` Batch keys: ${batch.map(([key]) => key).join(', ')}`);
|
|
241
241
|
console.error(`\nš Full response from model:\n${translations}\n`);
|
|
242
|
-
|
|
242
|
+
|
|
243
243
|
// Try to save what we can
|
|
244
244
|
const minLength = Math.min(translatedTexts.length, batch.length);
|
|
245
245
|
for (let i = 0; i < minLength; i++) {
|
|
@@ -333,7 +333,7 @@ class GPTrans {
|
|
|
333
333
|
'{FROM_DENONYM}': fromReplace.FROM_DENONYM,
|
|
334
334
|
});
|
|
335
335
|
|
|
336
|
-
return model.block();
|
|
336
|
+
return await model.block({ addSystemExtra: false });
|
|
337
337
|
|
|
338
338
|
} finally {
|
|
339
339
|
// Always release the lock
|
|
@@ -407,14 +407,14 @@ class GPTrans {
|
|
|
407
407
|
|
|
408
408
|
// Track which keys need translation
|
|
409
409
|
const keysNeedingTranslation = [];
|
|
410
|
-
|
|
410
|
+
|
|
411
411
|
for (const [context, pairs] of this.dbFrom.entries()) {
|
|
412
412
|
// Skip the _context metadata
|
|
413
413
|
if (context === '_context') continue;
|
|
414
|
-
|
|
414
|
+
|
|
415
415
|
this.setContext(context);
|
|
416
416
|
const contextHash = this._hash(context);
|
|
417
|
-
|
|
417
|
+
|
|
418
418
|
for (const [key, text] of Object.entries(pairs)) {
|
|
419
419
|
// Check if translation already exists
|
|
420
420
|
if (!this.dbTarget.get(contextHash, key)) {
|
|
@@ -438,7 +438,7 @@ class GPTrans {
|
|
|
438
438
|
const checkInterval = setInterval(() => {
|
|
439
439
|
// Check if there are still pending translations or batch being processed
|
|
440
440
|
const hasPending = this.pendingTranslations.size > 0 || this.isProcessingBatch;
|
|
441
|
-
|
|
441
|
+
|
|
442
442
|
// Check if all needed translations are now complete
|
|
443
443
|
let allTranslated = true;
|
|
444
444
|
for (const { contextHash, key } of keysNeedingTranslation) {
|
|
@@ -447,7 +447,7 @@ class GPTrans {
|
|
|
447
447
|
break;
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
|
-
|
|
450
|
+
|
|
451
451
|
if (allTranslated && !hasPending) {
|
|
452
452
|
clearInterval(checkInterval);
|
|
453
453
|
resolve();
|
|
@@ -610,7 +610,7 @@ class GPTrans {
|
|
|
610
610
|
'{FROM_DENONYM}': this.replaceFrom.FROM_DENONYM,
|
|
611
611
|
});
|
|
612
612
|
|
|
613
|
-
return await model.block();
|
|
613
|
+
return await model.block({ addSystemExtra: false });
|
|
614
614
|
|
|
615
615
|
} finally {
|
|
616
616
|
releaseLock();
|
|
@@ -696,7 +696,7 @@ class GPTrans {
|
|
|
696
696
|
// Save translated image - preserve original file format
|
|
697
697
|
const filename = path.basename(targetPath, path.extname(targetPath));
|
|
698
698
|
const formatOptions = generator.getReferenceMetadata();
|
|
699
|
-
|
|
699
|
+
|
|
700
700
|
// Apply default quality settings for JPEG images
|
|
701
701
|
if (formatOptions && (formatOptions.format === 'jpeg' || formatOptions.format === 'jpg')) {
|
|
702
702
|
// Apply custom quality if specified, otherwise use defaults
|
|
@@ -705,7 +705,7 @@ class GPTrans {
|
|
|
705
705
|
formatOptions.chromaSubsampling = '4:4:4'; // Better color quality
|
|
706
706
|
formatOptions.optimiseCoding = true; // Lossless size reduction
|
|
707
707
|
}
|
|
708
|
-
|
|
708
|
+
|
|
709
709
|
await generator.save({ directory: targetDir, filename, formatOptions });
|
|
710
710
|
} else {
|
|
711
711
|
throw new Error('No translated image was generated');
|