mirror of
https://github.com/xxnuo/MTranServer.git
synced 2026-05-06 21:51:13 +08:00
fix: html trans 500
This commit is contained in:
@@ -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
30
tests/engine-html.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user