-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I18N: Set C++ locale and format sizes according to the locale #1699
base: main
Are you sure you want to change the base?
Conversation
We were not able to find or create Copr project
Unless the HTTP status code above is >= 500, please check your configuration for:
|
Displaying a package size, an installation size, a download speed etc. formats decimal numbers to 1-digit precision after the decimal point (49.5 KiB). However, users expect the number to be formatted according their locale. E.g. in cs_CZ.UTF-8, it is "49,5 KiB". DNF5 formats these values with fmt::format() which utilizes C++ locale if "L" formatting option is used. C++ locale (std::locale::global()) and C locale (setlocale(), C++-wrapped as std::setlocale()) are two different things and DNF5 only has set the C locale up to now. This patch starts setting C++ locale, which also implicitly sets C locale. This patch also modifies libdnf5::cli::utils::units::format_size_aligned() to use the locale-dependent decimal seperator (available since fmt-8.0.0). I manually tested dnf5 and dnf5daemon-client and they work for me. Though there is a risk that the new C++ locale will affect some code uknown to me, like regular expression matching, or thread-specific locales. If the affected code was unfixable, we can resort to saving the desired C++ locale into a dedicated object accessible to format_size_aligned() and pass it explicitly for fmt::format. Thorough testing is welcome. Related: rpm-software-management#1687
88d7177
to
4b74503
Compare
I wonder how many inputs, outputs and regexes this PR will break. I'm considering whether to merge this PR now or first prepare a PR to fix the bugs I mentioned above. |
First we need to fix the parser. |
Some locale bugs in the parser are tracked in #1706. |
Displaying a package size, an installation size, a download speed etc. formats decimal numbers to 1-digit precision after the decimal point (49.5 KiB). However, users expect the number to be formatted according their locale. E.g. in cs_CZ.UTF-8, it is "49,5 KiB".
DNF5 formats these values with fmt::format() which utilizes C++ locale if "L" formatting option is used.
C++ locale (std::locale::global()) and C locale (setlocale(), C++-wrapped as std::setlocale()) are two different things and DNF5 only has set the C locale up to now.
This patch starts setting C++ locale, which also implicitly sets C locale. This patch also modifies
libdnf5::cli::utils::units::format_size_aligned() to use the locale-dependent decimal seperator (available since fmt-8.0.0).
I manually tested dnf5 and dnf5daemon-client and they work for me.
Though there is a risk that the new C++ locale will affect some code uknown to me, like regular expression matching, or thread-specific locales. If the affected code was unfixable, we can resort to saving the desired C++ locale into a dedicated object accessible to format_size_aligned() and pass it explicitly for fmt::format. Thorough testing is welcome.
Related: #1687