Skip to content

Commit

Permalink
насилуем байты
Browse files Browse the repository at this point in the history
  • Loading branch information
mrf0rtuna4 committed May 5, 2024
1 parent 663d678 commit cf1069d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions core/translator.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 = []
Expand All @@ -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:
Expand All @@ -40,4 +41,4 @@ def update_localizations():
return files


update_localizations()
update_localizations()

0 comments on commit cf1069d

Please sign in to comment.