forked from bmaltais/kohya_ss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalization.py
More file actions
31 lines (23 loc) · 757 Bytes
/
localization.py
File metadata and controls
31 lines (23 loc) · 757 Bytes
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
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="utf8") 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()