Skip to content

Token counts render Chinese units (万/千/百) when locale is "en" #613

Description

@JoshBolding

Summary

With the app language set to English ("locale": "en" in settings.json), token counts render using Chinese myriad units. The context-window chip shows the Grok 4.6 window as 50万 instead of 500K, while every surrounding string ("Context window", "Provided by Grok CLI") is correctly in English.

Environment

  • Grok App v0.2.18, Windows x64 portable build
  • Windows 11
  • settings.json"locale": "en"
  • Grok Build CLI 1.0.3

Root cause

formatTokenCount() in src/lib/contextUsage.ts:726 has no English branch. The locale argument is only used to choose between Simplified and Traditional Chinese:

export function formatTokenCount(n: number, locale: string = "zh"): string {
  const isTw = locale === "zh-TW" || /* ...zh-hant... */;
  const wan = isTw ? "萬" : "万";
  const yi  = isTw ? "億" : "亿";
  if (whole >= 100_000_000) return `...${yi}`;
  if (whole >= 10_000)      return `...${wan}`;
  if (whole >= 1_000)       return `...千`;  // not locale-gated
  if (whole >= 100)         return `...百`;  // not locale-gated
  return String(whole);
}

For locale === "en", isTw is false, so wan resolves to "万". The 千 and 百 branches are unconditional and apply to every locale.

The surrounding plumbing is correct — AppWorkbench.tsx:20615 does pass locale={locale}, and that value resolves to "en". The formatter itself is the only gap.

formatContextChipLabel() (src/lib/contextUsage.ts:750) carries the same locale: string = "zh" default and inherits the behavior.

Expected vs actual (locale en)

tokens current expected
500,000 50万 500K
12,400 1.2万 12.4K
1,000,000 100万 1M
5,000 5千 5K
300 3百 300

Suggested fix

Add an English K/M/B path ahead of the CJK bands, gated on the locale not starting with zh.

Existing tests in src/lib/contextUsage.test.ts:43-64 cover only Chinese (handles edge and Chinese scale bands (百/千/万/亿) and uses 萬/億 for zh-TW), so an en case would lock this in.

Happy to send a PR if that would help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:i18nLocalizationbugSomething isn't workingfrom:communityReported from X / communitypriority:p1Major UX / high impact

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions