Repository navigation
fix(prompts): format numbers in en-US whatever the browser locale is - #1095
Merged
Merged
Conversation
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
approved these changes
Oct 16, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
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.
7 of 12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.formatNumber()toweb/src/lib/format.ts, next toformatDate, which already pins'en-US'. Nothing in the app uses next-intl'suseFormatter. The codebase's existing pattern is an explicit'en-US'(formatDate,insights/kpi-format.ts), so this follows it./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).formatCompactNumbernow usesformatNumberbelow 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.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 featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
[email protected]/demo123).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./dashboard/prompts/insights?range=90d). Google Vol. shows 39,000 and 8,520. Onmainit shows "39.000" and "8.520".mainit reads "1.000".cd web && yarn test src/lib/format.test.tsChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)yarn test(722 tests) andyarn buildalso pass locally.🤖 Generated with Claude Code