From 3665bd1916d5169377587c142985db30eb475e80 Mon Sep 17 00:00:00 2001 From: bim-g Date: Wed, 29 Dec 2021 22:45:07 +0200 Subject: [PATCH] [FEAT][TRA] add tranlate class module --- .idea/php.xml | 7 ++++++- .idea/wepesi_validation.iml | 7 ++++++- composer.json | 4 +++- index.php | 1 + lang/en/language.php | 4 ++++ lang/fr/language.php | 10 +++++++++ .../configs/wepesi_validation.properties | 0 nbproject/project.properties | 20 ------------------ nbproject/project.xml | 10 --------- shared/global.php | 5 +++++ src/Escape.php | 21 +++++++++++++++++++ src/VString.php | 14 ++++++------- test/index.php | 4 ++-- 13 files changed, 65 insertions(+), 42 deletions(-) create mode 100644 lang/en/language.php create mode 100644 lang/fr/language.php delete mode 100644 nbproject/configs/wepesi_validation.properties delete mode 100644 nbproject/project.properties delete mode 100644 nbproject/project.xml create mode 100644 shared/global.php create mode 100644 src/Escape.php diff --git a/.idea/php.xml b/.idea/php.xml index f6159c8..3b1bcf5 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -1,4 +1,9 @@ - + + + + + + \ No newline at end of file diff --git a/.idea/wepesi_validation.iml b/.idea/wepesi_validation.iml index c956989..1ee89a6 100644 --- a/.idea/wepesi_validation.iml +++ b/.idea/wepesi_validation.iml @@ -1,7 +1,12 @@ - + + + + + + diff --git a/composer.json b/composer.json index 938fc09..609da5c 100644 --- a/composer.json +++ b/composer.json @@ -18,5 +18,7 @@ "Wepesi\\app\\":"src/" } }, - "require": {} + "require": { + "php": ">=7.4" + } } diff --git a/index.php b/index.php index 160ad47..4ae3eb2 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ "hello" +]; \ No newline at end of file diff --git a/lang/fr/language.php b/lang/fr/language.php new file mode 100644 index 0000000..e89a9fd --- /dev/null +++ b/lang/fr/language.php @@ -0,0 +1,10 @@ +"`%s` doit avoir un minimum de `%s` caracteres", + "`%s` should have maximum of `%s` caracters"=>"`%s` doit avoir un maximum de `%s` caracteres", + "`%s` this should be an email"=>"`%s` doit etre un email", + "`%s` this should be a link(url)"=>"`%s` doit avoir un lien(url) ", + "`%s` should match %s"=>"`%s` doit correpondre a `%s`", + "`%s` is required"=>"`%s` est obligatoire", + "`%s` should be a string"=>"`%s` doit est une chaine de caractere", +]; \ No newline at end of file diff --git a/nbproject/configs/wepesi_validation.properties b/nbproject/configs/wepesi_validation.properties deleted file mode 100644 index e69de29..0000000 diff --git a/nbproject/project.properties b/nbproject/project.properties deleted file mode 100644 index f83c2b3..0000000 --- a/nbproject/project.properties +++ /dev/null @@ -1,20 +0,0 @@ -auxiliary.org-netbeans-modules-css-prep.less_2e_compiler_2e_options= -auxiliary.org-netbeans-modules-css-prep.less_2e_enabled=false -auxiliary.org-netbeans-modules-css-prep.less_2e_mappings=/less:/css -auxiliary.org-netbeans-modules-css-prep.sass_2e_compiler_2e_options= -auxiliary.org-netbeans-modules-css-prep.sass_2e_enabled=false -auxiliary.org-netbeans-modules-css-prep.sass_2e_mappings=/scss:/css -auxiliary.org-netbeans-modules-javascript2-requirejs.enabled=true -auxiliary.org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder=js/libs -browser.reload.on.save=true -code.analysis.excludes= -ignore.path= -include.path=\ - ${php.global.include.path} -php.version=PHP_73 -source.encoding=UTF-8 -src.dir=. -tags.asp=false -tags.short=false -testing.providers= -web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml deleted file mode 100644 index af5763e..0000000 --- a/nbproject/project.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - org.netbeans.modules.php.project - - - wepesi_validation - - - - diff --git a/shared/global.php b/shared/global.php new file mode 100644 index 0000000..ef606ef --- /dev/null +++ b/shared/global.php @@ -0,0 +1,5 @@ +0){ + $key_value=!isset($language[$message])?null:$language[$message]; + $message_key=$key_value!=null?vsprintf($key_value,$data):vsprintf($message,$data); + } + return $message_key; + } +} \ No newline at end of file diff --git a/src/VString.php b/src/VString.php index bf0730f..ec0d62c 100644 --- a/src/VString.php +++ b/src/VString.php @@ -43,7 +43,7 @@ function min(int $rule_values=0){ if (strlen($this->string_value) < $min) { $message=[ "type"=>"string.min", - "message"=> "`{$this->string_item}` should have minimum of `{$min}` caracters", + "message"=> i18n::translate("`%s` should have minimum of `%s` caracters",[$this->string_item,$min]), "label"=>$this->string_item, "limit"=>$min ]; @@ -62,7 +62,7 @@ function max(int $rule_values=1){ if (strlen($this->string_value) > $max) { $message = [ "type" => "string.max", - "message" => "`{$this->string_item}` should have maximum of `{$max}` caracters", + "message" => i18n::translate("`%s` should have maximum of `%s` caracters",[$this->string_item,$max]), "label" => $this->string_item, "limit" => $max ]; @@ -78,7 +78,7 @@ function email(){ if (!filter_var($this->string_value, FILTER_VALIDATE_EMAIL)) { $message = [ "type" => "string.email", - "message" => "`{$this->string_item}` this should be an email", + "message" => i18n::translate("`%s` this should be an email",[$this->string_item]), "label" => $this->string_item, ]; $this->addError($message); @@ -93,7 +93,7 @@ function url(){ if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $this->string_value)) { $message = [ "type" => "string.url", - "message" => "`{$this->string_item}` this shoudl be a link(url)", + "message" => i18n::translate("`{$this->string_item}` this should be a link(url)"), "label" => $this->string_item, ]; $this->addError($message); @@ -110,7 +110,7 @@ function match(string $key_tomatch){ if (isset($this->source_data[$key_tomatch]) && (strlen($this->string_value)!= strlen($this->source_data[$key_tomatch])) && ($this->string_value!=$this->source_data[$key_tomatch])) { $message = [ "type" => "string.match", - "message" => "`{$this->string_item}` should match {$key_tomatch}", + "message" => i18n::translate("`%s` should match %s",[$this->string_item,$key_tomatch]), "label" => $this->string_item, ]; $this->addError($message); @@ -122,7 +122,7 @@ function required(){ if (empty($required_value)) { $message = [ "type"=> "any.required", - "message" => "`{$this->string_item}` is required", + "message" => i18n::translate("`%s` is required",[$this->string_item]), "label" => $this->string_item, ]; $this->addError($message); @@ -149,7 +149,7 @@ private function checkExist(string $itemKey=null){ }else if(!preg_match($regex,$this->source_data[$item_to_check]) || strlen(trim($this->source_data[$item_to_check]))==0){ $message=[ "type" => "string.unknow", - "message" => "`{$item_to_check}` shoud be a s tring", + "message" => i18n::translate("`%s` should be a string",[$item_to_check]), "label" => $item_to_check, ]; $this->addError($message); diff --git a/test/index.php b/test/index.php index e1b6107..aaa4e86 100644 --- a/test/index.php +++ b/test/index.php @@ -16,7 +16,7 @@ "date_created"=>"2021-05-23" ]; $valid=new Validate($source); -// include "./test/string.php"; + include "./test/string.php"; // include "./test/number.php"; // include "./test/boolean.php"; - include "./test/date.php"; +// include "./test/date.php";