-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from Batres3/main
- Loading branch information
Showing
4 changed files
with
259 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
from typing import Callable | ||
import json | ||
from sys import argv | ||
from glob import glob | ||
|
||
language = argv[1].lower() | ||
TRANSLATION_FOLDER = "translations/" | ||
file = f"{TRANSLATION_FOLDER}{language}.json" | ||
|
||
if file in glob(f"{TRANSLATION_FOLDER}*.json"): | ||
with open(file, "r") as f: | ||
translation = json.load(f) | ||
else: | ||
raise ValueError("Requested translation is not currently supported.\nThe program will now exit.") | ||
|
||
|
||
if any(not word.isascii() for word in translation.values()): | ||
print("unicode found") | ||
font_edit = r"" | ||
else: | ||
font_edit = "" | ||
print(f"Translating pdf to {language}") | ||
|
||
MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] | ||
WEEKDAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] | ||
WEEKDAYS_SHORT = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] | ||
WEEK = ["Week"] | ||
NOTES = ["Notes"] | ||
NOTE = ["Note"] | ||
NOTES_INDEX = ["Notes Index"] | ||
ALL_NOTES = ["All notes"] | ||
SCHEDULE = ["Schedule"] | ||
PRIORITIES = ["Top priorities"] | ||
MORE = ["More"] | ||
REFLECT = ["Reflect"] | ||
PHRASES = ["Things I'm grateful for", "The best thing that happened today", "Daily log"] | ||
|
||
def handle_all() -> None: | ||
handle_annual() | ||
handle_quarterly() | ||
handle_monthly() | ||
handle_weekly() | ||
handle_daily() | ||
handle_daily_reflect() | ||
handle_daily_notes() | ||
handle_notes_indexed() | ||
|
||
def add_identifier(keys: list[str], func: Callable[[str], str] = lambda x: x, dictionary: dict[str, str] = translation) -> dict[str, str]: | ||
return {func(key): func(dictionary.get(key)) for key in keys} | ||
|
||
def handle_annual() -> None: | ||
with open("out/annual.tex", "r") as file: | ||
text = file.read() | ||
|
||
replace = add_identifier(MONTHS, lambda x: "{" + x + "}}") | ||
replace |= add_identifier(NOTES, lambda x: "{" + x + "}") | ||
for english, spanish in replace.items(): | ||
text = text.replace(english, spanish) | ||
|
||
with open("out/annual.tex", "w") as file: | ||
file.write(font_edit) | ||
file.write(text) | ||
|
||
def handle_quarterly() -> None: | ||
with open("out/quarterly.tex", "r") as file: | ||
text = file.read() | ||
|
||
replace = add_identifier(MONTHS, lambda x: "{" + x + "}}") | ||
replace |= add_identifier(NOTES, lambda x: "{" + x + "}") | ||
for english, spanish in replace.items(): | ||
text = text.replace(english, spanish) | ||
|
||
with open("out/quarterly.tex", "w") as file: | ||
file.write(font_edit) | ||
file.write(text) | ||
|
||
def handle_monthly() -> None: | ||
with open("out/monthly.tex", "r") as file: | ||
text = file.read() | ||
|
||
replace = add_identifier(MONTHS, lambda x: "}{" + x + "}") | ||
replace |= add_identifier(WEEKDAYS) | ||
replace |= add_identifier(WEEK, lambda x: "[c]{" + x) | ||
replace |= add_identifier(NOTES, lambda x: "{" + x + "}") | ||
for english, spanish in replace.items(): | ||
text = text.replace(english, spanish) | ||
|
||
with open("out/monthly.tex", "w") as file: | ||
file.write(font_edit) | ||
file.write(text) | ||
|
||
def handle_weekly() -> None: | ||
with open("out/weekly.tex", "r") as file: | ||
text = file.read() | ||
|
||
replace = add_identifier(MONTHS, lambda x: "}{" + x + "}") | ||
replace |= add_identifier(WEEK, lambda x: "}{" + x) | ||
replace |= add_identifier(WEEKDAYS, lambda x: ", " + x + "}") | ||
replace |= add_identifier(NOTES, lambda x: "{" + x) | ||
for english, spanish in replace.items(): | ||
text = text.replace(english, spanish) | ||
|
||
with open("out/weekly.tex", "w") as file: | ||
file.write(font_edit) | ||
file.write(text) | ||
|
||
def handle_daily() -> None: | ||
with open("out/daily.tex", "r") as file: | ||
text = file.read() | ||
|
||
replace = add_identifier(MONTHS, lambda x: "}{" + x + "}") | ||
replace |= add_identifier(WEEK, lambda x: "}{" + x) | ||
replace |= add_identifier(WEEKDAYS, lambda x: "}{" + x + ",") | ||
replace |= add_identifier(WEEKDAYS_SHORT, lambda x: "}{" + x + ",") | ||
replace |= add_identifier(SCHEDULE, lambda x: "{" + x + "\\") | ||
replace |= add_identifier(PRIORITIES, lambda x: "{" + x + "\\") | ||
replace |= add_identifier(NOTES, lambda x: "{" + x + " $") | ||
replace |= add_identifier(MORE, lambda x: "{" + x + "}") | ||
replace |= add_identifier(REFLECT, lambda x: "{" + x + "}") | ||
replace |= add_identifier(ALL_NOTES) | ||
for english, spanish in replace.items(): | ||
text = text.replace(english, spanish) | ||
|
||
with open("out/daily.tex", "w") as file: | ||
file.write(font_edit) | ||
file.write(text) | ||
|
||
def handle_daily_reflect() -> None: | ||
with open("out/daily_reflect.tex", "r") as file: | ||
text = file.read() | ||
|
||
replace = add_identifier(MONTHS, lambda x: "}{" + x + "}") | ||
replace |= add_identifier(WEEK, lambda x: "}{" + x) | ||
replace |= add_identifier(WEEKDAYS, lambda x: "}{" + x + ",") | ||
replace |= add_identifier(WEEKDAYS_SHORT, lambda x: "}{" + x + ",") | ||
replace |= add_identifier(REFLECT, lambda x: "{" + x + "}") | ||
replace |= add_identifier(PHRASES) | ||
for english, spanish in replace.items(): | ||
text = text.replace(english, spanish) | ||
|
||
with open("out/daily_reflect.tex", "w") as file: | ||
file.write(font_edit) | ||
file.write(text) | ||
|
||
def handle_daily_notes() -> None: | ||
with open("out/daily_notes.tex", "r") as file: | ||
text = file.read() | ||
|
||
replace = add_identifier(MONTHS, lambda x: "}{" + x + "}") | ||
replace |= add_identifier(WEEK, lambda x: "}{" + x) | ||
replace |= add_identifier(WEEKDAYS, lambda x: "}{" + x + ",") | ||
replace |= add_identifier(WEEKDAYS_SHORT, lambda x: "}{" + x + ",") | ||
replace |= add_identifier(NOTES, lambda x: "{" + x + "}") | ||
for english, spanish in replace.items(): | ||
text = text.replace(english, spanish) | ||
|
||
with open("out/daily_notes.tex", "w") as file: | ||
file.write(font_edit) | ||
file.write(text) | ||
|
||
def handle_notes_indexed() -> None: | ||
with open("out/notes_indexed.tex", "r") as file: | ||
text = file.read() | ||
|
||
replace = add_identifier(NOTES_INDEX, lambda x: "}{" + x) | ||
replace |= add_identifier(NOTE, lambda x: "}{" + x) | ||
for english, spanish in replace.items(): | ||
text = text.replace(english, spanish) | ||
|
||
with open("out/notes_indexed.tex", "w") as file: | ||
file.write(font_edit) | ||
file.write(text) | ||
|
||
handle_all() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"January": "Januar", | ||
"February": "Februar", | ||
"March": "März", | ||
"April": "April", | ||
"May": "Mai", | ||
"June": "Juni", | ||
"July": "Juli", | ||
"August": "August", | ||
"September": "September", | ||
"October": "Oktober", | ||
"November": "November", | ||
"December": "Dezember", | ||
"Monday": "Montag", | ||
"Tuesday": "Dienstag", | ||
"Wednesday": "Mittwoch", | ||
"Thursday": "Donnerstag", | ||
"Friday": "Freitag", | ||
"Saturday": "Samstag", | ||
"Sunday": "Sonntag", | ||
"Mon": "Mo", | ||
"Tue": "Di", | ||
"Wed": "Mi", | ||
"Thu": "Do", | ||
"Fri": "Fr", | ||
"Sat": "Sa", | ||
"Sun": "So", | ||
"Week": "Woche", | ||
"Notes": "Notizen", | ||
"Note": "Notiz", | ||
"Notes Index": "Notizverzeichnis", | ||
"All notes": "Alle Notizen", | ||
"Schedule": "Zeitplan", | ||
"Top priorities": "höchste Priorität", | ||
"More": "mehr", | ||
"Reflect": "Reflektieren", | ||
"Things I'm grateful for": "Dinge, für die ich dankbar bin", | ||
"The best thing that happened today": "Das Beste, was heute passiert ist", | ||
"Daily log": "Tagebuch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"January": "Enero", | ||
"February": "Febrero", | ||
"March": "Marzo", | ||
"April": "Abril", | ||
"May": "Mayo", | ||
"June": "Junio", | ||
"July": "Julio", | ||
"August": "Agosto", | ||
"September": "Septiembre", | ||
"October": "Octubre", | ||
"November": "Noviembre", | ||
"December": "Diciembre", | ||
"Monday": "Lunes", | ||
"Tuesday": "Martes", | ||
"Wednesday": "Miércoles", | ||
"Thursday": "Jueves", | ||
"Friday": "Viernes", | ||
"Saturday": "Sábado", | ||
"Sunday": "Domingo", | ||
"Mon": "Lun", | ||
"Tue": "Mar", | ||
"Wed": "Miér", | ||
"Thu": "Jue", | ||
"Fri": "Vie", | ||
"Sat": "Sab", | ||
"Sun": "Dom", | ||
"Week": "Semana", | ||
"Notes": "Notas", | ||
"Note": "Nota", | ||
"Notes Index": "Índice de notas", | ||
"All notes": "Todas las notas", | ||
"Schedule": "Horario", | ||
"Top priorities": "Prioridades", | ||
"More": "Más", | ||
"Reflect": "Reflexión", | ||
"Things I'm grateful for": "Cosas por las que estoy agradecido", | ||
"The best thing that happened today": "Lo mejor que ha pasado hoy", | ||
"Daily log": "Registro diario" | ||
} |