Skip to content

Commit 9370f22

Browse files
committed
fix: deletion of translation
1 parent a0b2be4 commit 9370f22

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

packages/studio-web/src/app/shared/download/download.service.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,22 @@ Please host all assets on your server, include the font and package imports defi
8181
(t_node) => t_node.id,
8282
),
8383
);
84-
//update current translation text
84+
//update current translation text or remove delete
8585
doc
8686
.querySelectorAll("s.translation, s.sentence__translation")
8787
.forEach((sentence: Element) => {
88-
if (
89-
sentence.id in translations &&
90-
translation_node_ids.has(sentence.id)
91-
) {
92-
sentence.textContent = translations[sentence.id];
88+
const sentenceID: string = sentence.hasAttribute("sentence-id")
89+
? (sentence.getAttribute("sentence-id") as string)
90+
: sentence.id;
91+
if (sentenceID in translations) {
92+
sentence.textContent = translations[sentenceID];
93+
} else {
94+
//remove deleted translations
95+
sentence.remove();
9396
}
9497
});
98+
// Add new translations
9599
sentence_nodes.forEach((sentence: Element) => {
96-
// Add a translation
97100
if (
98101
sentence.id in translations &&
99102
!translation_node_ids.has(sentence.id)
@@ -111,17 +114,6 @@ Please host all assets on your server, include the font and package imports defi
111114
newSentence.append(translations[sentence.id]);
112115
sentence.insertAdjacentElement("afterend", newSentence);
113116
}
114-
// Remove a translation
115-
if (
116-
sentence.id in translations &&
117-
translations[sentence.id] === null &&
118-
translation_node_ids.has(sentence.id)
119-
) {
120-
let elementToRemove = doc.querySelector(
121-
`#${sentence.id}.sentence__translation`,
122-
);
123-
elementToRemove?.remove();
124-
}
125117
});
126118

127119
return true;

packages/web-component/src/components/read-along-component/read-along.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,11 +1087,10 @@ export class ReadAlongComponent {
10871087
.forEach((sentences) => {
10881088
if (sentences.length) {
10891089
sentences.forEach((sentence) => {
1090-
let translation: { [key: string]: string } = {};
10911090
if (sentence.id && sentenceIsAligned(sentence)) {
1092-
translation[sentence.id] = "";
10931091
lastAlignedSentenceId = `${sentence.id}`;
1094-
} else {
1092+
} else if (/translation/.test(sentence.className)) {
1093+
const translation: { [key: string]: string } = {};
10951094
if ((sentence as Element).hasAttribute("sentence-id")) {
10961095
let sentenceID = (sentence as Element).getAttribute(
10971096
"sentence-id",
@@ -1387,14 +1386,13 @@ export class ReadAlongComponent {
13871386
}
13881387

13891388
removeLine(sentence_element: Element) {
1390-
let newTranslation = {};
1391-
newTranslation[sentence_element.id] = null;
1392-
this.translations = { ...this.translations, ...newTranslation };
1389+
delete this.translations[sentence_element.id];
1390+
this.translations = { ...this.translations };
13931391
}
13941392

13951393
updateTranslation(sentence_id: string, text: string) {
13961394
this.translations[sentence_id] = text;
1397-
console.log(JSON.stringify(this.translations));
1395+
//console.log(JSON.stringify(this.translations));
13981396
}
13991397

14001398
async handleFiles(event: any, pageIndex: number) {
@@ -1753,9 +1751,8 @@ export class ReadAlongComponent {
17531751
if (event.key == "Enter") event.preventDefault();
17541752
}}
17551753
data-placeholder={this.getI18nString("line-placeholder")}
1756-
>
1757-
{this.translations[sentenceID]}
1758-
</p>
1754+
innerHTML={this.translations[sentenceID]}
1755+
></p>
17591756
</span>
17601757
);
17611758
} else {

0 commit comments

Comments
 (0)