#!/usr/bin/env python3 import json import os import requests import xml.etree.ElementTree as ET from openpilot.common.basedir import BASEDIR from openpilot.selfdrive.ui.tests.test_translations import UNFINISHED_TRANSLATION_TAG from openpilot.selfdrive.ui.update_translations import LANGUAGES_FILE, TRANSLATIONS_DIR TRANSLATION_TAG = " 90 else "red" # Download badge badge_label = f"LANGUAGE {name}" badge_message = f"{percent_finished}% complete" if unfinished_translations != 0: badge_message += f" ({unfinished_translations} unfinished)" r = requests.get(f"{SHIELDS_URL}/{badge_label}-{badge_message}-{color}", timeout=10) assert r.status_code == 200, "Error downloading badge" content_svg = r.content.decode("utf-8") xml = ET.fromstring(content_svg) assert "width" in xml.attrib max_badge_width = max(max_badge_width, int(xml.attrib["width"])) # Make tag ids in each badge unique to combine them into one svg for tag in ("r", "s"): content_svg = content_svg.replace(f'id="{tag}"', f'id="{tag}{idx}"') content_svg = content_svg.replace(f'"url(#{tag})"', f'"url(#{tag}{idx})"') badge_svg.extend([f'', content_svg, ""]) badge_svg.insert(0, '') badge_svg.append("") with open(os.path.join(BASEDIR, "translation_badge.svg"), "w") as badge_f: badge_f.write("\n".join(badge_svg))