Fixed T usage in ValidationRules, round 2.

This commit is contained in:
Sipke Schoorstra
2015-10-16 10:45:08 +02:00
parent a9abc294e3
commit 255547288b
7 changed files with 23 additions and 15 deletions

View File

@@ -1,5 +1,4 @@
using System;
using Orchard.DynamicForms.Helpers;
using Orchard.DynamicForms.Services;
using Orchard.DynamicForms.Services.Models;
using Orchard.Localization;
@@ -22,7 +21,9 @@ namespace Orchard.DynamicForms.ValidationRules {
}
private LocalizedString GetValidationMessage(ValidationContext context) {
return new LocalizedString(Tokenize(T(ErrorMessage.WithDefault(String.Format("{0} must match the value of {1}.", context.FieldName, TargetName))).ToString(), context));
return String.IsNullOrWhiteSpace(ErrorMessage)
? T("{0} must match the value of {1}.", context.FieldName, TargetName)
: new LocalizedString(Tokenize(ErrorMessage, context));
}
}
}

View File

@@ -28,7 +28,9 @@ namespace Orchard.DynamicForms.ValidationRules {
}
private LocalizedString GetValidationMessage(ValidationContext context) {
return new LocalizedString(Tokenize(T(ErrorMessage.WithDefault(String.Format("{0} is not a valid email address.", context.FieldName))).ToString(), context));
return String.IsNullOrWhiteSpace(ErrorMessage)
? T("{0} is not a valid email address.", context.FieldName)
: new LocalizedString(Tokenize(ErrorMessage, context));
}
}
}

View File

@@ -1,5 +1,4 @@
using System;
using Orchard.DynamicForms.Helpers;
using Orchard.DynamicForms.Services;
using Orchard.DynamicForms.Services.Models;
using Orchard.Localization;
@@ -18,7 +17,9 @@ namespace Orchard.DynamicForms.ValidationRules {
}
private LocalizedString GetValidationMessage(ValidationContext context) {
return new LocalizedString(Tokenize(T(ErrorMessage.WithDefault(String.Format("{0} is a mandatory field.", context.FieldName))).ToString(), context));
return String.IsNullOrWhiteSpace(ErrorMessage)
? T("{0} is a mandatory field.", context.FieldName)
: new LocalizedString(Tokenize(ErrorMessage, context));
}
}
}

View File

@@ -1,5 +1,4 @@
using System;
using Orchard.DynamicForms.Helpers;
using Orchard.DynamicForms.Services;
using Orchard.DynamicForms.Services.Models;
using Orchard.Localization;
@@ -18,7 +17,9 @@ namespace Orchard.DynamicForms.ValidationRules {
}
private LocalizedString GetValidationMessage(ValidationContext context) {
return new LocalizedString(Tokenize(T(ErrorMessage.WithDefault(String.Format("An option is required for {0}.", context.FieldName))).ToString(), context));
return String.IsNullOrWhiteSpace(ErrorMessage)
? T("An option is required for {0}.", context.FieldName)
: new LocalizedString(Tokenize(ErrorMessage, context));
}
}
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Text.RegularExpressions;
using Orchard.DynamicForms.Helpers;
using Orchard.DynamicForms.Services;
using Orchard.DynamicForms.Services.Models;
using Orchard.Localization;
@@ -27,7 +26,9 @@ namespace Orchard.DynamicForms.ValidationRules {
}
private LocalizedString GetValidationMessage(ValidationContext context) {
return new LocalizedString(Tokenize(T(ErrorMessage.WithDefault(String.Format("{0} must match the following pattern: {1}.", context.FieldName, Pattern))).ToString(), context));
return String.IsNullOrWhiteSpace(ErrorMessage)
? T("{0} must match the following pattern: {1}.", context.FieldName, Pattern)
: new LocalizedString(Tokenize(ErrorMessage, context));
}
}
}

View File

@@ -1,5 +1,4 @@
using System;
using Orchard.DynamicForms.Helpers;
using Orchard.DynamicForms.Services;
using Orchard.DynamicForms.Services.Models;
using Orchard.Localization;
@@ -18,7 +17,9 @@ namespace Orchard.DynamicForms.ValidationRules {
}
private LocalizedString GetValidationMessage(ValidationContext context) {
return new LocalizedString(Tokenize(T(ErrorMessage.WithDefault(String.Format("{0} is a required field.", context.FieldName))).ToString(), context));
return String.IsNullOrWhiteSpace(ErrorMessage)
? T("{0} is a required field.", context.FieldName)
: new LocalizedString(Tokenize(ErrorMessage, context));
}
}
}

View File

@@ -40,12 +40,13 @@ namespace Orchard.DynamicForms.ValidationRules {
}
private LocalizedString GetValidationMessage(ValidationContext context) {
if (!String.IsNullOrWhiteSpace(ErrorMessage))
return new LocalizedString(Tokenize(String.Format(T(ErrorMessage).ToString(), context.FieldName, Minimum, Maximum), context));
if(!String.IsNullOrWhiteSpace(ErrorMessage))
return new LocalizedString(Tokenize(String.Format(ErrorMessage, context.FieldName, Minimum, Maximum), context));
if(Minimum != null && Maximum != null)
if (Minimum != null && Maximum != null)
return T("{0} must be between {1} and {2} characters long.", context.FieldName, Minimum, Maximum);
else if (Minimum != null)
if (Minimum != null)
return T("{0} must be at least {1} characters long.", context.FieldName, Minimum);
return T("{0} must be at most {1} characters long.", context.FieldName, Maximum);