Skip to content

fix(prompts): format numbers in en-US whatever the browser locale is - #1095

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/prompts-number-locale
Oct 16, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/prompts-number-locale

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

On app.ansvisor.com a prompt's Mentions read "1.232" (meaning 1,232) for a user whose browser is set to Turkish. The Prompts page formatted numbers with toLocaleString() without a locale, so they followed the browser's locale even though the UI is English-only (next-intl locales: ['en']). Turkish uses "." for thousands and "," for decimals, so the numbers misread as decimals.

  • Add formatNumber() to web/src/lib/format.ts, next to formatDate, which already pins 'en-US'. Nothing in the app uses next-intl's useFormatter. The codebase's existing pattern is an explicit 'en-US' (formatDate, insights/kpi-format.ts), so this follows it.
  • Use it for every number rendered on /dashboard/prompts: Mentions, Citations, Runs and Google Vol. (page.tsx), the platform volume chart tooltip (_charts.tsx), the Suggestions tab (_suggestions-card.tsx) and the bulk import dialog ("up to 1,000 rows", components/prompts/bulk-import-prompts.tsx).
  • formatCompactNumber now uses formatNumber below 1,000 too. Otherwise a fractional value such as Avg. AI Volume showed as "512,25" in a Turkish browser. This helper is shared, so other pages that use it get the same fix. English output is unchanged everywhere.
  • Add web/src/lib/format.test.ts. It simulates a Turkish default locale and fails on the old fallback ("512,25" instead of "512.25").

Out of scope: other pages still call toLocaleString() / toLocaleDateString() without a locale. Those pages are Traffic, Insights, Shopping, Citations, Topics, the prompt detail page, Similar Topics, the sidebar prompt count and the content components. formatRelative (≥ 30 days) also shows dates in the browser's format. These will come in a separate PR; dates need a format decision first.

Related issue

None. Reported from the live Prompts page.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Run the web app and sign in with the demo account ([email protected] / demo123).
  2. Set the browser language to Turkish, or simulate it in the DevTools console: const o = Number.prototype.toLocaleString; Number.prototype.toLocaleString = function (l, x) { return o.call(this, l ?? 'tr-TR', x); }; Then switch tabs without reloading so the page re-renders.
  3. Open Prompts → Insights (/dashboard/prompts/insights?range=90d). Google Vol. shows 39,000 and 8,520. On main it shows "39.000" and "8.520".
  4. Prompts → Add prompt → Bulk import reads "up to 1,000 rows". On main it reads "1.000".
  5. cd web && yarn test src/lib/format.test.ts

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

yarn test (722 tests) and yarn build also pass locally.

🤖 Generated with Claude Code

A Turkish browser showed a prompt's 1,232 mentions as "1.232" because the
Prompts page called toLocaleString() without a locale. Add formatNumber()
next to formatDate in lib/format.ts and use it for every number on the
Prompts page (table, volume chart, suggestions, bulk import) and for the
formatCompactNumber fallback below 1,000.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, approving. On the tree merged with main web tests pass (803) and the typecheck is clean apart from the known read-excel-file error. One note for later: #1049 added lib/number-format.ts, which formats in the UI's locale. While the UI is English-only both give the same output, but when a second locale lands, formatNumber should move onto it.

@gkhngyk
gkhngyk merged commit eb23e51 into ansvisor:main Oct 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants