Skip to content
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

full globalization for default validation messages #40

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 14 additions & 1 deletion ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ component{
// setup shared constraints
wirebox.getInstance( "validationManager@cbvalidation" )
.setSharedConstraints( configSettings.validation.sharedConstraints );
i18n = {
defaultLocale = "en_US",
localeStorage = "cookie",
// Extra resource bundles to load
resourceBundles = {
cbvalidation = configSettings.validation.cbi18nResourcePath
}
};
}

/**
Expand Down Expand Up @@ -94,13 +102,18 @@ component{
// Default Config Structure
configStruct.validation = {
manager = this.COLDBOX_VALIDATION_MANAGER,
sharedConstraints = {}
sharedConstraints = {},
cbi18nResourcePath = "#moduleMapping#/resources/i18n/cbvalidation"
};

// manager
if( structKeyExists( validationDSL, "manager" ) ){
configStruct.validation.manager = validationDSL.manager;
}
// manager
if( structKeyExists( validationDSL, "cbi18nResourcePath" ) ){
configStruct.validation.cbi18nResourcePath = validationDSL.cbi18nResourcePath;
}
// shared constraints
if( structKeyExists( validationDSL, "sharedConstraints" ) ){
structAppend( configStruct.validation.sharedConstraints, validationDSL.sharedConstraints, true );
Expand Down
4 changes: 3 additions & 1 deletion models/result/ValidationResult.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ component accessors="true" {
* @return IValidationResult
*/
any function addError( required error ){
// always replace because default messages are globalized
globalReplacements( arguments.error.getMessage(), error );
// Verify Custom Messages via constraints, these take precedence
if( structKeyExists( constraints, error.getField() ) AND structKeyExists( constraints[error.getField()], "#error.getValidationType()#Message" ) ){
// override message with custom constraint
Expand Down Expand Up @@ -163,7 +165,7 @@ component accessors="true" {
// The validation type
arguments.message = replacenocase( arguments.message, "{validationType}", arguments.error.getValidationType(), "all");
// The validation data
if( arguments.error.getValidationType() neq 'UDF' ){
if( !ListFindNocase("UDF,RequiredIf,RequiredUnless,Unique", arguments.error.getValidationType()) ){
arguments.message = replacenocase( arguments.message, "{validationData}", arguments.error.getValidationData(), "all");
}
// The target name of the object
Expand Down
3 changes: 2 additions & 1 deletion models/validators/AcceptedValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -42,7 +43,7 @@ component accessors="true" singleton {
}

var args = {
message : "The '#arguments.field#' is not a 1, yes, true or on",
message : resourceService.getResource("default.Accepted@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/AlphaValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -42,7 +43,7 @@ component accessors="true" singleton {
}

var args = {
message : "The '#arguments.field#' is not alpha only",
message : resourceService.getResource("default.Alpha@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/DiscreteValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -86,7 +87,7 @@ component accessors="true" singleton {

if ( !r ) {
var args = {
message : "The '#arguments.field#' value is #operation# than #operationValue#",
message : resourceService.getResource( resource = "default.Discrete@cbvalidation", values = { operation = operation, operationValue = operationValue } ),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/InListValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -42,7 +43,7 @@ component accessors="true" singleton {
}

var args = {
message : "The '#arguments.field#' value is not in the constraint list: #arguments.validationData#",
message : resourceService.getResource("default.InList@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/MaxValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -42,7 +43,7 @@ component accessors="true" singleton {
}

var args = {
message : "The '#arguments.field#' value is not less than or equal to #arguments.validationData#",
message : resourceService.getResource("default.Max@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/MethodValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -45,7 +46,7 @@ component accessors="true" singleton {
}

var args = {
message : "The '#arguments.field#' value does not validate",
message : resourceService.getResource("default.Method@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/MinValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -42,7 +43,7 @@ component accessors="true" singleton {
}

var args = {
message : "The '#arguments.field#' value is not greater than or equal to #arguments.validationData#",
message :resourceService.getResource("default.Min@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/RangeValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -62,7 +63,7 @@ component accessors="true" singleton {
return true;
}
var args = {
message : "The '#arguments.field#' value is not the value field range (#arguments.validationData#)",
message : resourceService.getResource("default.Range@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/RegexValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -42,7 +43,7 @@ component accessors="true" singleton {
}

var args = {
message : "The '#arguments.field#' value does not match the regular expression: #arguments.validationData#",
message : resourceService.getResource("default.Regex@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/RequiredIfValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
component accessors="true" extends="RequiredValidator" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -67,7 +68,7 @@ component accessors="true" extends="RequiredValidator" singleton {

// No data, fail it
var args = {
message : "The '#arguments.field#' value is required",
message : resourceService.getResource("default.RequiredIf@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isNull( arguments.targetValue ) ? "NULL" : isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/RequiredUnlessValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
component accessors="true" extends="RequiredValidator" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -68,7 +69,7 @@ component accessors="true" extends="RequiredValidator" singleton {

// No data, fail it
var args = {
message : "The '#arguments.field#' value is required",
message : resourceService.getResource("default.RequiredUnless@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isNull( arguments.targetValue ) ? "NULL" : isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/RequiredValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -51,7 +52,7 @@ component accessors="true" singleton {

// No data, fail it
var args = {
message : "The '#arguments.field#' value is required",
message : resourceService.getResource("default.Required@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isNull( arguments.targetValue ) ? "NULL" : isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/SameAsNoCaseValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -50,7 +51,7 @@ component accessors="true" singleton {
}

var args = {
message : "The '#arguments.field#' value is not the same as #compareValue.toString()#",
message : resourceService.getResource( resource = "default.SameAsNoCase@cbvalidation", values = { compareValue = compareValue.toString() } ),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/SameAsValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -44,7 +45,7 @@ component accessors="true" singleton {
return true;
}
var args = {
message : "The '#arguments.field#' value is not the same as #compareValue.toString()#",
message : resourceService.getResource( resource = "default.SameAs@cbvalidation", values = { compareValue = compareValue.toString() } ),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/SizeValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -91,7 +92,7 @@ component accessors="true" singleton {
}
}
var args = {
message : "The '#arguments.field#' value is not in the required size range (#arguments.validationData#)",
message : resourceService.getResource("default.Size@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
5 changes: 3 additions & 2 deletions models/validators/TypeValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -36,7 +37,7 @@ component accessors="true" singleton {
// check incoming type
if ( !reFindNoCase( "^(#replace( variables.validTypes, ",", "|", "all" )#)$", arguments.validationData ) ) {
throw(
message = "The type you sent is invalid: #arguments.validationData#",
message = resourceService.getResource("default.Type@cbvalidation"),
detail = "Valid types are #variables.validTypes#",
type = "TypeValidator.InvalidValidationData"
);
Expand Down Expand Up @@ -155,7 +156,7 @@ component accessors="true" singleton {

if ( !r ) {
var args = {
message : "The '#arguments.field#' has an invalid type, expected type is #arguments.validationData#",
message : resourceService.getResource("default.Type@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
Expand Down
3 changes: 2 additions & 1 deletion models/validators/UDFValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -42,7 +43,7 @@ component accessors="true" singleton {
}

var args = {
message : "The '#arguments.field#' value does not validate",
message : resourceService.getResource("default.UDF@cbvalidation"),
field : arguments.field,
validationType : getName(),
rejectedValue : !isNull( arguments.targetValue ) && isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "",
Expand Down
4 changes: 2 additions & 2 deletions models/validators/UniqueValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
component accessors="true" singleton {

property name="name";
property name="resourceService" inject="ResourceService@cbi18n";

/**
* Constructor
Expand Down Expand Up @@ -49,14 +50,13 @@ component accessors="true" singleton {
validationResult.addError(
validationResult.newError(
argumentCollection = {
message : "The #targetColumn# '#arguments.targetValue#' is already in use",
message : resourceService.getResource( resource = "default.Unique@cbvalidation", values = { targetColumn = targetColumn, targetValue = targetValue } ),
field : arguments.field,
validationType : getName(),
validationData : arguments.validationData
}
)
);

return false;
}

Expand Down
20 changes: 20 additions & 0 deletions resources/i18n/cbValidation_en_US.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)

default.Accepted = The '{field}' is not a 1, yes, true or on
default.Alpha = The '{field}' is not alpha only
default.Discrete = The '{field}' value is {operation} than {operationValue}
default.InList = The '{field}' value is not in the constraint list: {validationData}
default.Max = The '{field}' value is not less than or equal to {validationData}
default.Method = The '{field}' value does not validate
default.Min = The '{field}' value is not greater than or equal to {validationData}
default.Range = The '{field}' value is not the value field range ({validationData})
default.Regex = The '{field}' value does not match the regular expression: {validationData}
default.Required = The '{field}' value is required
default.RequiredIf = The '{field}' value is required
default.RequiredUnless = The '{field}' value is required
default.SameAs = The '{field}' value is not the same as {compareValue}
default.SameAsNoCase = The '{field}' value is not the same as {compareValue}
default.Size = The '{field}' value is not in the required size range ({validationData})
default.Type = The '{field}' has an invalid type, expected type is {validationData}
default.UDF = The '{field}' value does not validate
default.Unique = The {targetColumn} '{targetValue}' is already in use
Loading