- fixed zypper to complain when given an invalid answer in y/n prompt
authorJan Kupec <jkupec@suse.cz>
Tue, 7 Aug 2007 14:04:33 +0000 (14:04 +0000)
committerJan Kupec <jkupec@suse.cz>
Tue, 7 Aug 2007 14:04:33 +0000 (14:04 +0000)
  (#232250) plus made the answer translatable.

src/zypper-callbacks.cc
src/zypper-callbacks.h

index a46ce3a..7f84607 100644 (file)
@@ -1,10 +1,13 @@
-#include "AliveCursor.h"
-#include "zypper.h"
-
 #include <ctype.h>
 #include <sstream>
 
+#include <boost/format.hpp>
+
+#include "AliveCursor.h"
+#include "zypper.h"
+
 using namespace std;
+using namespace boost;
 
 void display_progress ( const std::string &id, ostream & out, const string& s, int percent) {
   static AliveCursor cursor;
@@ -120,7 +123,6 @@ int read_action_ari (int default_action) {
 
 // ----------------------------------------------------------------------------
 
-// Read an answer (ynYN)
 bool read_bool_answer(const string & question, bool default_answer)
 {
   if (!gSettings.machine_readable)
@@ -138,13 +140,37 @@ bool read_bool_answer(const string & question, bool default_answer)
   istream & stm = cin;
 
   string c = "";
-  while (stm.good () && c != "y" && c != "Y" && c != "N" && c != "n")
+  bool been_here_before = false;
+  while (stm.good ()
+    // TranslatorExplanation This is a Lowercase 'y' for "yes" used as an
+    // answer in y/n prompts. Translate to the same letter as you translated
+    // it in the "[y/n]" string!.
+    && c != _("y")
+    // TranslatorExplanation Uppercase 'Y' for "yes" used as an
+    // answer in y/n prompts. Translate to the same letter as you translated
+    // it in the "[y/n]" string!.
+    && c != _("Y")
+    // TranslatorExplanation Lowercase 'n' for "no" used as an
+    // answer in y/n prompts. Translate to the same letter as you translated
+    // it in the "[y/n]" string!.
+    && c != _("n")
+    // TranslatorExplanation Uppercase 'N' for "no" used as an
+    // answer in y/n prompts. Translate to the same letter as you translated
+    // it in the "[y/n]" string!.
+    && c != _("N"))
+  {
+    if (been_here_before)
+      // TranslatorExplanation Example: Invalid answer 'x', enter 'y' or 'n':
+      cerr << format(_("Invalid answer '%s', enter '%s' or '%s':"))
+          % c % _("y") % _("n") << " ";
     c = zypp::str::getline (stm, zypp::str::TRIM);
+    been_here_before = true;
+  }
 
   MIL << "answer: " << c << endl;
-  if (c == "y" || c == "Y")
+  if (c == _("y") || c == _("Y"))
     return true;
-  else if (c == "n" || c == "N")
+  else if (c == _("n") || c == _("N"))
     return false;
   else
   {
index 500c081..396a9ad 100644 (file)
@@ -56,13 +56,11 @@ void display_error (Error error, const std::string& reason) {
 int read_action_ari (int default_action = -1);
 
 /**
- * Prompt for Yes/No answer from stdin.
+ * Prompt for y/n answer (localized) from stdin.
  *
  * \param question Question to be printed on prompt.
  * \param default_answer Value to be returned in non-interactive mode or on
  *      input failure.
- *
- * \todo make this localized
  */
 bool read_bool_answer(const string & question, bool default_answer);