From 68e471b4ed40034139e3d01af80c53202617e105 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Mon, 22 Aug 2022 15:53:21 -0700 Subject: [PATCH 1/3] add badge done correctly works Update translation_badge.svg Update translation_badge.svg Update translation_badge.svg Update README.md Update translation_badge.svg Update translation_badge.svg Update translation_badge.svg Update badge Update README.md test this try this finalize remove badges fixup readme add to test fix fix rm --- selfdrive/ui/translations/README.md | 7 +----- selfdrive/ui/translations/create_badges.py | 26 +++++++++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/selfdrive/ui/translations/README.md b/selfdrive/ui/translations/README.md index 5d469861482bb3..ac3112c61af3fb 100644 --- a/selfdrive/ui/translations/README.md +++ b/selfdrive/ui/translations/README.md @@ -1,11 +1,6 @@ # Multilanguage -[![language](https://raw.githubusercontent.com/commaai/openpilot/badges/translation_badge_main_en.svg)](https://github.com/commaai/openpilot/blob/master/selfdrive/ui/translations/main_en.ts) -[![language](https://raw.githubusercontent.com/commaai/openpilot/badges/translation_badge_main_pt.svg)](https://github.com/commaai/openpilot/blob/master/selfdrive/ui/translations/main_pt.ts) -[![language](https://raw.githubusercontent.com/commaai/openpilot/badges/translation_badge_main_zh-CHT.svg)](https://github.com/commaai/openpilot/blob/master/selfdrive/ui/translations/main_zh-CHT.ts) -[![language](https://raw.githubusercontent.com/commaai/openpilot/badges/translation_badge_main_zh-CHS.svg)](https://github.com/commaai/openpilot/blob/master/selfdrive/ui/translations/main_zh-CHS.ts) -[![language](https://raw.githubusercontent.com/commaai/openpilot/badges/translation_badge_main_ko.svg)](https://github.com/commaai/openpilot/blob/master/selfdrive/ui/translations/main_ko.ts) -[![language](https://raw.githubusercontent.com/commaai/openpilot/badges/translation_badge_main_ja.svg)](https://github.com/commaai/openpilot/blob/master/selfdrive/ui/translations/main_ja.ts) +[![languages](https://raw.githubusercontent.com/commaai/openpilot/badges/translation_badge.svg)](#) ## Contributing diff --git a/selfdrive/ui/translations/create_badges.py b/selfdrive/ui/translations/create_badges.py index d9e2d443b969d4..2490aa7a44f366 100755 --- a/selfdrive/ui/translations/create_badges.py +++ b/selfdrive/ui/translations/create_badges.py @@ -8,20 +8,18 @@ TRANSLATION_TAG = "'] + for idx, (name, file) in enumerate(translation_files.items()): with open(os.path.join(TRANSLATIONS_DIR, f"{file}.ts"), "r") as tr_f: tr_file = tr_f.read() - print(f"[![language](https://raw.githubusercontent.com/commaai/openpilot/badges/{TRANSLATION_BADGE.format(file)})]({TRANSLATION_LINK.format(file)}.ts)") - total_translations = 0 unfinished_translations = 0 for line in tr_file.splitlines(): @@ -35,6 +33,18 @@ r = requests.get(f"https://img.shields.io/badge/LANGUAGE {name}-{percent_finished}%25 complete-{color}") assert r.status_code == 200, "Error downloading badge" + content_svg = r.content.decode("utf-8") + + # need to make tag ids in each badge unique + 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})"') + + global_svg.append(''.format(idx * (BADGE_HEIGHT + BADGE_OFFSET))) + global_svg.append(content_svg) + global_svg.append("") + + global_svg.append("") - with open(os.path.join(BASEDIR, TRANSLATION_BADGE.format(file)), "wb") as badge_f: - badge_f.write(r.content) + with open(os.path.join(BASEDIR, "translation_badge.svg"), "w") as badge_f: + badge_f.write("\n".join(global_svg)) From b006f985509fcc16b6e6308d74d679e0b5035069 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Mon, 22 Aug 2022 20:31:19 -0700 Subject: [PATCH 2/3] clean up --- selfdrive/ui/translations/create_badges.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/selfdrive/ui/translations/create_badges.py b/selfdrive/ui/translations/create_badges.py index 2490aa7a44f366..7ec835600be723 100755 --- a/selfdrive/ui/translations/create_badges.py +++ b/selfdrive/ui/translations/create_badges.py @@ -8,14 +8,13 @@ TRANSLATION_TAG = "'] + badge_svg = [f''] for idx, (name, file) in enumerate(translation_files.items()): with open(os.path.join(TRANSLATIONS_DIR, f"{file}.ts"), "r") as tr_f: tr_file = tr_f.read() @@ -35,16 +34,16 @@ assert r.status_code == 200, "Error downloading badge" content_svg = r.content.decode("utf-8") - # need to make tag ids in each badge unique + # make tag ids in each badge unique 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})"') - global_svg.append(''.format(idx * (BADGE_HEIGHT + BADGE_OFFSET))) - global_svg.append(content_svg) - global_svg.append("") + badge_svg.append(''.format(idx * BADGE_HEIGHT)) + badge_svg.append(content_svg) + badge_svg.append("") - global_svg.append("") + badge_svg.append("") with open(os.path.join(BASEDIR, "translation_badge.svg"), "w") as badge_f: - badge_f.write("\n".join(global_svg)) + badge_f.write("\n".join(badge_svg)) From 132f125e6e0c0365cf2582acb831c26175b11c13 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Mon, 22 Aug 2022 20:33:34 -0700 Subject: [PATCH 3/3] no formats --- selfdrive/ui/translations/create_badges.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/selfdrive/ui/translations/create_badges.py b/selfdrive/ui/translations/create_badges.py index 7ec835600be723..451fbb23eb12b3 100755 --- a/selfdrive/ui/translations/create_badges.py +++ b/selfdrive/ui/translations/create_badges.py @@ -39,9 +39,7 @@ 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.append(''.format(idx * BADGE_HEIGHT)) - badge_svg.append(content_svg) - badge_svg.append("") + badge_svg.extend([f'', content_svg, ""]) badge_svg.append("")