Commit a281022b authored by Fabian Sommer's avatar Fabian Sommer Committed by Commit Bot

Fix l10n for RTL languagues in the Request PIN dialog.

Fix l10n by no longer appending strings programmatically.

R=emaxx

      (e.g. smartcard), enter wrong PIN.

Bug: 1023360
Test: Enable RTL language, attempt to log in with PIN dialog
Change-Id: I9d4ffd3d1acef532d4899ef95a99d31af6fb682e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1926483Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Fabian Sommer <fabiansommer@google.com>
Cr-Commit-Position: refs/heads/master@{#720907}
parent 1a8bc86b
...@@ -3348,21 +3348,27 @@ ...@@ -3348,21 +3348,27 @@
<message name="IDS_REQUEST_PIN_DIALOG_PROCESSING" desc="The text displayed while the certificate provider API is waiting for response from extension."> <message name="IDS_REQUEST_PIN_DIALOG_PROCESSING" desc="The text displayed while the certificate provider API is waiting for response from extension.">
Processing request... Processing request...
</message> </message>
<message name="IDS_REQUEST_PIN_DIALOG_INVALID_PIN_ERROR" desc="The error message displayed in the certificate provider PIN request dialog when an invalid PIN was entered."> <message name="IDS_REQUEST_PIN_DIALOG_INVALID_PIN_ERROR" desc="The error message displayed in the certificate provider PIN request dialog when an invalid PIN was entered. Should end with a full stop since it can be chained with more text.">
Invalid PIN. Invalid PIN.
</message> </message>
<message name="IDS_REQUEST_PIN_DIALOG_INVALID_PUK_ERROR" desc="The error message displayed in the certificate provider PIN request dialog when an invalid PUK was entered."> <message name="IDS_REQUEST_PIN_DIALOG_INVALID_PUK_ERROR" desc="The error message displayed in the certificate provider PIN request dialog when an invalid PUK was entered. Should end with a full stop since it can be chained with more text.">
Invalid PUK. Invalid PUK.
</message> </message>
<message name="IDS_REQUEST_PIN_DIALOG_MAX_ATTEMPTS_EXCEEDED_ERROR" desc="The error message displayed in the certificate provider PIN request dialog when maximum allowed attempts exceeded."> <message name="IDS_REQUEST_PIN_DIALOG_MAX_ATTEMPTS_EXCEEDED_ERROR" desc="The error message displayed in the certificate provider PIN request dialog when maximum allowed attempts exceeded.">
Maximum allowed attempts exceeded. Maximum allowed attempts exceeded.
</message> </message>
<message name="IDS_REQUEST_PIN_DIALOG_UNKNOWN_ERROR" desc="The error message displayed in the certificate provider PIN request dialog when unknown error occurred in extension code."> <message name="IDS_REQUEST_PIN_DIALOG_UNKNOWN_ERROR" desc="The error message displayed in the certificate provider PIN request dialog when unknown error occurred in extension code. Should end with a full stop since it can be chained with more text.">
Unknown error. Unknown error.
</message> </message>
<message name="IDS_REQUEST_PIN_DIALOG_ATTEMPTS_LEFT" desc="The text displayed in the certificate provider PIN request dialog about the number of attempts left"> <message name="IDS_REQUEST_PIN_DIALOG_ATTEMPTS_LEFT" desc="The text displayed in the certificate provider PIN request dialog about the number of attempts left">
Attempts left: <ph name="ATTEMPTS_LEFT">$1<ex>3</ex></ph> Attempts left: <ph name="ATTEMPTS_LEFT">$1<ex>3</ex></ph>
</message> </message>
<message name="IDS_REQUEST_PIN_DIALOG_ERROR_RETRY" desc="The text displayed in the certificate provider PIN request dialog when the previous login attempt was unsuccessful, including the reason for the previous failure.">
<ph name="ERROR_MESSAGE">$1<ex>Invalid PIN.</ex></ph> Please try again.
</message>
<message name="IDS_REQUEST_PIN_DIALOG_ERROR_RETRY_ATTEMPTS" desc="The text displayed in the certificate provider PIN request dialog when the previous login attempt was unsuccessful but there are more attempts remaining. Includes the reason for the previous failure.">
<ph name="ERROR_MESSAGE">$1<ex>Invalid PIN.</ex></ph> Please try again. Attempts left: <ph name="ATTEMPTS_LEFT">$2<ex>3</ex></ph>
</message>
<message name="IDS_REQUEST_PIN_DIALOG_PIN" desc="The Provider Identification Number abbreviation"> <message name="IDS_REQUEST_PIN_DIALOG_PIN" desc="The Provider Identification Number abbreviation">
PIN PIN
</message> </message>
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/i18n/number_formatting.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/ui/passphrase_textfield.h" #include "chrome/browser/chromeos/ui/passphrase_textfield.h"
...@@ -129,7 +130,7 @@ void RequestPinView::SetDialogParameters(SecurityTokenPinCodeType code_type, ...@@ -129,7 +130,7 @@ void RequestPinView::SetDialogParameters(SecurityTokenPinCodeType code_type,
int attempts_left, int attempts_left,
bool accept_input) { bool accept_input) {
locked_ = false; locked_ = false;
SetErrorMessage(error_label, attempts_left); SetErrorMessage(error_label, attempts_left, accept_input);
SetAcceptInput(accept_input); SetAcceptInput(accept_input);
switch (code_type) { switch (code_type) {
...@@ -225,7 +226,8 @@ void RequestPinView::SetAcceptInput(bool accept_input) { ...@@ -225,7 +226,8 @@ void RequestPinView::SetAcceptInput(bool accept_input) {
} }
void RequestPinView::SetErrorMessage(SecurityTokenPinErrorLabel error_label, void RequestPinView::SetErrorMessage(SecurityTokenPinErrorLabel error_label,
int attempts_left) { int attempts_left,
bool accept_input) {
base::string16 error_message; base::string16 error_message;
switch (error_label) { switch (error_label) {
case SecurityTokenPinErrorLabel::kInvalidPin: case SecurityTokenPinErrorLabel::kInvalidPin:
...@@ -253,17 +255,25 @@ void RequestPinView::SetErrorMessage(SecurityTokenPinErrorLabel error_label, ...@@ -253,17 +255,25 @@ void RequestPinView::SetErrorMessage(SecurityTokenPinErrorLabel error_label,
break; break;
} }
if (attempts_left >= 0) { base::string16 display_message;
if (!error_message.empty()) if (!accept_input) {
error_message.append(base::ASCIIToUTF16(" ")); display_message = error_message;
error_message.append(l10n_util::GetStringFUTF16( } else if (attempts_left == -1) {
IDS_REQUEST_PIN_DIALOG_ATTEMPTS_LEFT, display_message = l10n_util::GetStringFUTF16(
base::ASCIIToUTF16(std::to_string(attempts_left)))); IDS_REQUEST_PIN_DIALOG_ERROR_RETRY, error_message);
} else if (error_message.empty()) {
display_message =
l10n_util::GetStringFUTF16(IDS_REQUEST_PIN_DIALOG_ATTEMPTS_LEFT,
base::FormatNumber(attempts_left));
} else {
display_message = l10n_util::GetStringFUTF16(
IDS_REQUEST_PIN_DIALOG_ERROR_RETRY_ATTEMPTS, error_message,
base::FormatNumber(attempts_left));
} }
error_label_->SetVisible(true); error_label_->SetVisible(true);
error_label_->SetText(error_message); error_label_->SetText(display_message);
error_label_->SetTooltipText(error_message); error_label_->SetTooltipText(display_message);
error_label_->SetEnabledColor(gfx::kGoogleRed600); error_label_->SetEnabledColor(gfx::kGoogleRed600);
error_label_->SizeToPreferredSize(); error_label_->SizeToPreferredSize();
textfield_->SetInvalid(true); textfield_->SetInvalid(true);
......
...@@ -93,7 +93,8 @@ class RequestPinView final : public views::DialogDelegateView, ...@@ -93,7 +93,8 @@ class RequestPinView final : public views::DialogDelegateView,
void Init(); void Init();
void SetAcceptInput(bool accept_input); void SetAcceptInput(bool accept_input);
void SetErrorMessage(SecurityTokenPinErrorLabel error_label, void SetErrorMessage(SecurityTokenPinErrorLabel error_label,
int attempts_left); int attempts_left,
bool accept_input);
// Updates the header text |header_label_| based on values from // Updates the header text |header_label_| based on values from
// |window_title_| and |code_type_|. // |window_title_| and |code_type_|.
void UpdateHeaderText(); void UpdateHeaderText();
......
...@@ -27,26 +27,14 @@ ...@@ -27,26 +27,14 @@
<div slot="footer"> <div slot="footer">
<div id="pinKeyboardContainer"> <div id="pinKeyboardContainer">
<pin-keyboard id="pinKeyboard" enable-letters <pin-keyboard id="pinKeyboard" enable-letters
has-error="[[hasError_(parameters, userEdited_)]]" has-error="[[isErrorLabelVisible_(errorLabelId_, userEdited_)]]"
aria-label$="[[getAriaLabel_(locale, parameters, errorLabelId_, aria-invalid$="[[isAriaInvalid_(parameters, userEdited_)]]"
userEdited_)]]"
on-pin-change="onPinChange_" on-submit="onSubmit_" on-pin-change="onPinChange_" on-submit="onSubmit_"
disabled="[[!canSubmit_]]"> disabled="[[!canSubmit_]]">
<div id="errorContainer" problem <div id="errorContainer" role="alert" problem
hidden="[[!hasError_(parameters, userEdited_)]]"> hidden$="[[!isLabelVisible_(parameters, userEdited_)]]">
<iron-icon id="errorIcon" icon="cr:error-outline"></iron-icon> <iron-icon id="errorIcon" icon="cr:error-outline"></iron-icon>
<span hidden="[[!isErrorLabelVisible_( [[getLabel_(locale, parameters, errorLabelId_, userEdited_)]]
errorLabelId_, userEdited_)]]">
[[i18nDynamic(locale, errorLabelId_)]]
</span>
<span hidden="[[!isErrorLabelVisible_(
errorLabelId_, userEdited_)]]">
[[i18nDynamic(locale, 'securityTokenPinDialogTryAgain')]]
</span>
<span hidden="[[!isAttemptsLeftVisible_(parameters)]]">
[[i18nDynamic(locale, 'securityTokenPinDialogAttemptsLeft',
parameters.attemptsLeft)]]
</span>
</div> </div>
</pin-keyboard> </pin-keyboard>
</div> </div>
......
...@@ -146,31 +146,28 @@ Polymer({ ...@@ -146,31 +146,28 @@ Polymer({
}, },
/** /**
* Returns whether an error message should be displayed to the user. * Returns whether the error label should be shown.
* @param {OobeTypes.SecurityTokenPinDialogParameters} parameters * @param {OobeTypes.SecurityTokenPinDialogParameters} parameters
* @param {boolean} userEdited * @param {boolean} userEdited
* @return {boolean} * @return {boolean}
* @private * @private
*/ */
hasError_: function(parameters, userEdited) { isErrorLabelVisible_: function(parameters, userEdited) {
if (!parameters) return parameters &&
return false; parameters.errorLabel !==
if (parameters.attemptsLeft != -1)
return true;
return parameters.errorLabel !=
OobeTypes.SecurityTokenPinDialogErrorType.NONE && OobeTypes.SecurityTokenPinDialogErrorType.NONE &&
!userEdited; !userEdited;
}, },
/** /**
* Returns whether the error label should be shown. * Returns a string for a11y whether there is an error.
* @param {string} errorLabelId * @param {OobeTypes.SecurityTokenPinDialogParameters} parameters
* @param {boolean} userEdited * @param {boolean} userEdited
* @return {boolean} * @return {string}
* @private * @private
*/ */
isErrorLabelVisible_: function(errorLabelId, userEdited) { isAriaInvalid_: function(parameters, userEdited) {
return errorLabelId && !userEdited; return this.isErrorLabelVisible_(parameters, userEdited) ? 'true' : 'false';
}, },
/** /**
...@@ -184,7 +181,19 @@ Polymer({ ...@@ -184,7 +181,19 @@ Polymer({
}, },
/** /**
* Returns the aria label to be used for the PIN input field. * Returns whether there is a visible label for the PIN input field
* @param {OobeTypes.SecurityTokenPinDialogParameters} parameters
* @param {boolean} userEdited
* @return {boolean}
* @private
*/
isLabelVisible_: function(parameters, userEdited) {
return this.isErrorLabelVisible_(parameters, userEdited) ||
this.isAttemptsLeftVisible_(parameters);
},
/**
* Returns the label to be used for the PIN input field.
* @param {string} locale * @param {string} locale
* @param {OobeTypes.SecurityTokenPinDialogParameters} parameters * @param {OobeTypes.SecurityTokenPinDialogParameters} parameters
* @param {string} errorLabelId * @param {string} errorLabelId
...@@ -192,18 +201,24 @@ Polymer({ ...@@ -192,18 +201,24 @@ Polymer({
* @return {string} * @return {string}
* @private * @private
*/ */
getAriaLabel_: function(locale, parameters, errorLabelId, userEdited) { getLabel_: function(locale, parameters, errorLabelId, userEdited) {
var pieces = []; if (!this.isLabelVisible_(parameters, userEdited)) {
if (this.isErrorLabelVisible_(errorLabelId, userEdited)) { return '';
pieces.push(this.i18n(errorLabelId)); }
pieces.push(this.i18n('securityTokenPinDialogTryAgain')); if (!this.isErrorLabelVisible_(parameters, userEdited) &&
this.isAttemptsLeftVisible_(parameters)) {
return this.i18n(
'securityTokenPinDialogAttemptsLeft', parameters.attemptsLeft);
}
if (parameters && !parameters.enableUserInput) {
return this.i18n(errorLabelId);
} }
if (this.isAttemptsLeftVisible_(parameters)) { if (!this.isAttemptsLeftVisible_(parameters)) {
pieces.push(this.i18n( return this.i18nRecursive(
'securityTokenPinDialogAttemptsLeft', parameters.attemptsLeft)); locale, 'securityTokenPinDialogErrorRetry', errorLabelId);
} }
// Note: The language direction is not taken into account here, since the return this.i18n(
// order of pieces follows the reading order. 'securityTokenPinDialogErrorRetryAttempts', this.i18n(errorLabelId),
return pieces.join(' '); parameters.attemptsLeft);
}, },
}); });
...@@ -671,6 +671,10 @@ void GaiaScreenHandler::DeclareLocalizedValues( ...@@ -671,6 +671,10 @@ void GaiaScreenHandler::DeclareLocalizedValues(
IDS_SAML_SECURITY_TOKEN_PIN_DIALOG_TRY_AGAIN); IDS_SAML_SECURITY_TOKEN_PIN_DIALOG_TRY_AGAIN);
builder->Add("securityTokenPinDialogAttemptsLeft", builder->Add("securityTokenPinDialogAttemptsLeft",
IDS_REQUEST_PIN_DIALOG_ATTEMPTS_LEFT); IDS_REQUEST_PIN_DIALOG_ATTEMPTS_LEFT);
builder->Add("securityTokenPinDialogErrorRetry",
IDS_REQUEST_PIN_DIALOG_ERROR_RETRY);
builder->Add("securityTokenPinDialogErrorRetryAttempts",
IDS_REQUEST_PIN_DIALOG_ERROR_RETRY_ATTEMPTS);
builder->Add("securityTokenPinDialogUnknownError", builder->Add("securityTokenPinDialogUnknownError",
IDS_REQUEST_PIN_DIALOG_UNKNOWN_ERROR); IDS_REQUEST_PIN_DIALOG_UNKNOWN_ERROR);
builder->Add("securityTokenPinDialogUnknownInvalidPin", builder->Add("securityTokenPinDialogUnknownInvalidPin",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment