fix: subtitle

This commit is contained in:
Gabe
2025-10-10 13:49:04 +08:00
parent 769a4f00aa
commit 251e57ec61
7 changed files with 139 additions and 143 deletions

View File

@@ -1,4 +1,5 @@
import { logger } from "../libs/log.js";
import { truncateWords } from "../libs/utils.js";
/**
* @class BilingualSubtitleManager
@@ -163,11 +164,11 @@ export class BilingualSubtitleManager {
if (subtitle) {
const p1 = document.createElement("p");
p1.style.cssText = this.#setting.originStyle;
p1.textContent = subtitle.text;
p1.textContent = truncateWords(subtitle.text);
const p2 = document.createElement("p");
p2.style.cssText = this.#setting.originStyle;
p2.textContent = subtitle.translation || "...";
p2.textContent = truncateWords(subtitle.translation) || "...";
if (this.#setting.isBilingual) {
this.#captionWindowEl.replaceChildren(p1, p2);
@@ -207,16 +208,16 @@ export class BilingualSubtitleManager {
async #translateAndStore(subtitle) {
subtitle.isTranslating = true;
try {
const { toLang, apiSetting } = this.#setting;
const { fromLang, toLang, apiSetting } = this.#setting;
const [translatedText] = await this.#translationService({
text: subtitle.text,
fromLang: "en",
fromLang,
toLang,
apiSetting,
});
subtitle.translation = translatedText;
} catch (error) {
logger.error("Translation failed for:", subtitle.text, error);
logger.info("Translation failed for:", subtitle.text, error);
subtitle.translation = "[Translation failed]";
} finally {
subtitle.isTranslating = false;