@@ -42,6 +42,10 @@ class UpdateLicenseCode(object):
42
42
"<!-- Language Selector Start - DO NOT DELETE -->" ,
43
43
"<!-- Language Selector End - DO NOT DELETE -->" ,
44
44
),
45
+ "language-footer" : (
46
+ "<!-- Language Footer Start - DO NOT DELETE -->" ,
47
+ "<!-- Language Footer End - DO NOT DELETE -->" ,
48
+ ),
45
49
}
46
50
47
51
languages = {}
@@ -214,6 +218,7 @@ def process_file(self, filepath):
214
218
self .log (f" Updating content: { filepath .name } " , "verbose" )
215
219
content = self .add_includes (content )
216
220
content = self .add_language_selector (content , filepath )
221
+ content = self .add_language_footer (content , filepath )
217
222
with filepath .open ("w" , encoding = "utf-8" ) as outfile :
218
223
outfile .write (content )
219
224
else :
@@ -291,6 +296,39 @@ def add_language_selector(self, content, filepath):
291
296
292
297
return content
293
298
299
+ def add_language_footer (self , content , filepath ):
300
+ """Build and insert a language footer dropdown list."""
301
+ license_data = self .license_data [filepath ]
302
+ current_language = license_data ["language" ]
303
+ sibling_languages = self .languages [license_data ["type" ]]
304
+ footer = ''
305
+ for i , iso_code in enumerate (sibling_languages ):
306
+ if iso_code == current_language :
307
+ continue
308
+ # Determine to option value for the language. English breaks the
309
+ # pattern so handle it differently.
310
+ index = f"legalcode.{ iso_code } "
311
+ if iso_code == "en" :
312
+ index = "legalcode"
313
+ link = (
314
+ f'<a href="/licenses/{ license_data ["type" ]} /4.0/{ index } ">'
315
+ f"{ self .iso_to_language [iso_code ]} </a>"
316
+ )
317
+ if i != (len (sibling_languages ) - 1 ):
318
+ link = f"{ link } ,\n "
319
+
320
+ footer = f'{ footer } { link } '
321
+
322
+ # Add the language footer block to the content
323
+ start , end = UpdateLicenseCode .placeholders ["language-footer" ]
324
+ target_string = re .search (
325
+ f"{ start } .*?{ end } " , content , re .DOTALL
326
+ ).group ()
327
+ replacement = f"{ start } \n { footer } .\n { end } "
328
+ content = content .replace (target_string , replacement , 1 )
329
+
330
+ return content
331
+
294
332
def parse_filename (self , filepath ):
295
333
license_info = filepath .name [0 :- 5 ].split ("_" )
296
334
type = license_info [0 ]
0 commit comments