tags 475802 + patch
thanks

[CC to some people that commented on these bug reports related to
input translation on prompts.]

On 14 January 2012 22:24, Daniel Hartwig <[email protected]> wrote:
> Anyway, there are not many places where the prompt is invoked so I
> will get a patch together next time I am at the workstation.

Actually, ignoring cwidget prompts for now, there is only one straight
yes-no prompt:
  - cmdline_prompt.cc(prompt_trust)

This method currently expects the user to type exactly "yes" or it's
translation.  Using rpmatch(3) (a wrapper for nl_langinfo(3)) the
attached patch changes this to a more standard yn prompt.

This is a great option which addresses all concerns raised for Bug:
#475802 and LP: #16953, and uses standard translations for input to
the yes-no prompt.

*NOTE* This patch addresses only the "untrusted sources" command-line
prompt.  I provide some comments regarding the other prompts afterwards.

Now, some verbose examples of the new behaviour: (please skip forward
if short attention :-)

Deng Xiyue wrote:
> For Chinese user, "Yes" will be translated to "是", which will be used
> for the is_ok comparison.  Meanwhile, "是" will not be able to input
> when input method is unavailable, which in turn isn't installed by
> default install settings.

So, for example, in the zh_CN locale this prompt now accepts responses
starting with:
  - affirmative: "y", or "是"
  - negative: "n", "不", or "否"


Noritada Kobayashi wrote:
> Yeah, it's true for Japanese users.  "Yes" and "No" are respectively
> "はい" (hai) and "いいえ" (iie) in Japanese.  Since they can be input
> only via input methods, however, softwares usually provide a prompt
> like "Yes/No" or "Y/N" to us.  Forcing users to input "はい" is not a
> good idea.

In ja_JP locale the responses can start with:
  - affirmative: "y", "y", "はい", or "ハイ"
  - negative: "n", "n", "いいえ", or "イイエ"


Adam Borowski wrote:
> This way, if the language is russian, the prompt would be:
> "Start nuclear war? (Да/Нет) (Y/N)"

The "[y/n]" hint should not be included when there is already a
translated hint.

>
> where both "д" and "y" would confirm, and both "н" and "n" would deny.

ru_RU responses:
  - affirmative: "д", or "y"
  - negative: "н", or "n"


Santiago M. Mola wrote:
> Should I go ahead and install the packages anyway?
> To continue, enter "Sí"; to abort, enter "No":
> ---
>
> It doesn't work! I typed Si, S, Yes, Y... it doesn't work anyway...

The es_ES locale will now accept both "Sí" and "Si" (and any other
response beginning with "s" or "y").


*** Other prompts ***

A quick survey of the current situation with the other prompts.

