diff src/chat.js @ 74:64e35a92d163

add translation
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 28 Aug 2025 13:31:46 -0600
parents 60ebb333b40c
children
line wrap: on
line diff
--- a/src/chat.js	Thu Aug 28 05:16:32 2025 -0600
+++ b/src/chat.js	Thu Aug 28 13:31:46 2025 -0600
@@ -159,3 +159,26 @@
 		recorder.stop();
 	}
 }
+
+function showSelected(select) {
+	if( select.value !== 'show_trans' )
+		return;
+	let top = select.parentNode.parentNode;
+	let trans = top.querySelector('div[trans=needed]');
+	if( !trans )
+		return;
+	let msg = top.getAttribute('msg');
+	let message = top.querySelector('div[message]');
+	let text = textContent(message);
+	let url = `translate.js?msg=${msg}&text=${encodeURIComponent(text)}&language=${chat.language}`;
+	ajax(url);
+	showWaitingAiIcon();
+}
+
+function translated(msg,text) {
+	hideWaitingAiIcon();
+	let top = document.querySelector(`div[msg="${msg}"]`);
+	let trans = top.querySelector('div[trans]');
+	trans.setAttribute('trans','');
+	trans.innerHTML = text;
+}