it starts with two?
This commit is contained in:
parent
129e56c402
commit
b6993e430a
3 changed files with 54 additions and 0 deletions
BIN
gen_json.pmp
Normal file
BIN
gen_json.pmp
Normal file
Binary file not shown.
1
lang.json
Normal file
1
lang.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"v":"WL-0001","n":"wlang example.","l":{"en":{"ass":"English"},"lt":{"ass":"Lietuvių"}},"r":{"gb":"en","us":"en"},"d":"en"}
|
||||
53
wlang.py
Normal file
53
wlang.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import locale
|
||||
import json
|
||||
|
||||
# default language file
|
||||
langfile='lang.json'
|
||||
|
||||
# error and shit
|
||||
try:
|
||||
langfilecon=open(langfile).read()
|
||||
except:
|
||||
print('wlang error:Language file not found, continuing execution. Make sure to set the language file!')
|
||||
|
||||
# default language
|
||||
lang='en'
|
||||
deflangfull=locale.getdefaultlocale()[0]
|
||||
deflang=deflangfull[3:len(deflangfull)].lower()
|
||||
|
||||
# functions
|
||||
def setlangfile(lfile):
|
||||
global langfile
|
||||
global langfilecon
|
||||
langfile=lfile
|
||||
langfilecon=open(langfile).read()
|
||||
|
||||
def setlang(l):
|
||||
global lang
|
||||
lang=l
|
||||
|
||||
# get the d, n and v values
|
||||
def getlangname():
|
||||
return json.loads(langfilecon)["n"]
|
||||
|
||||
def getlangver():
|
||||
return json.loads(langfilecon)["v"]
|
||||
|
||||
def getinlangdef():
|
||||
return json.loads(langfilecon)["d"]
|
||||
|
||||
# the big one
|
||||
def getobj(obj):
|
||||
# get the thing
|
||||
try:
|
||||
return json.loads(langfilecon)["l"][lang][obj]
|
||||
except:
|
||||
# else use replaced
|
||||
try:
|
||||
return json.loads(langfilecon)["l"][json.loads(langfilecon)["r"][lang]][obj]
|
||||
except:
|
||||
# else use default
|
||||
try:
|
||||
return json.loads(langfilecon)["l"][json.loads(langfilecon)["d"]][obj]
|
||||
except:
|
||||
return f'Invalid-{lang}' # give up
|
||||
Loading…
Add table
Add a link
Reference in a new issue