refactor language distiction

This commit is contained in:
AntonObersteiner 2024-06-11 16:38:31 +02:00
parent d275334cbb
commit cdd9694b66

View file

@ -23,13 +23,14 @@ def get_both_languages(text):
german, english = text german, english = text
return german, english return german, english
def generate_text(number_of_lines = 200, language = None): def generate_texts(number_of_lines = 200):
""" language can be None (both), "en" or "de". """ language can be "en" or "de".
""" """
local_hidden_data = hidden_data[:] local_hidden_data = hidden_data[:]
do_german = not language or language == "de" result = {
do_english = not language or language == "en" "de": "",
result = "" "en": "",
}
for i in range(number_of_lines): for i in range(number_of_lines):
emissions, _ = network.choose() emissions, _ = network.choose()
german = "" german = ""
@ -38,14 +39,14 @@ def generate_text(number_of_lines = 200, language = None):
ger, eng = get_both_languages(emission) ger, eng = get_both_languages(emission)
german += ger german += ger
english += eng english += eng
if do_german: result += german + "\n" result["de"] += german + "\n"
if do_english: result += english + "\n" result["en"] += 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)
ger, eng = get_both_languages(hidden_line) german, english = get_both_languages(hidden_line)
if do_german: result += german + "\n" result["de"] += german + "\n"
if do_english: result += english + "\n" result["en"] += english + "\n"
return result return result
def read_template(filename = "./template.html"): def read_template(filename = "./template.html"):
@ -58,9 +59,10 @@ def write_index(text, filename = "./deploy/index.html"):
def main(): def main():
template = read_template() template = read_template()
texts = generate_texts()
for language in ["de", "en"]: for language in ["de", "en"]:
generated = generate_text(language = language) generated = resolve_language(greeting, language) + "\n"
generated = resolve_language(greeting, language) + "\n" + generated generated += resolve_language(texts, language)
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")