Add support for localization lookup
This commit is contained in:
parent
28f3d7e6cb
commit
41a32accfd
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
import json
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -10,6 +11,10 @@ app = Flask(__name__)
|
|||||||
app.config["MONGO_URI"] = os.environ["MONGO_URI"]
|
app.config["MONGO_URI"] = os.environ["MONGO_URI"]
|
||||||
mongo = PyMongo(app)
|
mongo = PyMongo(app)
|
||||||
|
|
||||||
|
LOCALIZATION_JSON = {}
|
||||||
|
with open("./db_explorer/en.json") as f:
|
||||||
|
LOCALIZATION_JSON = json.load(f)
|
||||||
|
|
||||||
@app.template_filter('filter_vtt')
|
@app.template_filter('filter_vtt')
|
||||||
def filter_vtt(text):
|
def filter_vtt(text):
|
||||||
compendium_re = re.compile(r"@Compendium\[([^\]]+)\]\{([^\}]+)\}")
|
compendium_re = re.compile(r"@Compendium\[([^\]]+)\]\{([^\}]+)\}")
|
||||||
@ -20,8 +25,19 @@ def filter_vtt(text):
|
|||||||
if m.group('alt') is not None:
|
if m.group('alt') is not None:
|
||||||
return m.group('alt')
|
return m.group('alt')
|
||||||
return m.group('sdice')
|
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 = compendium_re.sub(compendium_return, text)
|
||||||
text = macro_re.sub(macro_return, text)
|
text = macro_re.sub(macro_return, text)
|
||||||
|
text = localize_re.sub(localize_return, text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
|
4563
db_explorer/db_explorer/en.json
Normal file
4563
db_explorer/db_explorer/en.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user