Respect system locale when formatting file sizes via config (#15271)

# Description

Commands and other pieces of code using `$env.config.format.filesize` to
format filesizes now respect the system locale when formatting the
numeric portion of a file size.

# User-Facing Changes

- System locale is respected when using `$env.config.format.filesize` to
format file sizes.
- Formatting a file size with a binary unit is now exact for large file
sizes and units.
- The output of `to text` is no longer dependent on the config.
This commit is contained in:
Ian Manske
2025-03-09 13:43:02 -07:00
committed by GitHub
parent 4fe7865ad0
commit d97b2e3c60
8 changed files with 412 additions and 186 deletions

View File

@ -22,9 +22,16 @@ pub fn get_system_locale() -> Locale {
#[cfg(debug_assertions)]
pub fn get_system_locale_string() -> Option<String> {
std::env::var(LOCALE_OVERRIDE_ENV_VAR)
.ok()
.or_else(sys_locale::get_locale)
std::env::var(LOCALE_OVERRIDE_ENV_VAR).ok().or_else(
#[cfg(not(test))]
{
sys_locale::get_locale
},
#[cfg(test)]
{
|| Some(Locale::en_US_POSIX.name().to_owned())
},
)
}
#[cfg(not(debug_assertions))]