make different language versions

This commit is contained in:
AntonObersteiner 2024-06-05 12:09:19 +02:00
parent 03c2329c7b
commit 8d3f799ff6
8 changed files with 46207 additions and 8 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@
__pycache__ __pycache__
deploy/index.html deploy/index.html
deploy/*/index.html

2086
deploy/de/regexr.css Normal file

File diff suppressed because it is too large Load diff

21008
deploy/de/regexr.js Normal file

File diff suppressed because it is too large Load diff

1
deploy/de/regexr.js.map Normal file

File diff suppressed because one or more lines are too long

2086
deploy/en/regexr.css Normal file

File diff suppressed because it is too large Load diff

21008
deploy/en/regexr.js Normal file

File diff suppressed because it is too large Load diff

1
deploy/en/regexr.js.map Normal file

File diff suppressed because one or more lines are too long

View file

@ -167,7 +167,11 @@ def pop_hidden_data():
index = randint(0, len(hidden_data) - 1) index = randint(0, len(hidden_data) - 1)
return hidden_data.pop(index) return hidden_data.pop(index)
def generate_text(number_of_lines = 200): def generate_text(number_of_lines = 200, language = None):
""" language can be None (both), "en" or "de".
"""
do_german = not language or language == "de"
do_english = not language or language == "en"
result = "" result = ""
for i in range(number_of_lines): for i in range(number_of_lines):
emissions, _ = network.choose() emissions, _ = network.choose()
@ -181,10 +185,13 @@ def generate_text(number_of_lines = 200):
case both: case both:
german += both german += both
english += both english += both
result += german + "\n" if do_german: result += german + "\n"
result += english + "\n" if do_english: result += english + "\n"
if random() < len(hidden_data) / (number_of_lines - i): if random() < len(hidden_data) / (number_of_lines - i):
result += pop_hidden_data() + "\n" hidden_line = pop_hidden_data()
german, english = hidden_line.split("\n")
if do_german: result += german + "\n"
if do_english: result += english + "\n"
return result return result
def read_template(filename = "./template.html"): def read_template(filename = "./template.html"):
@ -197,10 +204,11 @@ def write_index(text, filename = "./deploy/index.html"):
def main(): def main():
template = read_template() template = read_template()
generated = generate_text() for language in ["", "de", "en"]:
generated = generate_text(language = language)
generated = greeting + "\n" + generated generated = greeting + "\n" + generated
text = template.replace("<replace with text>", generated) text = template.replace("<replace with text>", generated)
write_index(text) write_index(text, filename = f"./deploy/{language}/index.html")
if __name__ == "__main__": if __name__ == "__main__":
main() main()