feat: localize logs page

This commit is contained in:
a.tolmachev
2026-04-02 23:06:25 +03:00
parent 2d7c43c438
commit 5e20b58766
3 changed files with 91 additions and 31 deletions
+20 -16
View File
@@ -20,6 +20,10 @@ document.addEventListener('DOMContentLoaded', function () {
var liveDot = document.querySelector('.live-dot');
var liveLabel = document.querySelector('.live-label');
function tKey(key) {
return window.t ? t(key) : key;
}
function currentWorkspaceId() {
var workspace = window.getCurrentWorkspace ? window.getCurrentWorkspace() : null;
return workspace ? workspace.id : null;
@@ -98,21 +102,21 @@ document.addEventListener('DOMContentLoaded', function () {
function renderLogs() {
if (state.loading && state.logs.length === 0) {
renderEmpty('Loading logs…', 'Fetching invocation history for the current workspace.');
renderEmpty(tKey('logs.loading.title'), tKey('logs.loading.sub'));
return;
}
if (state.loadError) {
renderEmpty('Unable to load logs', state.loadError);
renderEmpty(tKey('logs.error.title'), state.loadError);
return;
}
if (!state.logs.length) {
renderEmpty(
'No log entries found',
tKey('logs.empty.title'),
state.search || state.level !== 'all'
? 'Try widening the period or clearing the current search and level filters.'
: 'Run tests or published MCP tools to start collecting invocation history.'
? tKey('logs.empty.filtered')
: tKey('logs.empty.initial')
);
return;
}
@@ -172,7 +176,7 @@ document.addEventListener('DOMContentLoaded', function () {
if (detail.agentDisplayName || detail.agentSlug) {
var agentLabel = document.createElement('div');
agentLabel.className = 'log-detail-label';
agentLabel.textContent = 'Agent';
agentLabel.textContent = tKey('logs.detail.agent');
expanded.appendChild(agentLabel);
var agentPre = document.createElement('pre');
@@ -183,7 +187,7 @@ document.addEventListener('DOMContentLoaded', function () {
var requestLabel = document.createElement('div');
requestLabel.className = 'log-detail-label';
requestLabel.textContent = 'Request preview';
requestLabel.textContent = tKey('logs.detail.request');
expanded.appendChild(requestLabel);
var requestPre = document.createElement('pre');
@@ -193,7 +197,7 @@ document.addEventListener('DOMContentLoaded', function () {
var responseLabel = document.createElement('div');
responseLabel.className = 'log-detail-label';
responseLabel.textContent = 'Response preview';
responseLabel.textContent = tKey('logs.detail.response');
expanded.appendChild(responseLabel);
var responsePre = document.createElement('pre');
@@ -204,7 +208,7 @@ document.addEventListener('DOMContentLoaded', function () {
if (detail.errorKind || detail.requestId) {
var metaLabel = document.createElement('div');
metaLabel.className = 'log-detail-label';
metaLabel.textContent = 'Metadata';
metaLabel.textContent = tKey('logs.detail.meta');
expanded.appendChild(metaLabel);
var metaPre = document.createElement('pre');
@@ -253,14 +257,14 @@ document.addEventListener('DOMContentLoaded', function () {
async function loadLogs() {
if (!window.CrankApi) {
state.loadError = 'Admin API is not available';
state.loadError = tKey('logs.error.api');
renderLogs();
return;
}
state.workspaceId = currentWorkspaceId();
if (!state.workspaceId) {
state.loadError = 'Workspace is not selected';
state.loadError = tKey('logs.error.workspace');
renderLogs();
return;
}
@@ -276,7 +280,7 @@ document.addEventListener('DOMContentLoaded', function () {
state.openId = null;
}
} catch (error) {
state.loadError = error.message || 'Failed to load logs';
state.loadError = error.message || tKey('logs.error.load');
} finally {
state.loading = false;
renderLogs();
@@ -305,7 +309,7 @@ document.addEventListener('DOMContentLoaded', function () {
liveDot.style.cursor = 'pointer';
}
if (liveLabel) {
liveLabel.textContent = state.liveMode ? 'Live' : 'Paused';
liveLabel.textContent = state.liveMode ? tKey('logs.live') : tKey('logs.paused');
liveLabel.style.color = state.liveMode ? '' : 'var(--text-muted)';
liveLabel.style.cursor = 'pointer';
}
@@ -332,8 +336,8 @@ document.addEventListener('DOMContentLoaded', function () {
startPolling();
if (window.CrankUi) {
window.CrankUi.info(
state.liveMode ? 'Polling logs every 4 seconds.' : 'Automatic polling is paused.',
state.liveMode ? 'Live mode enabled' : 'Live mode paused'
state.liveMode ? tKey('logs.live.on.body') : tKey('logs.live.off.body'),
state.liveMode ? tKey('logs.live.on.title') : tKey('logs.live.off.title')
);
}
}
@@ -360,7 +364,7 @@ document.addEventListener('DOMContentLoaded', function () {
refreshBtn.addEventListener('click', function () {
loadLogs().then(function () {
if (!state.loadError && window.CrankUi) {
window.CrankUi.info('The latest invocation records were loaded for the current workspace.', 'Logs refreshed');
window.CrankUi.info(tKey('logs.refresh.body'), tKey('logs.refresh.title'));
}
});
});