fix: html trans 500

This commit is contained in:
xxnuo
2026-01-18 20:06:08 +08:00
parent 99b97d5eca
commit efa11e2497
2 changed files with 31 additions and 1 deletions

View File

@@ -129,7 +129,7 @@ export class TranslationEngine {
let translation: string;
try {
if (cleanText.length > this.maxSentenceLength) {
if (cleanText.length > this.maxSentenceLength && !effectiveOptions.html) {
translation = this._translateLongText(cleanText, effectiveOptions);
} else {
translation = this._translateInternal(cleanText, effectiveOptions);

30
tests/engine-html.test.ts Normal file
View File

@@ -0,0 +1,30 @@
import { describe, expect, test } from 'bun:test';
import { TranslationEngine } from '@/core/engine';
describe('TranslationEngine HTML handling', () => {
test('long html skips plain text splitting', () => {
const engine = new TranslationEngine() as any;
engine.isReady = true;
let usedLongText = false;
let usedInternal = false;
engine._translateLongText = () => {
usedLongText = true;
return 'split';
};
engine._translateInternal = (text: string, options: { html?: boolean }) => {
usedInternal = true;
expect(options.html).toBe(true);
return text;
};
const html = `<p dir="auto">${'Hello world '.repeat(80)}<a href="https://example.com">example</a></p>`;
const result = engine.translate(html, { html: true });
expect(result).toBe(html);
expect(usedInternal).toBe(true);
expect(usedLongText).toBe(false);
});
});