streamline biliguality

This commit is contained in:
AntonObersteiner 2024-06-11 16:23:28 +02:00
parent 677f3f6a06
commit 69cea5b644

View file

@ -15,44 +15,8 @@ def get_names(filename, pad = " "):
] ]
return names return names
greeting = {"": """ greeting = (
Re: AW: Studierendenabfrage """
von: Prüfungsverwaltung
---------
English-only version at cc.ifsr.de/en, this page is bilingual.
Eine nur auf deutsch formulierte Variante ist unter cc.ifsr.de/de
Hallo,
Zur angefragten Prüfung gibt es leider noch keine Datenbank,
daher unten angefügt unsere Notizen aus Prüfungsakten und Personendatenbank,
immer mit automatisch erstellter englischer Überstzung.
Vielleicht können Sie die ja mit regulären Ausdrücken filtern.
Das funktioniert wie normale Text-Suche, nur etwas flexibler:
(Erst|Zweit)versuch z.B. würde sowohl 'Erstversuch'
als auch 'Zweitversuch' markieren.
.* akzeptiert alle Zeichen, das können Sie an die 'Expression'
(oben auf der Seite) vorn anfügen,
um im Menü 'List' unten rechts den Anfang der Zeile zu sehen.
Sie sollten etwa 5 Studierende finden.
Viel Spaß
=== ENGLISCH VERSION ===
Hi,
there is no database for this exam, so I added our digitized notes below,
always with the auto-generated english translation.
Maybe you can filter it with regular expressions?
They are like normal text-search but more flexible:
E.g.: (Erst|Zweit)versuch would select both words:
'Erstversuch' (first attempt) and 'Zweitversuch' (second attempt).
.* will accept any text, you can add it at the start of the expression
(top of page) to see the whole line in the menu 'List' (bottom right).
You should find approximately 5 students.
Good Luck
""", "de": """
Re: AW: Studierendenabfrage Re: AW: Studierendenabfrage
von: Prüfungsverwaltung von: Prüfungsverwaltung
--------- ---------
@ -72,14 +36,14 @@ Sie sollten etwa 5 Studierende finden.
Viel Spaß Viel Spaß
""", "en": """ """, """
Re: AW: Student data request Re: AW: Student data request
from: Exam management from: Exam management
--------- ---------
Hi, Hi,
there is no database for this exam, so I added our digitized notes below . there is no database for this exam, so I added our digitized notes below.
Maybe you can filter it with regular expressions? Maybe you can filter it with regular expressions?
They are like normal text-search but more flexible: They are like normal text-search but more flexible:
E.g.: /(first|second) attempt/ would select both: E.g.: /(first|second) attempt/ would select both:
@ -89,43 +53,39 @@ E.g.: /(first|second) attempt/ would select both:
You should find approximately 5 students. You should find approximately 5 students.
Good Luck Good Luck
"""} """)
# fünf Tatverdächtige
# Uhrzeiten, siehe Infos von Verantwortlichen
# Groß-Klein-Schreibung
date = "06.06.2024"
hidden_data = [ hidden_data = [
"Anna Bartel: Zweitversuch nicht bestanden.\n" ("Anna Bartel: Zweitversuch nicht bestanden.",
"Anna Bartel: second attempt not passed.", "Anna Bartel: second attempt not passed."),
"Boris Parsch: Zweitversuch nicht bestanden.\n" ("Boris Parsch: Zweitversuch nicht bestanden.",
"Boris Parsch: second attempt not passed.", "Boris Parsch: second attempt not passed."),
"Charlotte Winter: 2. Versuch nicht bestanden.\n" ("Charlotte Winter: 2. Versuch nicht bestanden.",
"Charlotte Winter: 2nd attempt not passed.", "Charlotte Winter: 2nd attempt not passed."),
"Dennis Meier: 2. Versuch nicht bestanden.\n" ("Dennis Meier: 2. Versuch nicht bestanden.",
"Dennis Meier: 2nd attempt not passed.", "Dennis Meier: 2nd attempt not passed."),
"Elisa Menniz: Zweitversuch nicht bestanden.\n" ("Elisa Menniz: Zweitversuch nicht bestanden.",
"Elisa Menniz: second attempt not passed.", "Elisa Menniz: second attempt not passed."),
f"Anna Bartel: Prüfung um 13:00.\n" (f"Anna Bartel: Prüfung um 13:00.",
f"Anna Bartel: exam, 13:00.", f"Anna Bartel: exam, 13:00."),
f"Boris Parsch: Prüfung um 14:00.\n" (f"Boris Parsch: Prüfung um 14:00.",
f"Boris Parsch: exam, 14:00.", f"Boris Parsch: exam, 14:00."),
f"Charlotte Winter: Prüfung um 13:30.\n" (f"Charlotte Winter: Prüfung um 13:30.",
f"Charlotte Winter: exam, 13:30.", f"Charlotte Winter: exam, 13:30."),
f"Dennis Meier: Prüfung um 10:00.\n" (f"Dennis Meier: Prüfung um 10:00.",
f"Dennis Meier: exam, 10:00.", f"Dennis Meier: exam, 10:00."),
f"Elisa Menniz: Prüfung um 14:30.\n" (f"Elisa Menniz: Prüfung um 14:30.",
f"Elisa Menniz: exam, 14:30.", f"Elisa Menniz: exam, 14:30."),
f"Anna Bartel: blaue Augen.\n" (f"Anna Bartel: blaue Augen.",
f"Anna Bartel: blue eyes.", f"Anna Bartel: blue eyes."),
f"Boris Parsch: blaue Augen.\n" (f"Boris Parsch: blaue Augen.",
f"Boris Parsch: blue eyes.", f"Boris Parsch: blue eyes."),
f"Charlotte Winter: blaue Augen.\n" (f"Charlotte Winter: blaue Augen.",
f"Charlotte Winter: blue eyes.", f"Charlotte Winter: blue eyes."),
f"Dennis Meier: grüne Augen.\n" (f"Dennis Meier: grüne Augen.",
f"Dennis Meier: green eyes.", f"Dennis Meier: green eyes."),
f"Elisa Menniz: grüne Augen.\n" (f"Elisa Menniz: grüne Augen.",
f"Elisa Menniz: green eyes.", f"Elisa Menniz: green eyes."),
] ]
network = Network( network = Network(
@ -200,6 +160,25 @@ network = Network(
), ),
) )
def resolve_language(text, language):
if isinstance(text, str):
return text
if isinstance(text, dict):
return text[language]
german, english = text
if language == "de":
return german
else:
return english
def get_both_languages(text):
if isinstance(text, str):
return text, text
if isinstance(text, dict):
return text["de"], text["en"]
german, english = text
return german, english
def generate_text(number_of_lines = 200, language = None): def generate_text(number_of_lines = 200, language = None):
""" language can be None (both), "en" or "de". """ language can be None (both), "en" or "de".
""" """
@ -212,19 +191,15 @@ def generate_text(number_of_lines = 200, language = None):
german = "" german = ""
english = "" english = ""
for emission in emissions: for emission in emissions:
match emission: ger, eng = get_both_languages(emission)
case (ger, eng):
german += ger german += ger
english += eng english += eng
case both:
german += both
english += both
if do_german: result += german + "\n" if do_german: result += german + "\n"
if do_english: result += english + "\n" if do_english: result += english + "\n"
if random() < len(local_hidden_data) / (number_of_lines - i): if random() < len(local_hidden_data) / (number_of_lines - i):
index = randint(0, len(local_hidden_data) - 1) index = randint(0, len(local_hidden_data) - 1)
hidden_line = local_hidden_data.pop(index) hidden_line = local_hidden_data.pop(index)
german, english = hidden_line.split("\n") ger, eng = get_both_languages(hidden_line)
if do_german: result += german + "\n" if do_german: result += german + "\n"
if do_english: result += english + "\n" if do_english: result += english + "\n"
return result return result
@ -241,7 +216,7 @@ def main():
template = read_template() template = read_template()
for language in ["de", "en"]: for language in ["de", "en"]:
generated = generate_text(language = language) generated = generate_text(language = language)
generated = greeting[language] + "\n" + generated generated = resolve_language(greeting, language) + "\n" + generated
text = template.replace("<replace with text>", generated) text = template.replace("<replace with text>", generated)
write_index(text, filename = f"./deploy/{language}/index.html") write_index(text, filename = f"./deploy/{language}/index.html")