From 8c2a382e4b40d6408a9af458f9316e1503701196 Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Fri, 27 Aug 2010 16:37:54 +0200 Subject: Localization of [y/n] response in abrt-cli --- src/cli/report.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/cli/report.cpp') diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 4c5eb6f1..a7606995 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -531,17 +531,24 @@ static vector_string_t get_enabled_reporters(map_crash_data_t &crash_data) return result; } -/* Asks a [y/n] question on stdin/stdout. +/** + * Asks a [y/n] question on stdin/stdout. * Returns true if the answer is yes, false otherwise. */ static bool ask_yesno(const char *question) { - printf(question); + /* The response might take more than 1 char in non-latin scripts. */ + const char *yes = _("y"); + const char *no = _("N"); + char *full_question = xasprintf("%s [%s/%s]: ", question, yes, no); + printf(full_question); + free(full_question); fflush(NULL); - char answer[16] = "n"; + char answer[16]; fgets(answer, sizeof(answer), stdin); - /* TODO: localize 'y' */ - return ((answer[0] | 0x20) == 'y'); + /* Use strncmp here because the answer might contain a newline as + the last char. */ + return 0 == strncmp(answer, yes, strlen(yes)); } /* Returns true if echo has been changed from another state. */ @@ -712,7 +719,7 @@ int report(const char *crash_id, int flags) for (vector_string_t::const_iterator it = reporters.begin(); it != reporters.end(); ++it) { char question[255]; - snprintf(question, 255, _("Report using %s? [y/N]: "), it->c_str()); + snprintf(question, 255, _("Report using %s?"), it->c_str()); if (!ask_yesno(question)) { puts(_("Skipping...")); -- cgit