Skip to content

Commit

Permalink
Translations badges: concatenate into one badge (#25522)
Browse files Browse the repository at this point in the history
* 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

* clean up

* no formats
  • Loading branch information
sshane authored Aug 23, 2022
1 parent e84f397 commit ad8d3de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
7 changes: 1 addition & 6 deletions selfdrive/ui/translations/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
23 changes: 15 additions & 8 deletions selfdrive/ui/translations/create_badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@

TRANSLATION_TAG = "<translation"
UNFINISHED_TRANSLATION_TAG = "<translation type=\"unfinished\""
TRANSLATION_BADGE = "translation_badge_{}.svg"
TRANSLATION_LINK = "https://github.com/commaai/openpilot/blob/master/selfdrive/ui/translations/{}"
BADGE_HEIGHT = 20 + 8

if __name__ == "__main__":
with open(LANGUAGES_FILE, "r") as f:
translation_files = json.load(f)

print("Copy into selfdrive/ui/translations/README.md:\n")
for name, file in translation_files.items():
badge_svg = [f'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="{len(translation_files) * BADGE_HEIGHT}">']
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():
Expand All @@ -35,6 +32,16 @@

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")

# 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})"')

badge_svg.extend([f'<g transform="translate(0, {idx * BADGE_HEIGHT})">', content_svg, "</g>"])

badge_svg.append("</svg>")

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(badge_svg))

0 comments on commit ad8d3de

Please sign in to comment.