diff --git a/core/translator.py b/core/translator.py index 7746e1e..d25661b 100644 --- a/core/translator.py +++ b/core/translator.py @@ -1,7 +1,8 @@ import os -from deep_translator import GoogleTranslator import re +from deep_translator import GoogleTranslator + def read_readme(): with open("README.md", "r", encoding="utf-8") as file: @@ -11,12 +12,13 @@ def read_readme(): def update_localizations(): readme_content = read_readme() selected_langs = os.getenv("LANGS") - no_html_content = re.sub(r"<.*?>", "", readme_content) + + no_html_content = re.sub(r"<[^>]+>", "", readme_content) + no_html_content = re.sub(r"!\[([^]]+)]\([^)]+\)", r"\1", no_html_content) no_links_content = re.sub(r"\[([^]]+)]\(([^)]+)\)", r"\1", no_html_content) chunk_size = 5000 - chunks = [no_links_content[i:i+chunk_size] - for i in range(0, len(no_links_content), chunk_size)] + chunks = [no_links_content[i:i + chunk_size] for i in range(0, len(no_links_content), chunk_size)] languages = [lang.strip() for lang in selected_langs.split(",")] files = [] @@ -26,8 +28,7 @@ def update_localizations(): for lang in languages: try: - translated_chunks = [GoogleTranslator( - source='auto', target=lang).translate(text=chunk) for chunk in chunks] + translated_chunks = [GoogleTranslator(source='auto', target=lang).translate(text=chunk) for chunk in chunks] translated_content = " ".join(translated_chunks) with open(f"dist/{lang}.md", "w", encoding="utf-8") as file: @@ -40,4 +41,4 @@ def update_localizations(): return files -update_localizations() \ No newline at end of file +update_localizations()