1
+ from faker import Faker
2
+ from faker .config import AVAILABLE_LOCALES
1
3
from .en_KE import Provider as EnKeProvider
2
4
from .lo_LA import Provider as LoLaProvider
3
5
from .si_LK import Provider as SiLkProvider
6
8
7
9
8
10
def get_faker_provider (lang ):
11
+ """
12
+ The function `get_faker_provider` returns a provider based on the language code provided.
13
+
14
+ :param lang: The `get_faker_provider` function takes a language code as input and returns the
15
+ corresponding provider class based on the language. The language codes and their corresponding
16
+ provider classes are as follows:
17
+ :return: The function `get_faker_provider` returns a provider class based on the language code
18
+ provided as an argument. If the language code matches one of the supported languages ("en_KE",
19
+ "lo_LA", "si_LK", "sw_KE", "ta_LK"), it returns the corresponding provider class. Otherwise, it
20
+ returns `None`.
21
+ """
9
22
if lang == "en_KE" :
10
23
return EnKeProvider
11
24
if lang == "lo_LA" :
@@ -17,3 +30,26 @@ def get_faker_provider(lang):
17
30
if lang == "ta_LK" :
18
31
return TaLkProvider
19
32
return None
33
+
34
+
35
+ def create_faker (lang ):
36
+ """
37
+ The function `create_faker` creates a Faker object with a specified language locale and adds a
38
+ custom provider if available.
39
+
40
+ :param lang: The `lang` parameter is used to specify the language/locale for which you want to
41
+ create a Faker instance. The function checks if the specified language is in the list of available
42
+ locales (`AVAILABLE_LOCALES`). If it is, it creates a Faker instance with that locale. If the
43
+ specified language is
44
+ :return: An instance of the Faker class with the specified locale and additional provider if
45
+ available.
46
+ """
47
+ locale = lang if lang in AVAILABLE_LOCALES else None
48
+ fake = Faker (locale = locale )
49
+
50
+ if lang and lang not in AVAILABLE_LOCALES :
51
+ provider = get_faker_provider (lang )
52
+ if provider :
53
+ fake .add_provider (provider )
54
+
55
+ return fake
0 commit comments