Skip to content

Commit 3495e5c

Browse files
authored
Support for both chronicles.json and submod with various json files aswell
1 parent a48ab98 commit 3495e5c

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

.github/update.py

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,69 @@ def get_translation_mods():
8989
def get_translation_mods_translation():
9090
translation_mods = get_translation_mods()
9191
data = {}
92+
9293
for key, value in translation_mods.items():
94+
print(f"\n--- Processing language: {key} ---")
9395
tmp = {}
96+
chronicles_found = False
97+
9498
for item in value[1]["translations"]:
9599
base_url = value[0].rsplit('/', 1)[0] + "/content/"
100+
print(f"Checking base translation file: {base_url + item}")
101+
96102
try:
97103
tmp_str = urllib.request.urlopen(base_url + item).read()
98-
except:
99-
tmp_str = urllib.request.urlopen((base_url + item).replace("content", "Content").replace("config", "Config")).read()
100-
104+
except Exception as e:
105+
print(f"Error reading {base_url + item}: {e}")
106+
continue
107+
101108
if "chronicles.json" in item:
109+
print(f"Found chronicles.json in: {base_url + item}")
102110
chronicles_data = load_vcmi_json(tmp_str)
103111
prefixed_chronicles = {f"chronicles.{k}": v for k, v in chronicles_data.items()}
104112
tmp |= prefixed_chronicles
113+
chronicles_found = True
105114
else:
106115
tmp |= load_vcmi_json(tmp_str)
116+
117+
if not chronicles_found:
118+
try:
119+
repo_url_parts = value[0].split("/")
120+
repo_owner = repo_url_parts[3]
121+
repo_name = repo_url_parts[4]
122+
branch_name = repo_url_parts[5]
123+
api_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/git/trees/{branch_name}?recursive=1"
124+
125+
print(f"Fetching repo structure from: {api_url}")
126+
response = urllib.request.urlopen(api_url).read()
127+
repo_files = json5.loads(response)["tree"]
128+
129+
chronicles_json_files = [
130+
f["path"] for f in repo_files
131+
if "chronicles" in f["path"]
132+
and f["path"].endswith(".json")
133+
and "video" not in f["path"].lower()
134+
and not f["path"].endswith("mod.json")
135+
]
136+
137+
print(f"Found chronicles JSON files: {chronicles_json_files}")
138+
139+
for json_file in chronicles_json_files:
140+
json_file_url = f"https://raw.githubusercontent.com/{repo_owner}/{repo_name}/{branch_name}/{json_file}"
141+
print(f"Fetching JSON file: {json_file_url}")
142+
143+
try:
144+
tmp_str = urllib.request.urlopen(json_file_url).read()
145+
chronicles_data = load_vcmi_json(tmp_str)
146+
prefixed_chronicles = {f"chronicles.{k}": v for k, v in chronicles_data.items()}
147+
tmp |= prefixed_chronicles
148+
except Exception as e:
149+
print(f"Error reading JSON file {json_file_url}: {e}")
150+
except Exception as e:
151+
print(f"Error processing chronicles JSON files for {key}: {e}")
152+
107153
data[key] = tmp
154+
108155
return data
109156

110157
def get_translation_mods_translation_assets():

0 commit comments

Comments
 (0)