@@ -89,16 +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
- tmp |= load_vcmi_json (tmp_str )
104
+ except Exception as e :
105
+ print (f"Error reading { base_url + item } : { e } " )
106
+ continue
107
+
108
+ if "chronicles.json" in item :
109
+ print (f"Found chronicles.json in: { base_url + item } " )
110
+ chronicles_data = load_vcmi_json (tmp_str )
111
+ prefixed_chronicles = {f"chronicles.{ k } " : v for k , v in chronicles_data .items ()}
112
+ tmp |= prefixed_chronicles
113
+ chronicles_found = True
114
+ else :
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
+
101
153
data [key ] = tmp
154
+
102
155
return data
103
156
104
157
def get_translation_mods_translation_assets ():
@@ -132,7 +185,7 @@ def translation_mod_ratio(translation_mods_translation):
132
185
133
186
for language in [key for key , value in translation_mods_translation .items () if key != "english" ]:
134
187
data_ns = {}
135
- namespaces = [None , "map" , "campaign" ]
188
+ namespaces = [None , "map" , "campaign" , "chronicles" ]
136
189
for namespace in namespaces :
137
190
translation = translation_mods_translation [language ]
138
191
count_equal = 0
@@ -186,12 +239,18 @@ def get_mod_translations(languages):
186
239
for key , value in vcmi_mods .items ():
187
240
url = value ["mod" ].replace (" " , "%20" )
188
241
mod = load_vcmi_json (urllib .request .urlopen (url ).read ())
189
- if "language" not in mod :
190
- found_languages = []
191
- for language in languages :
192
- if language in mod :
193
- found_languages .append (language )
194
- data [key ] = found_languages
242
+ mod_name = mod .get ("name" , key )
243
+ mod_type = mod .get ("modType" , "unknown" ).lower ()
244
+
245
+ if mod_type == "translation" :
246
+ continue
247
+
248
+ found_languages = []
249
+ for language in languages :
250
+ if language in mod :
251
+ found_languages .append (language )
252
+
253
+ data [key ] = {"name" : mod_name , "modType" : mod_type , "languages" : found_languages }
195
254
return data
196
255
197
256
def create_md ():
@@ -232,21 +291,25 @@ def format_value(percent):
232
291
md .new_table (columns = df .shape [1 ], rows = df .shape [0 ], text = df .to_numpy ().flatten (), text_align = 'center' )
233
292
234
293
tmp = get_mod_translations (languages_translate )
235
- mod_counts = {language : sum ([ 1 for mods in tmp .values () if language in mods ]) for language in languages_translate }
294
+ mod_counts = {language : sum (1 for mods in tmp .values () if language in mods [ "languages" ]) for language in languages_translate }
236
295
total_mods = len (tmp )
237
296
percentages = [mod_counts [lang ] / total_mods if total_mods > 0 else 0 for lang in languages_translate ]
238
-
297
+
239
298
md .new_header (level = 2 , title = "Mods translation status" )
240
299
header = ["Language" ] + languages_translate
241
300
values = ["Translated mods" ] + [format_value (percent ) for percent in percentages ]
242
-
301
+
243
302
md .new_table (columns = len (header ), rows = 2 , text = header + values , text_align = 'center' )
244
303
245
304
md .new_header (level = 2 , title = "Mods translation details" )
246
305
tmp = get_mod_translations (languages_translate )
247
- df = pd .DataFrame (columns = ["Mod" ] + languages_translate )
248
- for mod in tmp :
249
- df = pd .concat ([df , pd .DataFrame ({"Mod" : "[" + mod + "](https://github.com/vcmi-mods/" + mod .replace (" " , "-" ) + ")" } | {x :["x" if x in tmp [mod ] else "" ] for x in languages_translate })], ignore_index = True )
306
+ df = pd .DataFrame (columns = ["Mod" , "Type" ] + languages_translate )
307
+
308
+ for mod , mod_data in tmp .items ():
309
+ df = pd .concat ([df , pd .DataFrame ({"Mod" : "[" + mod_data ["name" ] + "](https://github.com/vcmi-mods/" + mod .replace (" " , "-" ) + ")" , "Type" : mod_data ["modType" ], ** {x : ["x" if x in mod_data ["languages" ] else "" ] for x in languages_translate }})], ignore_index = True )
310
+
311
+ df = df .sort_values (by = ["Type" , "Mod" ])
312
+
250
313
df = df .T .reset_index ().T
251
314
md .new_table (columns = df .shape [1 ], rows = df .shape [0 ], text = df .to_numpy ().flatten (), text_align = 'center' )
252
315
0 commit comments