Skip to content

Commit

Permalink
working translator
Browse files Browse the repository at this point in the history
  • Loading branch information
amitkhare committed Sep 27, 2017
1 parent 250bf68 commit 8e53e09
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ if(!$v->isValid()){
> alphanumUnicode
> unique (avaiable only if instantiate EasyValidation With Database Details);
## TODO:
> Support for multiple locales
> Support for multiple locales : DONE
> Support for single field check like setField() in addition with setSource()
5 changes: 2 additions & 3 deletions src/EasyValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ private function connect($host="localhost",$username="root",$password="",$dbname
$mysqli = new \mysqli($host,$username,$password,$dbname);
/* check connection */
if (mysqli_connect_errno()) {
$this->setStatus(500,sprintf("Database Error: %s.", mysqli_connect_error()));
$this->setStatus(500, $this->translate("DB_ERROR",mysqli_connect_error()));
$this->isConnected=false;
} else {
$this->dbConn = $mysqli;
$this->isConnected=true;
}
}
private function translate($keyString,$fields=null){
private function translate($keyString,$fields=null) {
return Translator::translate($keyString,$fields,$this->locale,$this->localePath);
}
public function match($field1="",$field2="",$rules=[]){
Expand All @@ -88,7 +88,6 @@ public function match($field1="",$field2="",$rules=[]){
}

if($this->source[$field1] != $this->source[$field2]){
$string = "The `%s` field doesn't match with `%s`.";
$status = $this->translate("FIELDS_DONT_MATCH",[$field1,$field2]);
$this->setStatus(500,$status);
}
Expand Down
31 changes: 31 additions & 0 deletions src/locales/hi-IN.1.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{

"FIELDS_DONT_MATCH" : "`%s` और `%s` एक-दूसरे से मेल नहीं खाते.",
"FIELD_REQUIRED" : "`%s` ज़रूरी है.",
"FIELD_NOT_SET" : " `%s` फील्ड खली है.",
"FIELD_INVALID_IPV4": "`%s` फील्ड गलत IPv4 एड्रेस है.",
"FIELD_INVALID_IPV6": "`%s` फील्ड गलत IPv6 एड्रेस है.",
"FIELD_INVALID_FLOAT" : "`%s` फील्ड फ्लोट नहीं है.",
"FIELD_INVALID_STRING" : "`%s` फील्ड स्ट्रिंग नहीं है.",
"FIELD_INVALID_ALPHA" : "`%s` फील्ड अल्फाबेटिक [a-z,A-Z] वैल्यू नहीं है.",
"FIELD_INVALID_ALPHA_NUMERIC" : "`%s` फील्ड अल्फानुमेरिक [a-z,A-Z,0-9] वैल्यू नहीं है.",
"FIELD_INVALID_ALPHA_NUMERIC_UNICODE" : "The `%s` field is an invalid alpha-numerical-unicode value.",
"FIELD_INVALID_NUMERIC" : "The `%s` field is not a numeric value.",
"FIELD_INVALID_URL" : "The `%s` field is an invalid URL.",
"FIELD_INVALID_EMAIL" : "The `%s` field is an invalid email.",
"FIELD_INVALID_BOOLEAN" : "The `%s` field is not a boolean.",
"FIELD_VALUE_ALREADY_EXISTS" : "The `%s` field value already exists in database.",
"DB_NOT_CONNECTED" : "Database not connected. Database related rules will be unavailable. Can not apply `unique.%s` rule.",
"FIELD_VALUE_TOO_LONG" : "The `%s` field value is too long, it should not more than `%s` characters.",
"FIELD_VALUE_TOO_SHORT" : "The `%s` field value is too short, it should be at least `%s` characters long.",

"USERNAME":"यूजरनेम",
"FIRSTNAME":"प्रथम नाम",
"LASTNAME":"उप नाम",
"MIDDLENAME":"मध्य नाम",
"EMAIL":"ईमेल",
"PASSWORD":"पासवर्ड",
"MOBILE":"मोबाइल",
"PASSWORD_CONFIRM":"पासवर्ड कन्फर्म"

}
18 changes: 9 additions & 9 deletions src/locales/hi-IN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"FIELD_NOT_SET" : " `%s` फील्ड खली है.",
"FIELD_INVALID_IPV4": "`%s` फील्ड गलत IPv4 एड्रेस है.",
"FIELD_INVALID_IPV6": "`%s` फील्ड गलत IPv6 एड्रेस है.",
"FIELD_INVALID_FLOAT" : "The `%s` field is an invalid float.",
"FIELD_INVALID_STRING" : "The `%s` field is an invalid .",
"FIELD_INVALID_ALPHA" : "The `%s` field is an invalid alphabetical value.",
"FIELD_INVALID_ALPHA_NUMERIC" : "The `%s` field is an invalid alpha-numerical value.",
"FIELD_INVALID_ALPHA_NUMERIC_UNICODE" : "The `%s` field is an invalid alpha-numerical-unicode value.",
"FIELD_INVALID_NUMERIC" : "The `%s` field is not a numeric value.",
"FIELD_INVALID_URL" : "The `%s` field is an invalid URL.",
"FIELD_INVALID_EMAIL" : "The `%s` field is an invalid email.",
"FIELD_INVALID_BOOLEAN" : "The `%s` field is not a boolean.",
"FIELD_INVALID_FLOAT" : "`%s` में सिर्फ फ्लोट वैल्यू मान्य हैं.",
"FIELD_INVALID_STRING" : "`%s` में सिर्फ स्ट्रिंग वैल्यू मान्य हैं.",
"FIELD_INVALID_ALPHA" : "`%s` में सिर्फ अल्फाबेटिक [a-z,A-Z] वैल्यू मान्य हैं.",
"FIELD_INVALID_ALPHA_NUMERIC" : "`%s` में सिर्फ अल्फानुमेरिक [a-z,A-Z,0-9] वैल्यू मान्य हैं.",
"FIELD_INVALID_ALPHA_NUMERIC_UNICODE" : "`%s` में सिर्फ अल्फानुमेरिक+यूनिकोड [a-z,A-Z,0-9,+Unicode] वैल्यू मान्य हैं.",
"FIELD_INVALID_NUMERIC" : "`%s` फील्ड में सिर्फ नुमेरिक [0-9] वैल्यू मान्य हैं.",
"FIELD_INVALID_URL" : "`%s` फील्ड में सिर्फ URL मान्य हैं.",
"FIELD_INVALID_EMAIL" : "`%s` फील्ड में सिर्फ ईमेल एड्रेस मान्य हैं.",
"FIELD_INVALID_BOOLEAN" : "`%s` फील्ड में सिर्फ बूलियन [true/false] मान्य हैं.",
"FIELD_VALUE_ALREADY_EXISTS" : "The `%s` field value already exists in database.",
"DB_NOT_CONNECTED" : "Database not connected. Database related rules will be unavailable. Can not apply `unique.%s` rule.",
"FIELD_VALUE_TOO_LONG" : "The `%s` field value is too long, it should not more than `%s` characters.",
Expand Down

0 comments on commit 8e53e09

Please sign in to comment.