Add support for localization lookup

This commit is contained in:
Michal Kunc 2021-11-18 17:59:38 +01:00
parent 28f3d7e6cb
commit 41a32accfd
Signed by: michal
GPG Key ID: 4CA5FB6559E0BDF8
2 changed files with 4579 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import json
import urllib.parse
import os
import re
@ -10,6 +11,10 @@ app = Flask(__name__)
app.config["MONGO_URI"] = os.environ["MONGO_URI"]
mongo = PyMongo(app)
LOCALIZATION_JSON = {}
with open("./db_explorer/en.json") as f:
LOCALIZATION_JSON = json.load(f)
@app.template_filter('filter_vtt')
def filter_vtt(text):
compendium_re = re.compile(r"@Compendium\[([^\]]+)\]\{([^\}]+)\}")
@ -20,8 +25,19 @@ def filter_vtt(text):
if m.group('alt') is not None:
return m.group('alt')
return m.group('sdice')
localize_re = re.compile(r"@Localize\[([^\]]+)\]")
def localize_return(m):
path = m.group(1)
output = LOCALIZATION_JSON
for chunk in path.split('.'):
output = output.get(chunk, {})
if type(output) != str:
output = f"[LOCALIZATION LOOKUP ERROR - {m.group(0)}]"
return output
# Template
text = compendium_re.sub(compendium_return, text)
text = macro_re.sub(macro_return, text)
text = localize_re.sub(localize_return, text)
return text
@app.route("/")

File diff suppressed because it is too large Load Diff