-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactory.py
More file actions
30 lines (24 loc) · 844 Bytes
/
Copy pathfactory.py
File metadata and controls
30 lines (24 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class GreekTranslator:
def __init__(self) -> None:
self.translations = {"hello": "Χαίρετε"}
def translate(self, word: str) -> str:
return self.translations.get(word, word)
class EnglishTranslator:
def __init__(self) -> None:
self.translations = {"hello": "engligh_hello"}
def translate(self, word: str) -> str:
return self.translations.get(word, word)
def get_translator(lang="English") -> object:
translators = {"English": EnglishTranslator, "Greek": GreekTranslator}
return translators[lang]()
def main():
"""
>>> e, g = get_translator(lang="English"), get_translator(lang="Greek")
>>> e.translate(word="hello")
'engligh_hello'
>>> g.translate(word="hello")
'Χαίρετε'
"""
if __name__=='__main__':
import doctest
doctest.testmod()