Show translation diagnostics in admin

This commit is contained in:
rajchales-monito
2026-07-29 21:40:01 +02:00
parent 865c997756
commit f93c92cd96
3 changed files with 80 additions and 10 deletions
+38
View File
@@ -591,9 +591,47 @@ function renderActive() {
${renderAttachments(message.attachments)}
</article>
`).join("") + adminReadReceipt(conversation, messages);
decorateTranslationMeta(messages);
$("#messages").scrollTop = $("#messages").scrollHeight;
}
function decorateTranslationMeta(messages) {
document.querySelectorAll("#messages .message .by").forEach((element, index) => {
const meta = translationMeta(messages[index]);
if (!meta) return;
const badge = document.createElement("span");
badge.className = `translation-meta ${meta.status}`;
badge.textContent = meta.label;
if (meta.error) badge.title = meta.error;
element.append(" ");
element.append(badge);
});
}
function translationMeta(message) {
if (!message?.translationStatus) return null;
const status = String(message.translationStatus || "");
const source = String(message.originalLanguage || "?").toUpperCase();
const target = String(message.translatedLanguage || "?").toUpperCase();
return {
status,
error: message.translationError || "",
label: translationStatusLabel(status, source, target)
};
}
function translationStatusLabel(status, source, target) {
if (status === "translated") return `preklad: ${source} -> ${target}`;
if (status === "same_language") return `preklad: ${source} = ${target}`;
if (status === "failed") return `preklad: ${source} -> ${target} - chyba`;
if (status === "missing_key") return "preklad: chybi klic";
if (status === "disabled") return "preklad: vypnuto";
if (status === "empty") return `preklad: ${source} -> ${target} - prazdny`;
if (status === "skipped") return "preklad: preskoceno";
if (status === "pending") return "preklad: ceka";
return `preklad: ${status}`;
}
function renderMessageBody(message) {
const original = message.body ? `<p>${escapeHtml(message.body)}</p>` : "";
if (!message.translatedBody) return original;