mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Support multilingual error messages
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9232 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
43f146f40f
commit
ee5487d1f4
1 changed files with 31 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Validator class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
*/
|
||||
class Validator
|
||||
{
|
||||
|
|
@ -380,7 +381,11 @@ class Validator
|
|||
if(!is_dir($dir) && !mkdir($dir)) return false;
|
||||
if(!$this->_xml_path) return false;
|
||||
|
||||
$filepath = $dir.'/'.md5($this->_version.' '.$this->_xml_path).'.js';
|
||||
// current language
|
||||
$lang_type = class_exists('Context')?Context::getLangType():'en';
|
||||
|
||||
// check the file
|
||||
$filepath = $dir.'/'.md5($this->_version.' '.$this->_xml_path).".{$lang_type}.js";
|
||||
if(is_readable($filepath) && filemtime($filepath) > filemtime($this->_xml_path)) return $filepath;
|
||||
|
||||
$content = $this->_compile2js();
|
||||
|
|
@ -404,11 +409,16 @@ class Validator
|
|||
* @private
|
||||
*/
|
||||
function _compile2js() {
|
||||
global $lang;
|
||||
|
||||
$ruleset = basename($this->_xml_path,'.xml');
|
||||
$content = array();
|
||||
|
||||
if(preg_match('@(^|/)files/ruleset/\w+\.xml$@i', $this->_xml_path)) $ruleset = '@'.$ruleset;
|
||||
|
||||
// current language
|
||||
$lang_type = class_exists('Context')?Context::getLangType():'en';
|
||||
|
||||
// custom rulesets
|
||||
$addrules = array();
|
||||
foreach($this->_rules as $name=>$rule) {
|
||||
|
|
@ -429,10 +439,17 @@ class Validator
|
|||
$addrules = implode('', $addrules);
|
||||
|
||||
// filters
|
||||
$content = array();
|
||||
$content = array();
|
||||
$messages = array();
|
||||
foreach($this->_filters as $name=>$filter) {
|
||||
$field = array();
|
||||
|
||||
// form filed name
|
||||
if(isset($lang->{$name})) {
|
||||
$field_lang = addslashes($lang->{$name});
|
||||
$messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);";
|
||||
}
|
||||
|
||||
if($filter['required'] == 'true') $field[] = 'required:true';
|
||||
if($filter['rule']) $field[] = "rule:'{$filter['rule']}'";
|
||||
if($filter['default']) $field[] = "default:'{$filter['default']}'";
|
||||
|
|
@ -456,13 +473,20 @@ class Validator
|
|||
}
|
||||
}
|
||||
|
||||
if(count($content)) {
|
||||
$content = implode(',', $content);
|
||||
if(!$content) return '/* Error : empty ruleset */';
|
||||
|
||||
return "(function($,v){\nv=xe.getApp('validator')[0];if(!v)return;\n{$addrules}\nv.cast('ADD_FILTER',['{$ruleset}', {{$content}}]);\n})(jQuery);";
|
||||
} else {
|
||||
return '';
|
||||
// error messages
|
||||
foreach($lang->filter as $key=>$text) {
|
||||
if($text) {
|
||||
$text = addslashes($text);
|
||||
$messages[] = "v.cast('ADD_MESSAGE',['{$key}','{$text}']);";
|
||||
}
|
||||
}
|
||||
|
||||
$content = implode(',', $content);
|
||||
$messages = implode("\n", $messages);
|
||||
|
||||
return "(function($,v){\nv=xe.getApp('validator')[0];if(!v)return;\n{$addrules}\nv.cast('ADD_FILTER',['{$ruleset}', {{$content}}]);\n{$messages} // Hello\n})(jQuery);";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue