Skip to content

Header editing script #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/deploy-book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
run: |
pip install -r requirements.txt

# Update the headers (redundant here, but for symmetry do it anyway)
- name: Update headers
run: |
python edit_headers.py en

# Build the book
- name: Build the book
run: |
Expand Down
58 changes: 58 additions & 0 deletions edit_headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import argparse
import os

def edit_headers(target_language = "en"):
translation_dict = {
"Sample Preparation":{
"en":"Sample Preparation",
"es":"Sample Preparation",
"pt":"Preparação da amostra",
"cs":"Příprava vzorku",
},
"Sample Acquisition":{
"en":"Sample Acquisition",
"es":"Sample Acquisition",
"pt":"Aquisição da amostra",
"cs":"Snímání vzorku",
},
"Image Analysis and Data Handling":{
"en":"Image Analysis and Data Handling",
"es":"Image Analysis and Data Handling",
"pt":"Análise de imagens e tratamento de dados",
"cs":"Analýza obrazu a práce s daty",
},
"Data Interpretation":{
"en":"Data Interpretation",
"es":"Data Interpretation",
"pt":"Interpretação de dados",
"cs":"Interpretace dat",
},
"Additional Resources":{
"en":"Additional Resources",
"es":"Additional Resources",
"pt":"Recursos Adicionais",
"cs":"Další zdroje",
},
}

lines = open("_toc.yml", "r").readlines()
newlines = []
for line in lines:
for caption in translation_dict.keys():
if line == f"- caption: {caption}\n":
line=line.replace(caption,translation_dict[caption][target_language])
newlines.append(line)

with open("_toc.yml","w") as toc:
toc.writelines(newlines)



if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Say what language to translate the headers to")

parser.add_argument("target_language", help="Language to translate header language into. Currently supported options are en, es, pt, and cs")

args = parser.parse_args()

edit_headers(target_language=args.target_language)