File size: 790 Bytes
fb83c5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import logging
import os

localizationMap = {}


def load_localizations():
    localizationMap.clear()
    dirname = "./localizations"
    for file in os.listdir(dirname):
        fn, ext = os.path.splitext(file)
        if ext.lower() != ".json":
            continue
        localizationMap[fn] = os.path.join(dirname, file)


def load_language_js(language_name: str) -> str:
    fn = localizationMap.get(language_name, None)
    data = {}
    if fn is not None:
        try:
            with open(fn, "r", encoding="utf-8") as file:
                data = json.load(file)
        except Exception:
            logging.ERROR(f"Error loading localization from {fn}")

    return f"window.localization = {json.dumps(data)}"


load_localizations()