Skip to content

Commit 0bc9765

Browse files
committed
move language footer update to update_cc4_includes.py
- add lanugage footer update to update_cc4_includes.py - remove now deprecated add_cc4_links.py
1 parent d2ceada commit 0bc9765

File tree

2 files changed

+38
-208
lines changed

2 files changed

+38
-208
lines changed

tools/add_cc4_links.py

-208
This file was deleted.

tools/update_cc4_includes.py

+38
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class UpdateLicenseCode(object):
4242
"<!-- Language Selector Start - DO NOT DELETE -->",
4343
"<!-- Language Selector End - DO NOT DELETE -->",
4444
),
45+
"language-footer": (
46+
"<!-- Language Footer Start - DO NOT DELETE -->",
47+
"<!-- Language Footer End - DO NOT DELETE -->",
48+
),
4549
}
4650

4751
languages = {}
@@ -214,6 +218,7 @@ def process_file(self, filepath):
214218
self.log(f" Updating content: {filepath.name}", "verbose")
215219
content = self.add_includes(content)
216220
content = self.add_language_selector(content, filepath)
221+
content = self.add_language_footer(content, filepath)
217222
with filepath.open("w", encoding="utf-8") as outfile:
218223
outfile.write(content)
219224
else:
@@ -291,6 +296,39 @@ def add_language_selector(self, content, filepath):
291296

292297
return content
293298

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+
294332
def parse_filename(self, filepath):
295333
license_info = filepath.name[0:-5].split("_")
296334
type = license_info[0]

0 commit comments

Comments
 (0)