Skip to content

Translate errors #1163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public void onChanged(Resource<String> resource) {
// No FirebaseUser exists with this email address, show error.
mEmailInputLayout.setError(getString(R.string.fui_error_email_does_not_exist));
} else {
mEmailInputLayout.setError(resource.getException().getLocalizedMessage());
// Unknown error
mEmailInputLayout.setError(getString(R.string.fui_error_unknown));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;
import android.support.annotation.StringRes;
import android.support.design.widget.TextInputLayout;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
Expand Down Expand Up @@ -137,19 +138,19 @@ private void onSignInOperation(@Nullable Resource<IdpResponse> resource) {
break;
case FAILURE:
getDialogHolder().dismissDialog();
String message = getErrorMessage(resource.getException());
String message = getString(getErrorMessage(resource.getException()));
mPasswordLayout.setError(message);
break;
}
}

private String getErrorMessage(Exception exception) {
@StringRes
private int getErrorMessage(Exception exception) {
if (exception instanceof FirebaseAuthInvalidCredentialsException) {
// TODO: Add translated "wrong password" message
return exception.getLocalizedMessage();
return R.string.fui_error_invalid_password;
}

return exception.getLocalizedMessage();
return R.string.fui_error_unknown;
}

private void onForgotPasswordClicked() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void onFailure(@NonNull Exception e) {
}

private void finishWithError(Exception e) {
Toast.makeText(this, R.string.fui_general_error, Toast.LENGTH_LONG).show();
Toast.makeText(this, R.string.fui_error_unknown, Toast.LENGTH_LONG).show();
finish(RESULT_CANCELED, IdpResponse.getErrorIntent(e));
}

Expand Down
25 changes: 14 additions & 11 deletions auth/src/main/java/com/firebase/ui/auth/ui/phone/PhoneActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;
import android.support.annotation.StringRes;
import android.support.annotation.VisibleForTesting;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
Expand Down Expand Up @@ -221,18 +222,18 @@ private void onVerificationFailed(@NonNull FirebaseException ex) {
}
break;
case ERROR_TOO_MANY_REQUESTS:
showAlertDialog(getString(R.string.fui_error_too_many_attempts), null);
showAlertDialog(R.string.fui_error_too_many_attempts, null);
break;
case ERROR_QUOTA_EXCEEDED:
showAlertDialog(getString(R.string.fui_error_quota_exceeded), null);
showAlertDialog(R.string.fui_error_quota_exceeded, null);
break;
default:
Log.w(PHONE_VERIFICATION_LOG_TAG, error.getDescription(), ex);
showAlertDialog(error.getDescription(), null);
showAlertDialog(R.string.fui_error_unknown, null);
}
} else {
Log.w(PHONE_VERIFICATION_LOG_TAG, ex.getLocalizedMessage());
showAlertDialog(ex.getLocalizedMessage(), null);
Log.w(PHONE_VERIFICATION_LOG_TAG, "Unknown error", ex);
showAlertDialog(R.string.fui_error_unknown, null);
}
}

Expand Down Expand Up @@ -305,8 +306,10 @@ private void finish(FirebaseUser user) {
finish(RESULT_OK, response.toIntent());
}

private void showAlertDialog(@NonNull String s, DialogInterface.OnClickListener
onClickListener) {
private void showAlertDialog(@StringRes int messageId,
DialogInterface.OnClickListener onClickListener) {

String s = getString(messageId);
mAlertDialog = new AlertDialog.Builder(this)
.setMessage(s)
.setPositiveButton(R.string.fui_incorrect_code_dialog_positive_button_text, onClickListener)
Expand Down Expand Up @@ -346,7 +349,7 @@ public void onFailure(@NonNull Exception e) {
switch (error) {
case ERROR_INVALID_VERIFICATION_CODE:
showAlertDialog(
getString(R.string.fui_incorrect_code_dialog_body),
R.string.fui_incorrect_code_dialog_body,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand All @@ -357,7 +360,7 @@ public void onClick(DialogInterface dialog, int which) {
break;
case ERROR_SESSION_EXPIRED:
showAlertDialog(
getString(R.string.fui_error_session_expired),
R.string.fui_error_session_expired,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand All @@ -368,10 +371,10 @@ public void onClick(DialogInterface dialog, int which) {
break;
default:
Log.w(PHONE_VERIFICATION_LOG_TAG, error.getDescription(), e);
showAlertDialog(error.getDescription(), null);
showAlertDialog(R.string.fui_error_unknown, null);
}
} else {
showAlertDialog(e.getLocalizedMessage(), null);
showAlertDialog(R.string.fui_error_unknown, null);
}
}
});
Expand Down
Loading