On the command-line side there is:

  * cmdline_prompt.cc(prompt_essential): user must type a string
    exactly, either translated or untranslated.

    This is "working" right now, however, many translations require
    input methods to type and if those methods aren't available the
    user does not know they can type the untranslated string (they
    don't even get told what it is).

  * cmdline_prompt.cc(cmdline_do_prompt): the standard "Do you want
    to continue?" prompt for package installs, etc. -- does not
    accept translated input.

    We could (should?) accepted translated input to
    this prompt -- though there are a lot of commands and to handle
    this *thoroghly* will require translators to write small regular
    expressions like "nl_langinfo(YESEXPR)" provides.

  * cmdline_resolver.cc(cmdline_resolve_deps): the command-line
    problem resolver.

    Same situation as above.

I have not yet looked at the curses side very much.  I assume that
most yes-no prompts can have the keybindings overloaded (e.g.  "y" and
"j" mean "yes" for German) but don't know if there is a mechanism in
place to allow translators to define this.

Has any one had a chance to investigate the options for cwidget?
From d89a3db8ab15359ae8121a2d29f19d028ba91d32 Mon Sep 17 00:00:00 2001
From: Daniel Hartwig <[email protected]>
Date: Mon, 23 Jan 2012 20:57:37 +0800
Subject: [PATCH] I18n deficiency in cmdline "untrusted" prompt.

* src/cmdline/cmdline_prompt.cc(prompt_trust): use
  rpmatch(3) to properly handle translated and
  untranslated responses. (LP: #16953)
---
 src/cmdline/cmdline_prompt.cc |   44 ++++++++++------------------------------
 1 files changed, 11 insertions(+), 33 deletions(-)

diff --git a/src/cmdline/cmdline_prompt.cc b/src/cmdline/cmdline_prompt.cc
index f650ba4..d0b5499 100644
--- a/src/cmdline/cmdline_prompt.cc
+++ b/src/cmdline/cmdline_prompt.cc
@@ -553,30 +553,15 @@ static bool prompt_trust(const shared_ptr<terminal_metrics> &term_metrics)
 	}
 
 
-      // ForTranslators: This string is a confirmation message, which
-      // users (especially CJK users) should be able to input without
-      // input methods.  Please include nothing but ASCII characters.
-      // The text preceding the pipe character (|) will be ignored and
-      // can be removed from your translation.
-      const string okstr    = P_("Go ahead and ignore the warning|Yes");
-      // ForTranslators: This string is a confirmation message, which
-      // users (especially CJK users) should be able to input without
-      // input methods.  Please include nothing but ASCII characters.
-      // The text preceding the pipe character (|) will be ignored and
-      // can be removed from your translation.
-      const string abortstr = P_("Abort instead of overriding the warning|No");
-
-      // These strings are used to compare in a translation-invariant
-      // way, so that "yes" and "no" are always valid inputs; if the
-      // user can't enter the translated string for some reason,
-      // he/she can always enter the fallback strings.
-      const string fallback_okstr = "Yes";
-      const string fallback_abortstr = "No";
-
       while(1)
 	{
-	  printf(_("Do you want to ignore this warning and proceed anyway?\n"));
-	  printf(_("To continue, enter \"%s\"; to abort, enter \"%s\": "), okstr.c_str(), abortstr.c_str());
+          // ForTranslators: This prompt uses rpmatch(3) to accept
+          // standardized translated responses as well as "y"
+          // (affirmative) and "n" (negative).  The hint "[y/n]" can
+          // be translated to the standard native prompt (e.g. "[j/n]"
+          // for German) but, as there is no default response, please
+          // do not use a capital to indicate one.
+	  printf(_("Do you want to ignore this warning and proceed anyway? [y/n] "));
 	  char buf[1024];
 	  cin.getline(buf, 1023);
 	  buf[1023]='\0';
@@ -584,19 +569,11 @@ static bool prompt_trust(const shared_ptr<terminal_metrics> &term_metrics)
 	  if(cin.eof())
 	    throw StdinEOFException();
 
+          int res = rpmatch(buf);
+          if(res >= 0)
+            return res > 0;
 
-	  const bool is_ok =             strncasecmp(okstr.c_str(), buf, okstr.size()) == 0;
-	  const bool is_fallback_ok =    strncasecmp(fallback_okstr.c_str(), buf, fallback_okstr.size()) == 0;
-	  const bool is_abort =          strncasecmp(abortstr.c_str(), buf, abortstr.size()) == 0;
-	  const bool is_fallback_abort = strncasecmp(fallback_abortstr.c_str(), buf, fallback_abortstr.size()) == 0;
-
-	  const bool rval = is_ok || (is_fallback_ok && !is_abort);
-
-	  if(!is_ok && !is_abort && !is_fallback_ok && !is_fallback_abort)
-	    printf(_("Unrecognized input.  Enter either \"%s\" or \"%s\".\n"), okstr.c_str(), abortstr.c_str());
-	  else
-	    return rval;
+          printf(_("Unrecognized input.  Enter either \"%s\" or \"%s\".\n"), _("Yes"), _("No"));
 	}
     }
 
-- 
1.7.5.4

Reply via email to