diff --git a/gen_json.pmp b/gen_json.pmp new file mode 100644 index 0000000..de5b4bb Binary files /dev/null and b/gen_json.pmp differ diff --git a/lang.json b/lang.json new file mode 100644 index 0000000..ecf6e79 --- /dev/null +++ b/lang.json @@ -0,0 +1 @@ +{"v":"WL-0001","n":"wlang example.","l":{"en":{"ass":"English"},"lt":{"ass":"Lietuvių"}},"r":{"gb":"en","us":"en"},"d":"en"} \ No newline at end of file diff --git a/wlang.py b/wlang.py new file mode 100644 index 0000000..e7050ec --- /dev/null +++ b/wlang.py @@ -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 \ No newline at end of file