Replace number formatting regexes with Intl.NumberFormat

Created on 27 November 2023, 7 months ago
Updated 15 May 2024, about 1 month ago

Problem/Motivation

ProjectBrowser.svelte and ModulePage.svelte use complicated regexes to format numbers with comma number separators (1000000 -> 1,000,000)

We should replace these regex-based methods with the more readable & localizable Intl.NumberFormat class.

In this way, users get number separators they are used to in their own language - for example, German-speakers will see one million formatted as "1.000.000"

Proposed resolution

In util.js we should export a new instance of the number formatter:

export const NumberFormatter = new Intl.NumberFormat(navigator.language);

Then, as needed, we can use this new object to format numbers:

setTimeout(() => {
  announce(
    Drupal.t('@count Results for @active_tab, Sorted by @sortText', {
      '@count': numberFormatter.format($rowsCount),
      '@sortText': sortText,
      '@active_tab': ACTIVE_PLUGINS[$activeTab],
    }),
  );
}, 210);
✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

🇺🇸United States andy-blum Ohio, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024