Skip to content

Commit a570c4e

Browse files
authored
Merge pull request #1 from MajAhd/fea-farsi
Fea farsi
2 parents e0e884e + 57b6258 commit a570c4e

File tree

7 files changed

+460
-4
lines changed

7 files changed

+460
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
***
44

5+
## V0.3.3
6+
7+
- Support Farsi language
8+
9+
***
10+
511
## V0.3.2
612

713
- Support Deutsch language

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,15 @@ rules = {
3535
"first_name": ["required", "string", "max:128"]
3636
}
3737

38+
# by default return messages in English
3839
PyValidations.make(data, rules)
3940

41+
# get error messages in Deutsch language
42+
PyValidations.make(data, rules , "de")
43+
44+
# get error messages in Farsi language
45+
PyValidations.make(data, rules , "fa")
46+
4047
```
4148

4249
## Documentation

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='PyValidations',
5-
version='0.3.2',
5+
version='0.3.3',
66
author='Majid Ahmaditabar',
77
keywords='validation, data_validator , python_validator ,PyValidations',
88
author_email='mjd.ahd.tbr@gmail.com',

src/pyvalidations/factory/bind_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ def build(self, rule, lang="en"):
2121
message = Languages(lang) \
2222
.set_key(self.__key) \
2323
.set_value(self.__value) \
24-
.messages()[lang]
24+
.messages()[lang.lower()]
2525
return message[rule]

src/pyvalidations/lang/fa.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
class Fa:
2+
"""
3+
Validation Exception message in English
4+
:param attribute : name of validation target
5+
:param value : value of attribute
6+
"""
7+
8+
def __init__(self, attribute, value):
9+
self.attribute = attribute
10+
self.value = value
11+
12+
def messages(self):
13+
"""
14+
validation messages
15+
:return: dict
16+
"""
17+
return {
18+
"field": f"فیلد {self.attribute} وجود ندارد",
19+
"required": f" فیلد {self.attribute} الزامی است.",
20+
"required_if": f" وقتی {self.value} وجود داشته باشد، فیلد {self.attribute} مورد نیاز است.",
21+
"required_unless": f"فیلد {self.attribute} مورد نیاز است مگر اینکه {self.value} وجود نداشته باشد یا خالی باشد.",
22+
"required_with": f"فیلد {self.attribute} زمانی لازم است که {self.value} وجود داشته باشد.",
23+
"required_without": f"فیلد {self.attribute} زمانی لازم است که {self.value} موجود باشد/نیست.",
24+
"accepted": f"{self.attribute} باید پذیرفته شود.",
25+
"alpha": f"{self.attribute} باید فقط دارای حروف باشد.",
26+
"boolean": f"مقدار {self.attribute} باید: true، false، 1 یا 0 باشد.",
27+
"string": f"{self.attribute}باید از نوع متنی باشد. ",
28+
"start_with": f"{self.attribute} باید با {self.value} شروع شود.",
29+
"end_with": f"{self.attribute} باید با {self.value} ختم شود.",
30+
"numeric": f"{self.attribute} باید یک عدد باشد. ",
31+
"digits": f"{self.attribute} باید رقم {self.value} باشد.",
32+
"max": f"{self.attribute} نباید بزرگتر از {self.value} باشد. ",
33+
"min": f"{self.attribute} باید حداقل {self.value} باشد. ",
34+
"email": f"{self.attribute} باید یک آدرس ایمیل معتبر باشد. ",
35+
"url": f"{self.attribute} باید یک آدرس URL معتبر باشد.",
36+
"ip": f"{self.attribute} باید یک آدرس IP معتبر باشد. ",
37+
"ipv4": f"{self.attribute} باید یک آدرس IPv4 معتبر باشد.",
38+
"ipv6": f"{self.attribute} باید یک آدرس IPv6 معتبر باشد.",
39+
"in": f"{self.attribute} انتخاب شده نامعتبر است. ",
40+
"not_in": f"{self.attribute} انتخاب شده نامعتبر است.",
41+
"uuid": f"{self.attribute} باید یک UUID معتبر باشد.",
42+
"date": f"{self.attribute} تاریخ معتبری نیست. ",
43+
"time": f"{self.attribute} زمان معتبری نیست.",
44+
"datetime": f"{self.attribute} تاریخ معتبری نیست.",
45+
"timezone": f"{self.attribute} یک منطقه زمانی معتبر نیست. ",
46+
"date_equals": f"{self.attribute} باید تاریخی برابر با {self.value} باشد. ",
47+
"after": f"{self.attribute} باید تاریخ بعد از {self.value} باشد.",
48+
"after_or_equal": f"{self.attribute} باید تاریخ بعد یا برابر با {self.value} باشد.",
49+
"before": f"{self.attribute} باید تاریخ قبل از {self.value} باشد.",
50+
"before_or_equal": f"{self.attribute} باید تاریخ قبل یا برابر با {self.value} باشد.",
51+
"different": f"{self.attribute} باید با {self.value} متفاوت باشد.",
52+
"equal": f"{self.attribute} باید برابر با {self.value} باشد.",
53+
"gt": f"{self.attribute} باید بزرگتر از {self.value} باشد.",
54+
"gte": f"{self.attribute} باید بزرگتر یا مساوی با {self.value} باشد.",
55+
"lt": f"{self.attribute} باید کمتر از {self.value} باشد. ",
56+
"lte": f"{self.attribute} باید کمتر یا برابر با {self.value} باشد.",
57+
"confirmed": f"تأیید {self.attribute} مطابقت ندارد.",
58+
"nullable": f"{self.attribute} می تواند تهی باشد.",
59+
"file": f"{self.attribute} باید یک فایل باشد.",
60+
"mimes": f"{self.attribute} باید فایلی از نوع: {self.value} باشد.",
61+
"mime_types": f"{self.attribute} باید فایلی از نوع: {self.value} باشد.",
62+
"max_size": f"{self.attribute} نباید بیشتر از {self.value} کیلوبایت باشد.",
63+
"min_size": f"{self.attribute} باید حداقل {self.value} کیلوبایت باشد.",
64+
}

src/pyvalidations/lang/language.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .en import En
22
from .de import De
3+
from .fa import Fa
34

45

56
class Languages:
@@ -10,7 +11,7 @@ class Languages:
1011
__value = None
1112

1213
def __init__(self, lang_name="en"):
13-
self.lang_name = lang_name
14+
self.lang_name = lang_name.lower()
1415

1516
def set_key(self, key):
1617
"""
@@ -34,5 +35,6 @@ def messages(self):
3435
"""
3536
return {
3637
"en": En(self.__key, self.__value).messages(),
37-
"de": De(self.__key, self.__value).messages()
38+
"de": De(self.__key, self.__value).messages(),
39+
"fa": Fa(self.__key, self.__value).messages(),
3840
}

0 commit comments

Comments
 (0)