Skip to content

Scripting: Normalize output of FormatBytes#947

Merged
d0k3 merged 2 commits intod0k3:masterfrom
Epicpkmn11:normalize-bytes-in-scripts
Mar 18, 2026
Merged

Scripting: Normalize output of FormatBytes#947
d0k3 merged 2 commits intod0k3:masterfrom
Epicpkmn11:normalize-bytes-in-scripts

Conversation

@Epicpkmn11
Copy link
Contributor

The output of FormatBytes() is localized, but it is provided to scripts and some (such as the hacks.guide finalizing script) expect it in the English format. Currently trying to run finalize with any locale that uses , as the decimal separator crashes the script and anything that renames "GB" (ex. French "Go") would cause that script to incorrectly display the no free space error if those languages didn't all use "," separator.

I considered making the Lua version have a flag to enable/disable localization, but I couldn't quite tell what the proper way to do that would be.

ldmstm

This comment was marked as resolved.

@Epicpkmn11
Copy link
Contributor Author

Epicpkmn11 commented Feb 18, 2026

The lua flag I mentioned in the OP has now been added (thanks @ihaveamac for actually doing the code). lua tested using this script, seems good:

local stat = fs.stat_fs("0:")
print("Default:", ui.format_bytes(stat["free"]))
print("Explicit Normalized:", ui.format_bytes(stat["free"], {use_locale=false}))
print("Localized:", ui.format_bytes(stat["free"], {use_locale=true}))

ui.echo("Press A to exit.")
snap_260218011546

Edit: And (as seen in line 2) the lua API is unbroken from the previous version

@ihaveamac
Copy link
Contributor

Since this technically changes the Lua behavior this should include an update to the documentation for ui.format_bytes.

@ihaveamac
Copy link
Contributor

#### ui.format_bytes

* `string ui.format_bytes(int bytes[, table opts {bool use_locale}])`

Format a number with `Byte`, `kB`, `MB`, or `GB`.

* **Arguments**
        * `bytes` - Size to format
        * `opts` (optional) - Option flags
                * `use_locale` - Format based on current locale
* **Returns:** formatted string

Co-Authored-By: ihaveahax <ian@ianburgwin.net>
@Epicpkmn11 Epicpkmn11 force-pushed the normalize-bytes-in-scripts branch from 5611a25 to d8f149c Compare February 18, 2026 17:07
@Epicpkmn11
Copy link
Contributor Author

Oh didn't see your second comment so I just wrote it myself 😅

Fixed the stray ; and updated the docs, did it in a force push cause I know I've been asked to keep my commits clean here before sometimes.

@ihaveamac
Copy link
Contributor

It’s fine, yours is better than what I typed up anyway.

@Wolfvak
Copy link
Collaborator

Wolfvak commented Feb 18, 2026

about keeping it clean: we can just squash and merge, it's not a big deal

@d0k3 d0k3 merged commit d2445f0 into d0k3:master Mar 18, 2026
1 check passed
@d0k3
Copy link
Owner

d0k3 commented Mar 18, 2026

Squashed and merged, thank you!

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.

5 participants