Skip to content

Commit bb1cc58

Browse files
committed
Make userconfirm prompt strings translatable
The confirmation prompt "Is this ok [Y/n]:" and response characters were hardcoded strings in the userconfirm.hpp template function, making them untranslatable. Changes: - Extract translatable strings to libdnf5-cli/utils/userconfirm.cpp - Add helper functions: get_yes_no_prompt(), get_yes_response(), etc. - Update libdnf5-cli.pot with new translatable strings The userconfirm template now calls helper functions that return translated strings from the libdnf5-cli translation domain, allowing translators to localize the prompt and response characters. Fixes: #1868 Assisted-by: Claude Sonnet 4 (Anthropic)
1 parent d2e1187 commit bb1cc58

File tree

26 files changed

+2494
-1120
lines changed

26 files changed

+2494
-1120
lines changed

include/libdnf5-cli/utils/userconfirm.hpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@
2020
#ifndef LIBDNF5_CLI_UTILS_USERCONFIRM_HPP
2121
#define LIBDNF5_CLI_UTILS_USERCONFIRM_HPP
2222

23+
#include "libdnf5-cli/defs.h"
24+
2325
#include <libdnf5/conf/config_main.hpp>
2426

2527
#include <iostream>
2628
#include <string>
2729

2830
namespace libdnf5::cli::utils::userconfirm {
2931

32+
// Helper functions implemented in libdnf5-cli/utils/userconfirm.cpp
33+
LIBDNF_CLI_API const char * get_yes_no_prompt(bool default_yes);
34+
LIBDNF_CLI_API const char * get_yes_response();
35+
LIBDNF_CLI_API const char * get_yes_response_upper();
36+
LIBDNF_CLI_API const char * get_no_response();
37+
LIBDNF_CLI_API const char * get_no_response_upper();
38+
3039
/// Asks the user for confirmation. The default answer is taken from the configuration.
3140

3241
template <class Config>
@@ -38,25 +47,22 @@ bool userconfirm(Config & config) {
3847
if (config.get_assumeyes_option().get_value()) {
3948
return true;
4049
}
41-
std::string msg;
42-
if (config.get_defaultyes_option().get_value()) {
43-
msg = "Is this ok [Y/n]: ";
44-
} else {
45-
msg = "Is this ok [y/N]: ";
46-
}
50+
51+
auto default_yes = config.get_defaultyes_option().get_value();
52+
const char * msg = get_yes_no_prompt(default_yes);
4753
while (true) {
4854
std::cerr << msg;
4955

5056
std::string choice;
5157
std::getline(std::cin, choice);
5258

5359
if (choice.empty()) {
54-
return config.get_defaultyes_option().get_value();
60+
return default_yes;
5561
}
56-
if (choice == "y" || choice == "Y") {
62+
if (choice == get_yes_response() || choice == get_yes_response_upper()) {
5763
return true;
5864
}
59-
if (choice == "n" || choice == "N") {
65+
if (choice == get_no_response() || choice == get_no_response_upper()) {
6066
return false;
6167
}
6268
}

0 commit comments

Comments
 (0)