mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
fix(panel): restore missing i18n keys and localize en-US trend/CSV dates
- Add header.scopeAll and header.scopeAllShort in zh-CN and en-US and align StepTableWidget cost width estimation with formatUsd - Format trend chart hover titles, x-axis tick tooltips, and CSV summary/trend rows per active locale instead of hardcoded Chinese date labels - Add static t(...) key completeness and bilingual trend/CSV regression checks
This commit is contained in:
@@ -13,7 +13,11 @@ import {
|
||||
patchStyleVar,
|
||||
patchText,
|
||||
} from '../../core/domPatch.js';
|
||||
import { formatTokensPrecise, formatUsd } from '../../core/formatters.js';
|
||||
import {
|
||||
formatTokensPrecise,
|
||||
formatTrendSlotFullLabel,
|
||||
formatUsd,
|
||||
} from '../../core/formatters.js';
|
||||
import { SVG_NS } from '../../icons/SvgIcon.js';
|
||||
import { getEffectiveLocale, t } from '../../i18n/index.js';
|
||||
import { createConsumptionBreakdownContent } from '../ui/ConsumptionTooltipContent.js';
|
||||
@@ -738,7 +742,7 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) {
|
||||
const slotTok = safeSlotTokens(slot.tokens);
|
||||
const slotCost = Number.isFinite(Number(slot.costUsd)) ? Math.max(0, Number(slot.costUsd)) : 0;
|
||||
tooltipContent.update({
|
||||
title: slot.fullLabel || slot.label || '--',
|
||||
title: formatTrendSlotFullLabel(slot) || slot.label || '--',
|
||||
calls: slot.calls,
|
||||
totalTokens: slotTok,
|
||||
costText: formatUsd(slotCost, {
|
||||
@@ -1517,7 +1521,7 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) {
|
||||
const tickEl = h('span', {
|
||||
className: `trend-x-tick text-mono${isFirst ? ' is-start' : isLast ? ' is-end' : ''}`,
|
||||
text: slot.label || '',
|
||||
title: slot.fullLabel || slot.label || '',
|
||||
title: formatTrendSlotFullLabel(slot) || slot.label || '',
|
||||
});
|
||||
patchStyleVar(tickEl, '--tick-x', `${pct.toFixed(2)}%`);
|
||||
tickEl.onclick = () => {
|
||||
|
||||
@@ -94,11 +94,7 @@ function estTokenChars(val) {
|
||||
}
|
||||
|
||||
function estCostWidth(st) {
|
||||
const c = st?.costUsd;
|
||||
if (c == null || !Number.isFinite(Number(c))) {
|
||||
return st?.isPricingPending ? estProportionalTextWidth(t('fmt.pricingPending')) : 1;
|
||||
}
|
||||
return estProportionalTextWidth(formatUsd(Number(c)));
|
||||
return estProportionalTextWidth(formatUsd(st?.costUsd, { precise: true }));
|
||||
}
|
||||
|
||||
function estSegmentChars(seg, st) {
|
||||
|
||||
@@ -21,6 +21,14 @@ const EN_MONTH_SHORT = Object.freeze([
|
||||
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
|
||||
]);
|
||||
|
||||
const ZH_WEEKDAY_SHORT = Object.freeze([
|
||||
'周日', '周一', '周二', '周三', '周四', '周五', '周六',
|
||||
]);
|
||||
|
||||
const EN_WEEKDAY_SHORT = Object.freeze([
|
||||
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',
|
||||
]);
|
||||
|
||||
export function formatMetric(value, unit = '') {
|
||||
if (!Number.isFinite(value)) return '—';
|
||||
const numStr = Math.abs(value) >= 100 ? String(Math.round(value)) : value.toFixed(1);
|
||||
@@ -110,6 +118,59 @@ export function formatDateSpanBadge(startMs, endMs) {
|
||||
return `${s.getMonth() + 1}月${s.getDate()}日 ~ ${e.getMonth() + 1}月${e.getDate()}日`;
|
||||
}
|
||||
|
||||
export function formatTrendSlotFullLabel(slot, { locale, showFullYear = false } = {}) {
|
||||
const en =
|
||||
typeof locale === 'string' && locale.trim()
|
||||
? locale.trim().toLowerCase().startsWith('en')
|
||||
: isEnglishLocale();
|
||||
const sMs = Number(slot?.startMs);
|
||||
if (Number.isFinite(sMs) && sMs > 0) {
|
||||
const sd = new Date(sMs);
|
||||
const pad2 = (n) => String(n).padStart(2, '0');
|
||||
const rawFull = String(slot?.fullLabel || '');
|
||||
const includeYear = Boolean(
|
||||
showFullYear || /^\d{4}年/.test(rawFull) || sd.getFullYear() !== new Date().getFullYear()
|
||||
);
|
||||
const gran = String(slot?.granularity || '').toLowerCase();
|
||||
const isSubDay =
|
||||
gran === 'minute' ||
|
||||
gran === 'hour' ||
|
||||
(!gran && Number(slot?.endMs) > sMs && Number(slot.endMs) - sMs <= 3600_000 * 2);
|
||||
|
||||
if (isSubDay) {
|
||||
const eMs = Number(slot?.endMs);
|
||||
const ed = Number.isFinite(eMs) && eMs > 0 ? new Date(eMs) : new Date(sMs + 3600_000);
|
||||
const hh = `${pad2(sd.getHours())}:${pad2(sd.getMinutes())}`;
|
||||
const endHh = `${pad2(ed.getHours())}:${pad2(ed.getMinutes())}`;
|
||||
if (en) {
|
||||
const mon = EN_MONTH_SHORT[sd.getMonth()] || '';
|
||||
return includeYear
|
||||
? `${mon} ${sd.getDate()}, ${sd.getFullYear()}, ${hh} - ${endHh}`
|
||||
: `${mon} ${sd.getDate()}, ${hh} - ${endHh}`;
|
||||
}
|
||||
const yearPrefix = includeYear ? `${sd.getFullYear()}年` : '';
|
||||
return `${yearPrefix}${sd.getMonth() + 1}月${sd.getDate()}日 ${hh} - ${endHh}`;
|
||||
}
|
||||
|
||||
if (en) {
|
||||
const mon = EN_MONTH_SHORT[sd.getMonth()] || '';
|
||||
const wday = EN_WEEKDAY_SHORT[sd.getDay()] || '';
|
||||
return includeYear
|
||||
? `${mon} ${sd.getDate()}, ${sd.getFullYear()} (${wday})`
|
||||
: `${mon} ${sd.getDate()} (${wday})`;
|
||||
}
|
||||
const yearPrefix = includeYear ? `${sd.getFullYear()}年` : '';
|
||||
return `${yearPrefix}${sd.getMonth() + 1}月${sd.getDate()}日 (${ZH_WEEKDAY_SHORT[sd.getDay()] || ''})`;
|
||||
}
|
||||
|
||||
const rawFull = String(slot?.fullLabel || '').trim();
|
||||
const rawShort = String(slot?.label || '').trim();
|
||||
if (en && rawFull && /[\u4e00-\u9fff]/.test(rawFull)) {
|
||||
return rawShort || rawFull;
|
||||
}
|
||||
return rawFull || rawShort;
|
||||
}
|
||||
|
||||
export function formatUsd(amount, { precise = false } = {}) {
|
||||
if (amount == null || !Number.isFinite(Number(amount))) return t('fmt.pending');
|
||||
const val = Number(amount || 0);
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
formatPctNumber,
|
||||
formatSpeedMetric,
|
||||
formatTokensPrecise,
|
||||
formatTrendSlotFullLabel,
|
||||
formatUsd,
|
||||
mergeModelsByDisplayName,
|
||||
resolveModelDisplayInfo,
|
||||
@@ -20,8 +21,10 @@ import { buildXlsxWorkbookBytes } from './xlsxBuilder.js';
|
||||
const PLAIN_SIGNED_NUMBER_RE = /^[+-]?\d+(\.\d+)?$/;
|
||||
|
||||
const RANGE_LABELS_ZH = Object.freeze({
|
||||
'5h': '近5小时',
|
||||
today: '今日',
|
||||
'24h': '近24小时',
|
||||
week: '本周',
|
||||
'7d': '近7天',
|
||||
'14d': '近14天',
|
||||
'30d': '近30天',
|
||||
@@ -31,8 +34,10 @@ const RANGE_LABELS_ZH = Object.freeze({
|
||||
});
|
||||
|
||||
const RANGE_LABELS_EN = Object.freeze({
|
||||
'5h': 'Last 5 Hours',
|
||||
today: 'Today',
|
||||
'24h': 'Last 24 Hours',
|
||||
week: 'This Week',
|
||||
'7d': 'Last 7 Days',
|
||||
'14d': 'Last 14 Days',
|
||||
'30d': 'Last 30 Days',
|
||||
@@ -833,8 +838,10 @@ export function buildStepsMarkdownReport(
|
||||
export function buildConsumptionCsv(
|
||||
consumption,
|
||||
modelBreakdown = [],
|
||||
{ displaySettings = {}, includeBom = true } = {}
|
||||
{ displaySettings = {}, includeBom = true, locale } = {}
|
||||
) {
|
||||
const en = resolveExportEnglish(locale);
|
||||
const effectiveLocale = en ? 'en-US' : 'zh-CN';
|
||||
const cons = consumption || {};
|
||||
const acc = cons.account || {};
|
||||
const range = cons.selectedRange || {};
|
||||
@@ -860,7 +867,7 @@ export function buildConsumptionCsv(
|
||||
]),
|
||||
csvRow([
|
||||
'summary',
|
||||
range.label || range.key || 'all',
|
||||
resolveLocalizedRangeLabel(range, en),
|
||||
Number(acc.calls || 0),
|
||||
Number(acc.inputTokens || 0),
|
||||
Number(acc.cacheReadTokens || 0),
|
||||
@@ -928,7 +935,7 @@ export function buildConsumptionCsv(
|
||||
rows.push(
|
||||
csvRow([
|
||||
'trend',
|
||||
slot.fullLabel || slot.label || '',
|
||||
formatTrendSlotFullLabel(slot, { locale: effectiveLocale }) || slot.label || '',
|
||||
Number(slot.calls || 0),
|
||||
Number(slot.inputTokens || 0),
|
||||
Number(slot.cacheReadTokens || 0),
|
||||
|
||||
@@ -32,6 +32,8 @@ export const I18N_MESSAGES_EN_US = Object.freeze({
|
||||
'header.statusQuotaCached': 'Quota Cached',
|
||||
'header.statusQuotaOffline': 'Quota Offline',
|
||||
'header.statusLive': 'Monitoring',
|
||||
'header.scopeAll': 'All Agents',
|
||||
'header.scopeAllShort': 'All',
|
||||
'header.searchSessionPlaceholder': 'Search sessions, projects, or ID…',
|
||||
'select.searchPlaceholder': 'Filter options…',
|
||||
'select.noMatches': 'No matching items',
|
||||
|
||||
@@ -32,6 +32,8 @@ export const I18N_MESSAGES_ZH_CN = Object.freeze({
|
||||
'header.statusQuotaCached': '额度缓存',
|
||||
'header.statusQuotaOffline': '额度离线',
|
||||
'header.statusLive': '监控中',
|
||||
'header.scopeAll': '全部代理',
|
||||
'header.scopeAllShort': '全',
|
||||
'header.searchSessionPlaceholder': '搜索会话标题、项目或 ID…',
|
||||
'select.searchPlaceholder': '输入关键词筛选…',
|
||||
'select.noMatches': '没有匹配的选项',
|
||||
|
||||
Reference in New Issue
Block a user