From cb6ce42815b8da0f8633dbe326ce0cc68f7f1ba6 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Sun, 8 Feb 2026 17:37:47 +0100 Subject: [PATCH] fix: improve token formatting and aria-label in TokenUsageIndicator Remove trailing .0 from compact number formatting (1.0K -> 1K, 2.0M -> 2M). Include total token count in the aria-label when max context is unavailable, improving screen reader experience. --- client/src/components/Chat/Input/TokenUsageIndicator.tsx | 5 ++++- client/src/locales/en/translation.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/client/src/components/Chat/Input/TokenUsageIndicator.tsx b/client/src/components/Chat/Input/TokenUsageIndicator.tsx index 3008244d56..73e4421382 100644 --- a/client/src/components/Chat/Input/TokenUsageIndicator.tsx +++ b/client/src/components/Chat/Input/TokenUsageIndicator.tsx @@ -4,10 +4,12 @@ import { useLocalize, useTokenUsage } from '~/hooks'; import { cn } from '~/utils'; function formatTokens(n: number): string { - return new Intl.NumberFormat(undefined, { + const formatted = new Intl.NumberFormat(undefined, { notation: 'compact', maximumFractionDigits: 1, }).format(n); + // Remove trailing .0 before suffix (e.g., "1.0K" -> "1K", "2.0M" -> "2M") + return formatted.replace(/\.0(?=[A-Za-z]|$)/, ''); } interface ProgressBarProps { @@ -209,6 +211,7 @@ const TokenUsageIndicator = memo(function TokenUsageIndicator() { : localize('com_ui_token_usage_aria_no_max', { 0: formatTokens(inputTokens), 1: formatTokens(outputTokens), + 2: formatTokens(totalUsed), }); // Color based on percentage diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.json index e9dc93eb0d..cae721e2a6 100644 --- a/client/src/locales/en/translation.json +++ b/client/src/locales/en/translation.json @@ -1417,7 +1417,7 @@ "com_ui_token_exchange_method": "Token Exchange Method", "com_ui_token_url": "Token URL", "com_ui_token_usage_aria_full": "Token usage: {{0}} input, {{1}} output, {{2}} max context, {{3}}% used", - "com_ui_token_usage_aria_no_max": "Token usage: {{0}} input, {{1}} output", + "com_ui_token_usage_aria_no_max": "Token usage: {{0}} input, {{1}} output, {{2}} total tokens used", "com_ui_token_usage_context": "Context Usage", "com_ui_token_usage_input": "Input", "com_ui_token_usage_output": "Output",