Skip to content

Commit 406c763

Browse files
bethac07martinschatz-czmccruz07emiglietta
authored
Header editing script (#78)
* Header editing script * CS header translations add to edit_headers.py (#79) * Update edit_headers.py Portuguese updates * Update edit_headers.py (#80) --------- Co-authored-by: Martin Schätz <[email protected]> Co-authored-by: mccruz07 <[email protected]> Co-authored-by: emiglietta <[email protected]>
1 parent 76e4882 commit 406c763

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

.github/workflows/deploy-book.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ jobs:
2727
run: |
2828
pip install -r requirements.txt
2929
30+
# Update the headers (redundant here, but for symmetry do it anyway)
31+
- name: Update headers
32+
run: |
33+
python edit_headers.py en
34+
3035
# Build the book
3136
- name: Build the book
3237
run: |

edit_headers.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import argparse
2+
import os
3+
4+
def edit_headers(target_language = "en"):
5+
translation_dict = {
6+
"Sample Preparation":{
7+
"en":"Sample Preparation",
8+
"es":"Preparación de la muestra",
9+
"pt":"Preparação da amostra",
10+
"cs":"Příprava vzorku",
11+
},
12+
"Sample Acquisition":{
13+
"en":"Sample Acquisition",
14+
"es":"Adquisición de muestras",
15+
"pt":"Aquisição da amostra",
16+
"cs":"Snímání vzorku",
17+
},
18+
"Image Analysis and Data Handling":{
19+
"en":"Image Analysis and Data Handling",
20+
"es":"Análisis de Imágenes y Manejo de Datos",
21+
"pt":"Análise de imagens e tratamento de dados",
22+
"cs":"Analýza obrazu a práce s daty",
23+
},
24+
"Data Interpretation":{
25+
"en":"Data Interpretation",
26+
"es":"Interpretación de Datos",
27+
"pt":"Interpretação de dados",
28+
"cs":"Interpretace dat",
29+
},
30+
"Additional Resources":{
31+
"en":"Additional Resources",
32+
"es":"Recursos Adicionales",
33+
"pt":"Recursos Adicionais",
34+
"cs":"Další zdroje",
35+
},
36+
}
37+
38+
lines = open("_toc.yml", "r").readlines()
39+
newlines = []
40+
for line in lines:
41+
for caption in translation_dict.keys():
42+
if line == f"- caption: {caption}\n":
43+
line=line.replace(caption,translation_dict[caption][target_language])
44+
newlines.append(line)
45+
46+
with open("_toc.yml","w") as toc:
47+
toc.writelines(newlines)
48+
49+
50+
51+
if __name__ == "__main__":
52+
parser = argparse.ArgumentParser(description="Say what language to translate the headers to")
53+
54+
parser.add_argument("target_language", help="Language to translate header language into. Currently supported options are en, es, pt, and cs")
55+
56+
args = parser.parse_args()
57+
58+
edit_headers(target_language=args.target_language)

0 commit comments

Comments
 (0)