RepoPilot

Does this respect the user's locale for number formatting?

About sindresorhus/pretty-bytes · 2 messages · last activity 7/27/2026

Question

Does this respect the user's locale for number formatting?

RepoPilot

Yes, pretty-bytes does respect the user's locale for number formatting through the locale option.

The localization is handled by the toLocaleString function [index.js:L55-L65], which uses JavaScript's native Number.toLocaleString() method. This allows formatting of the numeric part according to the specified locale's conventions.

According to the README, the locale option supports multiple modes:

  • false (default): Output won't be localized
  • true: Uses the system/browser locale automatically
  • string: Accepts a BCP 47 language tag (e.g., 'de', 'en')
  • string[]: Accepts a list of BCP 47 language tags for fallback support

For example, with German locale (de), the decimal separator changes from a period to a comma:

  • prettyBytes(10.1, {locale: 'de'}) returns '10,1 B'
  • prettyBytes(10.1, {locale: 'en'}) returns '10.1 B'

Important caveat: The README explicitly notes that only the number and decimal separator are localized. The unit titles (B, kB, MB, etc.) are not localized and will not be translated regardless of the locale setting [readme.md:L125].

FOLLOW_UPS:

  • How does the precision/rounding work with locale?
  • What happens if you pass an invalid locale string?
  • Can you customize minimum or maximum fraction digits?

Want to ask your own question?

Open chat for sindresorhus/pretty-bytes

Public Q&A. Generated by RepoPilot from the actual source of sindresorhus/pretty-bytes. AI answers can be incomplete or stale — verify before relying on them.