INNER CODE UNIT · Python
sync_readme
timschneeb/awesome-shizuku · scripts/sync_translations.py:4
def sync_readme(source_path, target_path, toc_heading, source_code_label):
# Chinese Parser: Very lenient to catch broken formatting
# Just looks for [Name](URL) and grabs everything after it.
cn_app_pattern = re.compile(r'^(\s*(?:\*|-)\s+)\[([^\]]+)\]\(([^)]+)\)(.*)$')
cn_end_stripper = re.compile(r'(?:\s*`[^`]+`|\s*\[\(.*?\)\]\(.*?\)|\s*💰|\s*✨|\s*-\s*)+$')
cn_front_stripper = re.compile(r'^(?:\s*`[^`]+`|\s*💰|\s*✨|\s*-\s*)+')
# English Parser: Strict
# Requires spaces around the hyphen (\s+-\s+) so it doesn't break tags like '15-day trial'
en_app_pattern = re.compile(r'^(\s*(?:\*|-)\s+)\[([^\]]+)\]\(([^)]+)\)(.*?)\s+-\s+(.*)$')
en_end_stripper = re.compile(r'(?:\s*`[^`]+`|\s*\[\(.*?\)\]\(.*?\)|\s*💰|\s*✨)+$')
with open(source_path, 'r', encoding='utf-8') as f:
source_lines = f.read().splitlines()
with open(target_path, 'r', encoding='utf-8') as f:
target_lines = f.read().splitlines()
translations_by_url = {}