@@ -89,22 +89,69 @@ def get_translation_mods():
89
89
def get_translation_mods_translation ():
90
90
translation_mods = get_translation_mods ()
91
91
data = {}
92
+
92
93
for key , value in translation_mods .items ():
94
+ print (f"\n --- Processing language: { key } ---" )
93
95
tmp = {}
96
+ chronicles_found = False
97
+
94
98
for item in value [1 ]["translations" ]:
95
99
base_url = value [0 ].rsplit ('/' , 1 )[0 ] + "/content/"
100
+ print (f"Checking base translation file: { base_url + item } " )
101
+
96
102
try :
97
103
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
+
101
108
if "chronicles.json" in item :
109
+ print (f"Found chronicles.json in: { base_url + item } " )
102
110
chronicles_data = load_vcmi_json (tmp_str )
103
111
prefixed_chronicles = {f"chronicles.{ k } " : v for k , v in chronicles_data .items ()}
104
112
tmp |= prefixed_chronicles
113
+ chronicles_found = True
105
114
else :
106
115
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
+
107
153
data [key ] = tmp
154
+
108
155
return data
109
156
110
157
def get_translation_mods_translation_assets ():
0 commit comments