Skip to content

Commit

Permalink
fix: translation generation
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Nov 25, 2023
1 parent c941602 commit 93b7bb0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions gen_translated.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,21 @@

# generate ouput
meta_content = open(raw_date + "-this-week-in-rust.md", "r").read()
with open(raw_date + "-this-week-in-rust.md", 'a') as fh:
with open(raw_date + "-this-week-in-rust.md", 'w') as fh:
content = response[0]["translations"][0]["text"]
description: str = [line for line in content.split('\n') if line.startswith("El crate de esta semana es")][0]
description = [line for line in content.split('\n') if line.startswith("La caja de esta semana es")]
print(f"Match = {description}")
description = description[0]
finded = re.search(r'(\[(?P<caption>.*?)\])\((?P<image>.*?)(?P<description>\".*?\")?\)', description)
if finded is None:
print("No Encontrado")
description = "Esta semana en Rust es un blog semanal sobre el lenguaje de programación Rust, sus comunidades y su ecosistema."
else:
print("Encontrado!!")
finded = finded.groupdict()
link_name = re.sub(r'\[.*\]\(.*\)', finded["caption"], description)
content = content.replace("Esta semana en Rust es un blog semanal sobre el lenguaje de programación Rust, sus comunidades y su ecosistema.", link_name)
print(f"To Replace: {meta_content}")
new_content = meta_content.replace("Esta semana en Rust es un blog semanal sobre el lenguaje de programación Rust, sus comunidades y su ecosistema.", link_name)
print(f"Replacement Result: {new_content}")
content = new_content + '\n' + content
fh.write(content)

0 comments on commit 93b7bb0

Please sign in to comment.