Commit 6a7a8121 authored by Jeff nan's avatar Jeff nan

fix

parent 04f2dc2a
...@@ -700,12 +700,14 @@ function initVueApp(savedData) { ...@@ -700,12 +700,14 @@ function initVueApp(savedData) {
// 兼容数据根可能不是数组(深度搜索) // 兼容数据根可能不是数组(深度搜索)
const subtitleList = this.extractArrayFromJson(subtitleJson, 'subtitle'); const subtitleList = this.extractArrayFromJson(subtitleJson, 'subtitle');
const translatedList = this.extractArrayFromJson(translatedJson, 'translated'); const translatedList = this.extractArrayFromJson(translatedJson, 'translated');
// 打开编辑器:只对齐「界面上」看到的时间(末词/翻译末段 → 句子 end) // 打开编辑器:只对齐「界面上」看到的时间
// start: 首词/翻译首段 → 句子 start;end: 末词/翻译末段 → 句子 end
// 真正写回文件要等「覆盖上传并重新生成」 // 真正写回文件要等「覆盖上传并重新生成」
this.calibrateSubtitleWordEndTimes(subtitleList); this.calibrateSubtitleWordEndTimes(subtitleList);
this.subtitleEditor.subtitleList = subtitleList || []; this.subtitleEditor.subtitleList = subtitleList || [];
this.subtitleEditor.translatedList = translatedList || []; this.subtitleEditor.translatedList = translatedList || [];
this.subtitleEditor.mergedList = this.buildMergedList(this.subtitleEditor.subtitleList, this.subtitleEditor.translatedList); this.subtitleEditor.mergedList = this.buildMergedList(this.subtitleEditor.subtitleList, this.subtitleEditor.translatedList);
this.alignEditorViewStartTimes(this.subtitleEditor.mergedList);
this.alignEditorViewEndTimes(this.subtitleEditor.mergedList); this.alignEditorViewEndTimes(this.subtitleEditor.mergedList);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
...@@ -926,10 +928,9 @@ function initVueApp(savedData) { ...@@ -926,10 +928,9 @@ function initVueApp(savedData) {
const display = this.formatTime(total); const display = this.formatTime(total);
if (d.type === 'sentence-start') { if (d.type === 'sentence-start') {
// 句子 start ↔ 首词 start ↔ 翻译首段 start 保持一致
item.start = display; item.start = display;
if (words[0]) { this.syncSentenceStartToFirstSegments(item, total);
this.$set(words[0], 'start', this.serializeTimeByFormat(total, this.timeWriteFormat(words[0])));
}
} else if (d.type === 'sentence-end') { } else if (d.type === 'sentence-end') {
// 句子 end ↔ 末词 end ↔ 翻译末段 end 保持一致 // 句子 end ↔ 末词 end ↔ 翻译末段 end 保持一致
item.end = display; item.end = display;
...@@ -941,7 +942,11 @@ function initVueApp(savedData) { ...@@ -941,7 +942,11 @@ function initVueApp(savedData) {
return; return;
} }
this.$set(word, 'start', this.serializeTimeByFormat(total, this.timeWriteFormat(word))); this.$set(word, 'start', this.serializeTimeByFormat(total, this.timeWriteFormat(word)));
if (d.wordIndex === 0) item.start = display; // 改的是第一个单词:同步句子 start + 翻译首段 start
if (d.wordIndex === 0) {
item.start = display;
this.syncSentenceStartToFirstSegments(item, total, { skipWords: true });
}
} else if (d.type === 'word-end') { } else if (d.type === 'word-end') {
const word = words[d.wordIndex]; const word = words[d.wordIndex];
if (!word) { if (!word) {
...@@ -963,6 +968,29 @@ function initVueApp(savedData) { ...@@ -963,6 +968,29 @@ function initVueApp(savedData) {
this.$message.success('时间已更新'); this.$message.success('时间已更新');
}, },
// 编辑过程中:句子 start 同步到界面上的首词 / 翻译首段
syncSentenceStartToFirstSegments(item, startSec, options = {}) {
if (!item || isNaN(startSec)) return;
const skipWords = !!(options && options.skipWords);
const skipTranslated = !!(options && options.skipTranslated);
const words = Array.isArray(item.sWordsRef) ? item.sWordsRef : [];
if (!skipWords && words.length) {
const first = words[0];
if (first) {
this.$set(first, 'start', this.serializeTimeByFormat(startSec, this.timeWriteFormat(first)));
}
}
if (!skipTranslated) {
const tSegs = Array.isArray(item.tItemsRef) ? item.tItemsRef : [];
if (tSegs.length) {
const firstT = tSegs[0];
if (firstT) {
this.$set(firstT, 'start', this.serializeTimeByFormat(startSec, this.timeWriteFormat(firstT)));
}
}
}
},
// 编辑过程中:句子 end 同步到界面上的末词 / 翻译末段 // 编辑过程中:句子 end 同步到界面上的末词 / 翻译末段
syncSentenceEndToLastSegments(item, endSec, options = {}) { syncSentenceEndToLastSegments(item, endSec, options = {}) {
if (!item || isNaN(endSec)) return; if (!item || isNaN(endSec)) return;
...@@ -986,6 +1014,36 @@ function initVueApp(savedData) { ...@@ -986,6 +1014,36 @@ function initVueApp(savedData) {
} }
}, },
// 打开编辑器:按界面句子 start,对齐原文首词 / 翻译首段(仅编辑视图,不落盘)
alignEditorViewStartTimes(mergedList) {
let fixed = 0;
(mergedList || []).forEach((item) => {
if (!item) return;
const startSec = this.parseTimeToSeconds(item.start);
if (isNaN(startSec)) return;
let changed = false;
const words = Array.isArray(item.sWordsRef) ? item.sWordsRef : [];
if (words.length) {
const first = words[0];
const wordStartSec = this.parseTimeToSeconds(first && first.start);
if (isNaN(wordStartSec) || Math.abs(wordStartSec - startSec) >= 0.001) changed = true;
}
const tSegs = Array.isArray(item.tItemsRef) ? item.tItemsRef : [];
if (tSegs.length) {
const firstT = tSegs[0];
const tStartSec = this.parseTimeToSeconds(firstT && firstT.start);
if (isNaN(tStartSec) || Math.abs(tStartSec - startSec) >= 0.001) changed = true;
}
if (!changed) return;
this.syncSentenceStartToFirstSegments(item, startSec);
fixed += 1;
});
if (fixed > 0) {
console.info(`[编辑视图] 已按句子 start 对齐 ${fixed} 句的首词/翻译首段`);
}
return fixed;
},
// 打开编辑器:按界面句子 end,对齐原文末词 / 翻译末段(仅编辑视图,不落盘) // 打开编辑器:按界面句子 end,对齐原文末词 / 翻译末段(仅编辑视图,不落盘)
alignEditorViewEndTimes(mergedList) { alignEditorViewEndTimes(mergedList) {
let fixed = 0; let fixed = 0;
...@@ -1417,14 +1475,28 @@ function initVueApp(savedData) { ...@@ -1417,14 +1475,28 @@ function initVueApp(savedData) {
const sWords = Array.isArray(m.sWordsRef) ? m.sWordsRef.slice() : []; const sWords = Array.isArray(m.sWordsRef) ? m.sWordsRef.slice() : [];
const tSegs = Array.isArray(m.tItemsRef) ? m.tItemsRef.slice() : []; const tSegs = Array.isArray(m.tItemsRef) ? m.tItemsRef.slice() : [];
// 以界面句子时间为准;保存时强制末词/翻译末段与之对齐 // 以界面句子时间为准;保存时强制首/末词、翻译首/末段与之对齐
let sStartSec = this.parseTimeToSeconds(sWords.length ? sWords[0].start : m.start); let sStartSec = this.parseTimeToSeconds(m.start);
if (isNaN(sStartSec) && sWords.length) {
sStartSec = this.parseTimeToSeconds(sWords[0].start);
}
let sEndSec = this.parseTimeToSeconds(m.end); let sEndSec = this.parseTimeToSeconds(m.end);
if (isNaN(sEndSec) && sWords.length) { if (isNaN(sEndSec) && sWords.length) {
sEndSec = this.parseTimeToSeconds(sWords[sWords.length - 1].end); sEndSec = this.parseTimeToSeconds(sWords[sWords.length - 1].end);
} }
if (isNaN(sStartSec) && !isNaN(this.parseTimeToSeconds(m.start))) { if (!isNaN(sStartSec)) {
sStartSec = this.parseTimeToSeconds(m.start); if (sWords.length) {
const first = sWords[0];
sWords[0] = Object.assign({}, first, {
start: this.serializeTimeByFormat(sStartSec, this.timeWriteFormat(first)),
});
}
if (tSegs.length) {
const firstT = tSegs[0];
tSegs[0] = Object.assign({}, firstT, {
start: this.serializeTimeByFormat(sStartSec, this.timeWriteFormat(firstT)),
});
}
} }
if (!isNaN(sEndSec)) { if (!isNaN(sEndSec)) {
if (sWords.length) { if (sWords.length) {
...@@ -1450,9 +1522,8 @@ function initVueApp(savedData) { ...@@ -1450,9 +1522,8 @@ function initVueApp(savedData) {
text: this.buildSentenceFromWords(sWords), text: this.buildSentenceFromWords(sWords),
}); });
let tStartSec = this.parseTimeToSeconds(tSegs.length ? tSegs[0].start : sStartSec); // 翻译条目 start/end 与句子 start/end 实际对齐
if (isNaN(tStartSec)) tStartSec = sStartSec; const tStartSec = !isNaN(sStartSec) ? sStartSec : this.parseTimeToSeconds(tSegs.length ? tSegs[0].start : sStartSec);
// 翻译条目 end 与句子 end 实际对齐(同一时间)
const tEndSec = !isNaN(sEndSec) ? sEndSec : this.parseTimeToSeconds(tSegs.length ? tSegs[tSegs.length - 1].end : sEndSec); const tEndSec = !isNaN(sEndSec) ? sEndSec : this.parseTimeToSeconds(tSegs.length ? tSegs[tSegs.length - 1].end : sEndSec);
const tStartOut = this.serializeTimeByFormat(tStartSec, tFmt); const tStartOut = this.serializeTimeByFormat(tStartSec, tFmt);
const tEndOut = this.serializeTimeByFormat(tEndSec, tFmt); const tEndOut = this.serializeTimeByFormat(tEndSec, tFmt);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment