KEMBAR78
COMMON: Simplify API for getHumanReadableBytes() by ccawley2011 · Pull Request #4679 · scummvm/scummvm · GitHub
Skip to content

Conversation

@ccawley2011
Copy link
Member

This makes it easier to use in debug commands, avoids unnecessary string conversions and fixes a few cases where the units weren't being translated correctly.

Copy link
Member

@lephilousophe lephilousophe left a comment

Choose a reason for hiding this comment

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

I am not sure this PR goes in the right direction.
Instead of migrating from Common::String to char *, I think it should go to Common::U32String to allow for translated units.
Currently in the Weblate, KB is already translated КБ for Russian and Ukrainian languages and I don't really know how it behaves for now.

return Common::U32String::format(_("Download speed: %s %S"), speed.c_str(), _(speedUnits).c_str());
const char *speedUnits;
Common::String speed = Common::getHumanReadableBytes(CloudMan.getDownloadSpeed(), speedUnits);
return Common::U32String::format(_("Download speed: %s %S/s"), speed.c_str(), _(speedUnits).c_str());
Copy link
Member

Choose a reason for hiding this comment

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

I don't know why it was like this but %S means wide-char (and is not recommended).
You are passing an 8-bit string.

Copy link
Member Author

@ccawley2011 ccawley2011 Feb 4, 2023

Choose a reason for hiding this comment

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

_() converts the input to Common::U32String, and Common::U32String::format uses a custom implementation where %S always uses 4-byte chars.

@ccawley2011
Copy link
Member Author

ccawley2011 commented Feb 4, 2023

I am not sure this PR goes in the right direction. Instead of migrating from Common::String to char *, I think it should go to Common::U32String to allow for translated units. Currently in the Weblate, KB is already translated КБ for Russian and Ukrainian languages and I don't really know how it behaves for now.

The use of _s() within the function itself marks the string as translatable in Weblate, but doesn't actually translate it until it's passed to _(). By doing it this way, the function supports providing both translated units for use in the GUI and non-translated units for use in debug messages.

@lephilousophe
Copy link
Member

Oh! OK, I see. Nice!
Thanks for the explanation.

LGTM.

@sev-
Copy link
Member

sev- commented Feb 5, 2023

Nice, thank you!

@sev- sev- merged commit 6903fb4 into scummvm:master Feb 5, 2023
@ccawley2011 ccawley2011 deleted the get-human-readable-bytes branch February 5, 2023 22:08
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.

3 participants