From 8e53e09ee8718752eb507f2a9cbf195aa9f60fc0 Mon Sep 17 00:00:00 2001 From: Amit Kumar Khare Date: Wed, 27 Sep 2017 13:20:26 +0000 Subject: [PATCH] working translator --- README.md | 2 +- src/EasyValidation.php | 5 ++--- src/locales/hi-IN.1.lang | 31 +++++++++++++++++++++++++++++++ src/locales/hi-IN.lang | 18 +++++++++--------- 4 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 src/locales/hi-IN.1.lang diff --git a/README.md b/README.md index 15ca44b..48f34ec 100644 --- a/README.md +++ b/README.md @@ -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() diff --git a/src/EasyValidation.php b/src/EasyValidation.php index 11b6357..9939780 100644 --- a/src/EasyValidation.php +++ b/src/EasyValidation.php @@ -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=[]){ @@ -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); } diff --git a/src/locales/hi-IN.1.lang b/src/locales/hi-IN.1.lang new file mode 100644 index 0000000..e045db4 --- /dev/null +++ b/src/locales/hi-IN.1.lang @@ -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":"पासवर्ड कन्फर्म" + +} \ No newline at end of file diff --git a/src/locales/hi-IN.lang b/src/locales/hi-IN.lang index d0646bb..2750748 100644 --- a/src/locales/hi-IN.lang +++ b/src/locales/hi-IN.lang @@ -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.",