[feat] chat html translation
This commit is contained in:
@@ -69,16 +69,20 @@
|
|||||||
let lastParsed = ''
|
let lastParsed = ''
|
||||||
|
|
||||||
const markParsing = async (data: string, charArg?: string | groupChat | simpleCharacterArgument, mode?: "normal" | "back", chatID?: number, translateText?:boolean) => {
|
const markParsing = async (data: string, charArg?: string | groupChat | simpleCharacterArgument, mode?: "normal" | "back", chatID?: number, translateText?:boolean) => {
|
||||||
const marked = await ParseMarkdown(data, charArg, mode, chatID)
|
|
||||||
lastParsed = marked
|
|
||||||
if(translateText){
|
if(translateText){
|
||||||
|
const marked = await ParseMarkdown(data, charArg, mode, chatID)
|
||||||
translating = true
|
translating = true
|
||||||
const translated = await translateHTML(marked, false)
|
const translated = await translateHTML(marked, false)
|
||||||
translating = false
|
translating = false
|
||||||
|
lastParsed = translated
|
||||||
return translated
|
return translated
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
const marked = await ParseMarkdown(data, charArg, mode, chatID)
|
||||||
|
lastParsed = marked
|
||||||
return marked
|
return marked
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$: displaya(message)
|
$: displaya(message)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -168,9 +168,10 @@ export async function translateHTML(html: string, reverse:boolean): Promise<stri
|
|||||||
if (node.nodeType === Node.TEXT_NODE) {
|
if (node.nodeType === Node.TEXT_NODE) {
|
||||||
// Translate the text content of the node
|
// Translate the text content of the node
|
||||||
if(node.textContent){
|
if(node.textContent){
|
||||||
|
console.log(node.nodeName,node.textContent)
|
||||||
node.textContent = await translate(node.textContent || '', reverse);
|
node.textContent = await translate(node.textContent || '', reverse);
|
||||||
}
|
}
|
||||||
} else {
|
} else if(node.nodeType === Node.ELEMENT_NODE) {
|
||||||
// Translate child nodes
|
// Translate child nodes
|
||||||
for (const child of Array.from(node.childNodes)) {
|
for (const child of Array.from(node.childNodes)) {
|
||||||
await translateNode(child);
|
await translateNode(child);
|
||||||
|
|||||||
Reference in New Issue
Block a user