-
Notifications
You must be signed in to change notification settings - Fork 0
/
translations.py
70 lines (64 loc) · 1.4 KB
/
translations.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json,os,random
version="0.1"
global langstrings
langstrings=None
def checklang(lang):
if lang=="eng":
return "Already english."
elif os.path.isfile("langs/"+lang+".json"):
f=open("langs/"+lang+".json","r")
checking=json.loads(f.read())
f.close()
f=open("langs/eng.json","r")
default=json.loads(f.read())
f.close()
changedsome=False
for e in default:
if not e in checking:
checking[e]=default[e]
changedsome=True
else:
if type(default[e])==type({}):
if type(checking[e])!=type({}):
checking[e]=default[e]
changedsome=True
else:
for sube in default[e]:
if not sube in checking[e]:
checking[e][sube]=default[e][sube]
changedsome=True
#if changedsome:
# f=open("langs/"+lang+".json","w")
# f.write(json.dumps(checking,indent=4))
# f.close()
#return "Ok."
return checking
else:
return "Error: not found."
def setlang(lang):
global langstrings
if os.path.isfile("langs/"+lang+".json"):
chkl=checklang(lang)
if type(chkl)==str:
f=open("langs/"+lang+".json","r")
langstrings=json.loads(f.read())
f.close()
else:
langstrings=chkl
return "Ok."
else:
return "Error: not found."
def getstr(*path):
o=langstrings
for e in path:
o=o[e]
if type(o)==type([]):
o=random.choice(o)
return o
def getraw(*path):
o=langstrings
for e in path:
o=o[e]
return o