Skip to content

Instantly share code, notes, and snippets.

@LazZiya
Created November 4, 2020 09:32
Show Gist options
  • Save LazZiya/c6f02c91c46748b8b0fd62a23a32512d to your computer and use it in GitHub Desktop.
Save LazZiya/c6f02c91c46748b8b0fd62a23a32512d to your computer and use it in GitHub Desktop.
XLocalizer options to customize defatul error messages inline
services.AddRazorPages()
.AddXLocalizer<...>(ops =>
{
// ...
ops.ValidationErrors = new ValidationErrors
{
RequiredAttribute_ValidationError = "The {0} field is required.",
CompareAttribute_MustMatch = "'{0}' and '{1}' do not match.",
StringLengthAttribute_ValidationError = "The field {0} must be a string with a maximum length of {1}.",
// ...
};
ops.ModelBindingErrors = new ModelBindingErrors
{
AttemptedValueIsInvalidAccessor = "The value '{0}' is not valid for {1}.",
MissingBindRequiredValueAccessor = "A value for the '{0}' parameter or property was not provided.",
MissingKeyOrValueAccessor = "A value is required.",
// ...
};
ops.IdentityErrors = new IdentityErrors
{
DuplicateEmail = "Email '{0}' is already taken.",
DuplicateUserName = "User name '{0}' is already taken.",
InvalidEmail = "Email '{0}' is invalid.",
// ...
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment