-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlocales.py
More file actions
174 lines (149 loc) Β· 7.66 KB
/
locales.py
File metadata and controls
174 lines (149 loc) Β· 7.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
"""Centralised i18n string table for Writher.
All user-facing strings are stored here, keyed by language code.
Use ``get(key)`` to retrieve the string for the current ``config.LANGUAGE``.
Supports format placeholders via ``get(key, **kwargs)``.
To add a new language, add a new entry to ``_STRINGS`` with the same keys.
"""
import config
# ββ String tables βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
_STRINGS: dict[str, dict[str, str]] = {
"en": {
# assistant.py β dispatch confirmations
"note_saved": "Note saved (#{nid})",
"list_saved": "List '{title}' saved ({count} items)",
"added_to_list": "Added to '{title}'",
"list_not_found": "List '{title}' not found",
"appointment_created": "Appointment created: {title} ({dt})",
"reminder_set": "Reminder set: {dt}",
"unknown_command": "Unknown command: {name}",
"error": "Error: {detail}",
"not_understood": "I didn't understand the command",
# assistant.py β system prompt fragments
"system_prompt": (
"You are Writher, a voice assistant for productivity. "
"Current date and time: {now} ({weekday}). "
"The user speaks in {lang_name}. "
"Interpret their request and call the appropriate function. "
"When the user says relative times like 'tomorrow', 'in one hour', "
"'next Monday', convert them to absolute ISO datetimes. "
"Always respond by calling a function β never reply with plain text "
"unless no function fits."
),
"lang_name": "English",
# main.py β widget messages
"show_notes": "π Here are your notes",
"show_appointments": "π
Here is your agenda",
"show_reminders": "β° Here are your reminders",
"assistant_error": "Assistant error",
# tray_icon.py
"tray_idle": "Writher β idle",
"tray_recording": "Writher β recording...",
"tray_ollama_down": "Writher β Ollama not reachable",
"tray_notes_agenda": "Notes & Agenda",
"tray_quit": "Quit",
# notes_window.py β UI labels
"no_notes": "No notes",
"no_appointments": "No appointments",
"no_reminders": "No reminders",
"tab_notes": "π Notes",
"tab_agenda": "π
Agenda",
"tab_reminders": "β° Reminders",
"default_list_title": "List",
"default_note_title": "Note",
# notifier.py
"reminder_toast_title": "Writher Reminder",
"appointment_toast_title": "Writher Appointment",
"appointment_toast_body": "π
{title} β in {minutes} min",
"appointment_toast_now": "π
{title} β now!",
# tray_icon.py β settings menu
"tray_settings": "Settings",
# settings_window.py
"settings_title": "Settings",
"setting_record_mode": "Recording mode",
"setting_hold": "Hold to record",
"setting_toggle": "Press to start / stop",
"setting_max_duration": "Max recording (seconds)",
"setting_saved": "Settings saved",
"setting_microphone": "Microphone",
"setting_mic_default": "System default",
"setting_ollama_model": "Ollama model",
"setting_ollama_url": "Ollama URL",
"setting_whisper_model": "Whisper model",
"setting_language": "Language",
"setting_restart_required": "Restart required to apply",
},
"it": {
"note_saved": "Nota salvata (#{nid})",
"list_saved": "Lista '{title}' salvata ({count} elementi)",
"added_to_list": "Aggiunto a '{title}'",
"list_not_found": "Lista '{title}' non trovata",
"appointment_created": "Appuntamento creato: {title} ({dt})",
"reminder_set": "Reminder impostato: {dt}",
"unknown_command": "Comando sconosciuto: {name}",
"error": "Errore: {detail}",
"not_understood": "Non ho capito il comando",
"system_prompt": (
"You are Writher, a voice assistant for productivity. "
"Current date and time: {now} ({weekday}). "
"The user speaks in {lang_name}. "
"Interpret their request and call the appropriate function. "
"When the user says relative times like 'domani', 'tra un'ora', "
"'lunedì prossimo', convert them to absolute ISO datetimes. "
"Always respond by calling a function β never reply with plain text "
"unless no function fits."
),
"lang_name": "Italian",
"show_notes": "π Ecco le note",
"show_appointments": "π
Ecco l'agenda",
"show_reminders": "β° Ecco i reminder",
"assistant_error": "Errore assistente",
"tray_idle": "Writher β inattivo",
"tray_recording": "Writher β registrazione...",
"tray_ollama_down": "Writher β Ollama non raggiungibile",
"tray_notes_agenda": "Note & Agenda",
"tray_quit": "Esci",
"no_notes": "Nessuna nota",
"no_appointments": "Nessun appuntamento",
"no_reminders": "Nessun reminder",
"tab_notes": "π Note",
"tab_agenda": "π
Agenda",
"tab_reminders": "β° Reminder",
"default_list_title": "Lista",
"default_note_title": "Nota",
"reminder_toast_title": "Writher Promemoria",
"appointment_toast_title": "Writher Appuntamento",
"appointment_toast_body": "π
{title} β tra {minutes} min",
"appointment_toast_now": "π
{title} β adesso!",
# tray_icon.py β settings menu
"tray_settings": "Impostazioni",
# settings_window.py
"settings_title": "Impostazioni",
"setting_record_mode": "ModalitΓ registrazione",
"setting_hold": "Tieni premuto per registrare",
"setting_toggle": "Premi per avviare / fermare",
"setting_max_duration": "Durata max registrazione (secondi)",
"setting_saved": "Impostazioni salvate",
"setting_microphone": "Microfono",
"setting_mic_default": "Predefinito di sistema",
"setting_ollama_model": "Modello Ollama",
"setting_ollama_url": "URL Ollama",
"setting_whisper_model": "Modello Whisper",
"setting_language": "Lingua",
"setting_restart_required": "Riavvio necessario per applicare",
},
}
_FALLBACK = "en"
# ββ Public API ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def get(key: str, **kwargs) -> str:
"""Return the localised string for *key*, formatted with *kwargs*.
Falls back to English if the key is missing in the active language.
"""
lang = getattr(config, "LANGUAGE", _FALLBACK)
table = _STRINGS.get(lang, _STRINGS[_FALLBACK])
template = table.get(key, _STRINGS[_FALLBACK].get(key, key))
if kwargs:
try:
return template.format(**kwargs)
except (KeyError, IndexError):
return template
return template