-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlangmgr.py
40 lines (34 loc) · 1.07 KB
/
langmgr.py
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
39
40
import csv
import sqlcplants
class Language:
def __init__(self, lang):
self.lang = lang
self.dict = {}
if self.lang != "en":
self.read_dict_from_csv()
self.read_dict_from_db()
def read_dict_from_csv(self):
with open(f"{self.lang}.csv", newline='', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile, delimiter=';')
for row in reader:
self.dict[row[0]] = row[1]
def read_dict_from_db(self):
dict2 = sqlcplants.getDictionary()
self.dict.update(dict2)
def get(self, key):
if self.lang != "en":
val = self.dict.get(key)
if val == None:
val = "*" + key
else:
val = key
return val
def rget(self, value):
#print("value in rget:"+value)
if self.lang != "en":
for k, v in self.dict.items():
if v == value:
return k
return "*" + value
else:
return value