Skip to content

Comments

feat(i18n): format numbers with Intl.NumberFormat#1149

Merged
danielroe merged 7 commits intonpmx-dev:mainfrom
DDeenis:feat/number-locale-formatting
Feb 7, 2026
Merged

feat(i18n): format numbers with Intl.NumberFormat#1149
danielroe merged 7 commits intonpmx-dev:mainfrom
DDeenis:feat/number-locale-formatting

Conversation

@DDeenis
Copy link
Contributor

@DDeenis DDeenis commented Feb 7, 2026

Format all numbers relative to the current locale. Let me know if I missed any.
Package versions are NOT locale formatted on purpose - they can be used for installing a specific version of the package, and not necessarily have only numbers.

Example (package page - Arabic) image (`kB` is not translated since I have only updated English translations)

@vercel
Copy link

vercel bot commented Feb 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Feb 7, 2026 8:02pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Feb 7, 2026 8:02pm
npmx-lunaria Ignored Ignored Feb 7, 2026 8:02pm

Request Review

@github-actions
Copy link

github-actions bot commented Feb 7, 2026

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
lunaria/files/en-GB.json Localization changed, will be marked as complete.
lunaria/files/en-US.json Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

❌ Patch coverage is 61.90476% with 16 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/pages/package/[[org]]/[name].vue 6.66% 12 Missing and 2 partials ⚠️
app/components/Package/DownloadAnalytics.vue 50.00% 0 Missing and 1 partial ⚠️
app/composables/useNumberFormatter.ts 93.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@DDeenis
Copy link
Contributor Author

DDeenis commented Feb 7, 2026

Does it make sense to test browser APIs? 🤔

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2026

📝 Walkthrough

Walkthrough

This pull request centralises numeric and byte formatting by adding app/composables/useNumberFormatter.ts (exports useNumberFormatter, useCompactNumberFormatter, useBytesFormatter), replaces direct uses of formatCompactNumber/formatBytes across components and pages with the new composables, updates computeFacetValue in app/composables/usePackageComparison.ts to accept formatter parameters and adjusts call sites, removes the old formatter exports from app/utils/formatters.ts, adds size translation keys, and removes the corresponding unit tests for the removed utilities.

Possibly related PRs

Suggested reviewers

  • danielroe
  • whitep4nth3r
🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining the purpose of formatting numbers according to locale using Intl.NumberFormat, with specific clarifications about package versions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
app/composables/useNumberFormatter.ts (1)

14-32: Align byte unit labels with the base used.

The formatter uses 1024 multiples but labels values as kB/MB (SI). Consider switching to 1000-based units or renaming labels to KiB/MiB to avoid unit mismatch.

Possible adjustment (1000‑based)
-    format: (bytes: number) => {
-      if (bytes < 1024)
+    format: (bytes: number) => {
+      const kB = 1000
+      const MB = 1000 * 1000
+      if (bytes < kB)
         return t('package.size.b', {
           size: decimalNumberFormatter.value.format(bytes),
         })
-      if (bytes < 1024 * 1024)
+      if (bytes < MB)
         return t('package.size.kb', {
-          size: decimalNumberFormatter.value.format(bytes / 1024),
+          size: decimalNumberFormatter.value.format(bytes / kB),
         })
       return t('package.size.mb', {
-        size: decimalNumberFormatter.value.format(bytes / (1024 * 1024)),
+        size: decimalNumberFormatter.value.format(bytes / MB),
       })
     },
app/composables/usePackageComparison.ts (1)

352-354: Consider locale-formatting dependency counts too.

Now that formatters are injected, dependency and total dependency counts are still rendered via String(), so they won’t be locale-formatted. Adding a plain number formatter here would make the facet values fully consistent with the PR goal.

app/components/Package/Dependencies.vue (1)

153-199: Format the remaining “show all” counts for consistency.
Peer/optional sections still pass raw lengths, while other counts are now formatted.

♻️ Suggested tweak
   $t('package.peer_dependencies.show_all', {
-    count: sortedPeerDependencies.length,
+    count: numberFormatter.format(sortedPeerDependencies.length),
   })

   $t('package.optional_dependencies.show_all', {
-    count: sortedOptionalDependencies.length,
+    count: numberFormatter.format(sortedOptionalDependencies.length),
   })

Also applies to: 201-242

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
app/components/Package/Dependencies.vue (2)

203-241: ⚠️ Potential issue | 🟡 Minor

Optional dependencies “Show all” count is still unformatted.
Line 239 still passes the raw length; use the number formatter for locale consistency.

Proposed fix
         {{
           $t('package.optional_dependencies.show_all', {
-            count: sortedOptionalDependencies.length,
+            count: numberFormatter.format(sortedOptionalDependencies.length),
           })
         }}

139-143: ⚠️ Potential issue | 🟡 Minor

Remove per-element focus-visible utilities on buttons.
These buttons still apply focus-visible:outline-accent/70; the project uses a global button/select focus-visible rule, so inline utilities should be dropped.

Proposed fix
-        class="my-2 ms-1 font-mono text-xs text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70"
+        class="my-2 ms-1 font-mono text-xs text-fg-muted hover:text-fg transition-colors duration-200 rounded"
-        class="mt-2 font-mono text-xs text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70"
+        class="mt-2 font-mono text-xs text-fg-muted hover:text-fg transition-colors duration-200 rounded"
Based on learnings, “In the npmx.dev project, ensure that focus-visible styling for button and select elements is implemented globally in app/assets/main.css with the rule: button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }. Do not apply per-element inline utility classes like focus-visible:outline-accent/70 on these elements in Vue templates or components.”

Also applies to: 187-191

@danielroe danielroe added this pull request to the merge queue Feb 7, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 7, 2026
@vercel
Copy link

vercel bot commented Feb 7, 2026

@DDeenis is attempting to deploy a commit to the serhalp's projects Team on Vercel.

A member of the Team first needs to authorize it.

@DDeenis
Copy link
Contributor Author

DDeenis commented Feb 7, 2026

It seems that the PR for removed from the merge queue for unrelated reasons. Anyway, I've implemented coderabbit's suggestion.

@danielroe danielroe enabled auto-merge February 7, 2026 20:00
@danielroe danielroe added this pull request to the merge queue Feb 7, 2026
Merged via the queue into npmx-dev:main with commit 5ad013b Feb 7, 2026
17 of 18 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