Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
9f09af4a
Commit
9f09af4a
authored
Jul 22, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add better language support to Validator.
parent
341908d7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
4 deletions
+24
-4
system/validator.php
+24
-4
No files found.
system/validator.php
View file @
9f09af4a
...
@@ -31,6 +31,13 @@ class Validator {
...
@@ -31,6 +31,13 @@ class Validator {
public
$errors
;
public
$errors
;
/**
/**
* The language that should be used when retrieving error messages.
*
* @var string
*/
public
$lang
;
/**
* The "size" related validation rules.
* The "size" related validation rules.
*
*
* @var array
* @var array
...
@@ -425,15 +432,15 @@ class Validator {
...
@@ -425,15 +432,15 @@ class Validator {
}
}
else
else
{
{
$message
=
Lang
::
line
(
'validation.'
.
$rule
)
->
get
();
$message
=
Lang
::
line
(
'validation.'
.
$rule
)
->
get
(
$this
->
language
);
// For "size" rules that are validating strings or files, we need to adjust
// For "size" rules that are validating strings or files, we need to adjust
// the default error message appropriately.
// the default error message appropriately.
if
(
in_array
(
$rule
,
$this
->
size_rules
)
and
!
is_numeric
(
$this
->
attributes
[
$attribute
]))
if
(
in_array
(
$rule
,
$this
->
size_rules
)
and
!
is_numeric
(
$this
->
attributes
[
$attribute
]))
{
{
return
(
array_key_exists
(
$attribute
,
$_FILES
))
return
(
array_key_exists
(
$attribute
,
$_FILES
))
?
rtrim
(
$message
,
'.'
)
.
' '
.
Lang
::
line
(
'validation.kilobytes'
)
->
get
()
.
'.'
?
rtrim
(
$message
,
'.'
)
.
' '
.
Lang
::
line
(
'validation.kilobytes'
)
->
get
(
$this
->
language
)
.
'.'
:
rtrim
(
$message
,
'.'
)
.
' '
.
Lang
::
line
(
'validation.characters'
)
->
get
()
.
'.'
;
:
rtrim
(
$message
,
'.'
)
.
' '
.
Lang
::
line
(
'validation.characters'
)
->
get
(
$this
->
language
)
.
'.'
;
}
}
return
$message
;
return
$message
;
...
@@ -451,7 +458,7 @@ class Validator {
...
@@ -451,7 +458,7 @@ class Validator {
*/
*/
protected
function
format_message
(
$message
,
$attribute
,
$rule
,
$parameters
)
protected
function
format_message
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
{
$display
=
Lang
::
line
(
'attributes.'
.
$attribute
)
->
get
(
null
,
function
()
use
(
$attribute
)
{
return
str_replace
(
'_'
,
' '
,
$attribute
);
});
$display
=
Lang
::
line
(
'attributes.'
.
$attribute
)
->
get
(
$this
->
language
,
function
()
use
(
$attribute
)
{
return
str_replace
(
'_'
,
' '
,
$attribute
);
});
$message
=
str_replace
(
':attribute'
,
$display
,
$message
);
$message
=
str_replace
(
':attribute'
,
$display
,
$message
);
...
@@ -504,4 +511,16 @@ class Validator {
...
@@ -504,4 +511,16 @@ class Validator {
return
array
(
is_numeric
(
$colon
)
?
substr
(
$rule
,
0
,
$colon
)
:
$rule
,
$parameters
);
return
array
(
is_numeric
(
$colon
)
?
substr
(
$rule
,
0
,
$colon
)
:
$rule
,
$parameters
);
}
}
/**
* Set the language that should be used when retrieving error messages.
*
* @param string $langauge
* @return Validator
*/
public
function
lang
(
$language
)
{
$this
->
language
=
$language
;
return
$this
;
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment