-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslation.py
More file actions
38 lines (27 loc) · 1.2 KB
/
Copy pathTranslation.py
File metadata and controls
38 lines (27 loc) · 1.2 KB
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
31
32
33
34
35
36
37
38
from typing import Self, Set
class Translation:
def __init__(self, việt: str, eng: str, category: str) -> None:
if not (việt and eng and category):
raise ValueError(f'args:[{việt}, {eng}, {category}] cannot be have falsy.')
struct_pattern: str = '...'
self.việt: str = việt
self.engTranslations: Set[str] = {eng}
self.categories: Set[str] = {category}
self.isStructure: bool = struct_pattern in việt
def add(self, other: Self) -> None:
if self != other:
raise ValueError(f"Cannot add translations: ${self.việt} + {other.việt}")
self.engTranslations |= other.engTranslations
self.categories |= other.categories
def __str__(self) -> str:
return f"\n{self.việt} {self.categories}: {self.engTranslations}"
def __repr__(self) -> str:
return self.__str__()
def __eq__(self, other: object):
if isinstance(other, Translation):
return self.việt == other.việt
return False
def add_eng(self, eng: str) -> None:
self.engTranslations.add(eng)
def add_category(self, category: str) -> None:
self.categories.add(category)