Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dnf5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include <libdnf5/utils/bgettext/bgettext-mark-domain.h>
#include <libdnf5/utils/locker.hpp>
#include <libdnf5/version.hpp>
#include <locale.h>
#include <string.h>

#include <algorithm>
#include <cmath>
#include <cstring>
#include <filesystem>
#include <iostream>
#include <locale>

constexpr const char * DNF5_LOGGER_FILENAME = "dnf5.log";

Expand Down Expand Up @@ -940,11 +940,11 @@ static void print_new_leaves(Context & context) {
}

static void set_locale() {
auto * locale = setlocale(LC_ALL, "");
if (locale) {
return;
try {
std::locale::global(std::locale(""));
} catch (std::runtime_error & ex) {
std::cerr << "Failed to set locale, defaulting to \"C\"" << std::endl;
}
std::cerr << "Failed to set locale, defaulting to \"C\"" << std::endl;
}

} // namespace dnf5
Expand Down
8 changes: 6 additions & 2 deletions dnf5daemon-client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include <libdnf5/logger/stream_logger.hpp>
#include <libdnf5/utils/bgettext/bgettext-lib.h>
#include <libdnf5/utils/bgettext/bgettext-mark-domain.h>
#include <locale.h>
#include <string.h>

#include <cstring>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <locale>

namespace dnfdaemon::client {

Expand Down Expand Up @@ -220,7 +220,11 @@ static void add_commands(Context & context) {
int main(int argc, char * argv[]) {
std::unique_ptr<sdbus::IConnection> connection;

setlocale(LC_ALL, "");
try {
std::locale::global(std::locale(""));
} catch (std::runtime_error & ext) {
}


dnfdaemon::client::Context context;

Expand Down
3 changes: 3 additions & 0 deletions libdnf5-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ target_link_libraries(libdnf5-cli PRIVATE common)
target_link_libraries(libdnf5-cli PUBLIC libdnf5)

pkg_check_modules(LIBFMT REQUIRED fmt)
if (LIBFMT_VERSION VERSION_LESS 8.0.0)
add_definitions(-DFMT_PRE_8)
endif()
list(APPEND LIBDNF5_CLI_PC_REQUIRES "${LIBFMT_MODULE_NAME}")
target_link_libraries(libdnf5-cli PUBLIC ${LIBFMT_LIBRARIES})

Expand Down
9 changes: 8 additions & 1 deletion libdnf5-cli/utils/units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ std::pair<float, const char *> to_size(int64_t num) {

std::string format_size_aligned(int64_t num) {
auto [value, unit] = to_size(num);
return fmt::format("{0:.1f} {1:>3s}", value, unit);
return fmt::format(
#ifdef FMT_PRE_8
"{0:.1f} {1:>3s}",
#else
"{0:.1Lf} {1:>3s}",
#endif
value,
unit);
}


Expand Down
4 changes: 2 additions & 2 deletions test/libdnf5-cli/utils/test_utf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "utils/utf8.hpp"

#include <clocale>
#include <locale>


CPPUNIT_TEST_SUITE_REGISTRATION(UTF8Test);


void UTF8Test::setUp() {
// wide characters do not work at all until we set locales in the code
setlocale(LC_ALL, "C.UTF-8");
std::locale::global(std::locale("C.UTF-8"));

hello_world_en = "Hello world!";
hello_world_cs = "Ahoj světe!";
Expand Down