Skip to content

Instantly share code, notes, and snippets.

@schotime
Created June 20, 2012 02:00
Show Gist options
  • Save schotime/2957702 to your computer and use it in GitHub Desktop.
Save schotime/2957702 to your computer and use it in GitHub Desktop.
FluentValidation Localization Adapter
public class FluentValidationKeys : StringToken
{
public static StringToken CREDITCARD_ERROR = new FluentValidationKeys("'{PropertyName}' is not a valid credit card number.");
public static StringToken EMAIL_ERROR = new FluentValidationKeys("'{PropertyName}' is not a valid email address.");
public static StringToken EQUAL_ERROR = new FluentValidationKeys("'{PropertyName}' should be equal to '{PropertyValue}'.");
public static StringToken EXACT_LENGTH_ERROR = new FluentValidationKeys("'{PropertyName}' must be {MaxLength} characters in length. You entered {TotalLength} characters.");
public static StringToken EXCLUSIVEBETWEEN_ERROR = new FluentValidationKeys("'{PropertyName}' must be between {From} and {To} (exclusive). You entered {Value}.");
public static StringToken GREATERTHAN_ERROR = new FluentValidationKeys("'{PropertyName}' must be greater than '{ComparisonValue}'.");
public static StringToken GREATERTHANOREQUAL_ERROR = new FluentValidationKeys("'{PropertyName}' must be greater than or equal to '{ComparisonValue}'.");
public static StringToken INCLUSIVEBETWEEN_ERROR = new FluentValidationKeys("'{PropertyName}' must be between {From} and {To}. You entered {Value}.");
public static StringToken LENGTH_ERROR = new FluentValidationKeys("'{PropertyName}' must be between {MinLength} and {MaxLength} characters. You entered {TotalLength} characters.");
public static StringToken LESSTHAN_ERROR = new FluentValidationKeys("'{PropertyName}' must be less than '{ComparisonValue}'.");
public static StringToken LESSTHANOREQUAL_ERROR = new FluentValidationKeys("'{PropertyName}' must be less than or equal to '{ComparisonValue}'.");
public static StringToken NOTEMPTY_ERROR = new FluentValidationKeys("'{PropertyName}' should not be empty.");
public static StringToken NOTNULL_ERROR = new FluentValidationKeys("'{PropertyName}' must not be empty.");
public static StringToken NOTEQUAL_ERROR = new FluentValidationKeys("'{PropertyName}' should not be equal to '{PropertyValue}'.");
public static StringToken PREDICATE_ERROR = new FluentValidationKeys("The specified condition was not met for '{PropertyName}'.");
public static StringToken REGEX_ERROR = new FluentValidationKeys("'{PropertyName}' is not in the correct format.");
protected FluentValidationKeys(string defaultValue) : base(null, defaultValue)
{
}
}
public class FluentValidationLocalisationAdapter
{
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; is not a valid credit card number..
/// </summary>
public static StringToken CreditCardError
{
get { return FluentValidationKeys.CREDITCARD_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; is not a valid email address..
/// </summary>
public static StringToken email_error
{
get { return FluentValidationKeys.EMAIL_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; should be equal to &apos;{PropertyValue}&apos;..
/// </summary>
public static StringToken equal_error
{
get { return FluentValidationKeys.EQUAL_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; must be {MaxLength} characters in length. You entered {TotalLength} characters..
/// </summary>
public static StringToken exact_length_error
{
get { return FluentValidationKeys.EXACT_LENGTH_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; must be between {From} and {To} (exclusive). You entered {Value}..
/// </summary>
public static StringToken exclusivebetween_error
{
get { return FluentValidationKeys.EXCLUSIVEBETWEEN_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; must be greater than &apos;{ComparisonValue}&apos;..
/// </summary>
public static StringToken greaterthan_error
{
get { return FluentValidationKeys.GREATERTHAN_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; must be greater than or equal to &apos;{ComparisonValue}&apos;..
/// </summary>
public static StringToken greaterthanorequal_error
{
get { return FluentValidationKeys.GREATERTHANOREQUAL_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; must be between {From} and {To}. You entered {Value}..
/// </summary>
public static StringToken inclusivebetween_error
{
get { return FluentValidationKeys.INCLUSIVEBETWEEN_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; must be between {MinLength} and {MaxLength} characters. You entered {TotalLength} characters..
/// </summary>
public static StringToken length_error
{
get { return FluentValidationKeys.LENGTH_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; must be less than &apos;{ComparisonValue}&apos;..
/// </summary>
public static StringToken lessthan_error
{
get { return FluentValidationKeys.LESSTHAN_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; must be less than or equal to &apos;{ComparisonValue}&apos;..
/// </summary>
public static StringToken lessthanorequal_error
{
get { return FluentValidationKeys.LESSTHANOREQUAL_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; should not be empty..
/// </summary>
public static StringToken notempty_error
{
get { return FluentValidationKeys.NOTEMPTY_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; should not be equal to &apos;{PropertyValue}&apos;..
/// </summary>
public static StringToken notequal_error
{
get { return FluentValidationKeys.NOTEQUAL_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; must not be empty..
/// </summary>
public static StringToken notnull_error
{
get { return FluentValidationKeys.NOTNULL_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to The specified condition was not met for &apos;{PropertyName}&apos;..
/// </summary>
public static StringToken predicate_error
{
get { return FluentValidationKeys.PREDICATE_ERROR; }
}
/// <summary>
/// Looks up a localized string similar to &apos;{PropertyName}&apos; is not in the correct format..
/// </summary>
public static StringToken regex_error
{
get { return FluentValidationKeys.REGEX_ERROR; }
}
}
protected void Application_Start()
{
ValidatorOptions.ResourceProviderType = typeof(FluentValidationLocalisationAdapter);
}
@veyselozdemir
Copy link

what is StringToken class here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment