Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Sep 16, 2024

  1. I18N: Set C++ locale and format sizes according to the locale

    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
    ppisar committed Sep 16, 2024
    Configuration menu
    Copy the full SHA
    4b74503 View commit details
    Browse the repository at this point in the history