forked from Kenshin9977/video-dl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlang.py
269 lines (243 loc) · 8.37 KB
/
lang.py
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import enum
import locale
from typing import List
class Language(enum.Enum):
english = enum.auto()
french = enum.auto()
german = enum.auto()
class GuiField(enum.Enum):
# Main window static text
incorrect_timestamp = enum.auto()
link = enum.auto()
is_playlist = enum.auto()
playlist_items = enum.auto()
destination = enum.auto()
start = enum.auto()
end = enum.auto()
subtitles = enum.auto()
quality = enum.auto()
framerate = enum.auto()
vcodec = enum.auto()
acodec = enum.auto()
audio_only = enum.auto()
song_only = enum.auto()
song_only_tooltip = enum.auto()
cookies = enum.auto()
dl_button = enum.auto()
# Main window status
dl_cancel = enum.auto()
error = enum.auto()
dl_error = enum.auto()
dl_finish = enum.auto()
invalid_output_path = enum.auto()
# Progress window
download = enum.auto()
process = enum.auto()
update = enum.auto()
ff_remux = enum.auto()
ff_reencode = enum.auto()
ff_starting = enum.auto()
ff_speed = enum.auto()
cancel_button = enum.auto()
def _get_language() -> Language:
"""
Tries to determine the system language, fallbacks to english.
"""
# This dictionary maps the language of a locale to its associated enum
lang_map = {
"en": Language.english,
"fr": Language.french,
"de": Language.german,
}
locale.setlocale(locale.LC_ALL, "")
system_language = locale.getdefaultlocale()[0]
if system_language is None:
return Language.english
for available_language in lang_map.keys():
if available_language in system_language:
return lang_map[available_language]
return Language.english
_current_language = _get_language()
def get_text(field: GuiField) -> str:
ui_text = {
GuiField.incorrect_timestamp: {
Language.english: "Invalid timestamps",
Language.french: "Temps saisis invalides",
Language.german: "Ungültiger Zeitstempel",
},
GuiField.link: {
Language.english: "Link",
Language.french: "Lien",
Language.german: "Link",
},
GuiField.is_playlist: {
Language.english: "Playlist",
Language.french: "Playlist",
Language.german: "Wiedergabeliste",
},
GuiField.playlist_items: {
Language.english: "Indices",
Language.french: "Index",
Language.german: "Indizes",
},
GuiField.download: {
Language.english: "Download",
Language.french: "Téléchargement",
Language.german: "Herunterladen",
},
GuiField.process: {
Language.english: "Processing",
Language.french: "Traitement",
Language.german: "Echtzeitverarbeitung",
},
GuiField.destination: {
Language.english: "Destination folder",
Language.french: "Dossier de destination",
Language.german: "Zielordner",
},
GuiField.start: {
Language.english: "Start",
Language.french: "Début",
Language.german: "Anfang",
},
GuiField.end: {
Language.english: "End",
Language.french: "Fin",
Language.german: "Ende",
},
GuiField.subtitles: {
Language.english: "Subtitles",
Language.french: "Sous-titres",
Language.german: "Untertitel",
},
GuiField.quality: {
Language.english: "Maximum quality",
Language.french: "Qualité maximale",
Language.german: "Maximale Qualität",
},
GuiField.framerate: {
Language.english: "Maximum framerate",
Language.french: "Fréquence d'images par seconde maximum",
Language.german: "Maximale Bildfrequenz",
},
GuiField.vcodec: {
Language.english: "Video codec",
Language.french: "Codec vidéo",
Language.german: "Codec für video",
},
GuiField.acodec: {
Language.english: "Audio codec",
Language.french: "Codec audio",
Language.german: "Codec für audio",
},
GuiField.audio_only: {
Language.english: "Audio only",
Language.french: "Audio seul",
Language.german: "Nur Audio",
},
GuiField.song_only: {
Language.english: "Song only",
Language.french: "Musique seulement",
Language.german: "Nur Lied",
},
GuiField.song_only_tooltip: {
Language.english: "Uses SponsorBlock to discard any non musical section", # noqa
Language.french: "Utilise SponsorBlock pour retirer toutes les parties non musicales", # noqa
Language.german: "Verwendet SponsorBlock, um alle nicht musikalischen Abschnitte zu verwerfen", # noqa
},
GuiField.cookies: {
Language.english: "Use cookies from the selected browser",
Language.french: "Utiliser les cookies du navigateur selectionné",
Language.german: "Benutze Cookies des ausgewählten Webbrowsers",
},
GuiField.dl_button: {
Language.english: "Download",
Language.french: "Télécharger",
Language.german: "Herunterladen",
},
GuiField.dl_cancel: {
Language.english: "Download cancelled.",
Language.french: "Téléchargement annulé.",
Language.german: "Herunterladen abgebrochen.",
},
GuiField.error: {
Language.english: "Error: ",
Language.french: "Erreur : ",
Language.german: "Software-Fehler: ",
},
GuiField.dl_error: {
Language.english: "An error has occurred.",
Language.french: "Une erreur s'est produite.",
Language.german: "Ein Fehler ist aufgetreten.",
},
GuiField.dl_finish: {
Language.english: "Download finished.",
Language.french: "Téléchargement terminé.",
Language.german: "Herunterladen abgeschlossen.",
},
GuiField.invalid_output_path: {
Language.english: "Select a valid output path.",
Language.french: "Indiquez un dossier de destination valide.",
Language.german: "Wählen Sie einen gültigen Ausgabepfad.",
},
GuiField.ff_remux: {
Language.english: "Remuxing",
Language.french: "Remuxage",
Language.german: "Remuxen",
},
GuiField.ff_reencode: {
Language.english: "Re-encoding",
Language.french: "Réencodage",
Language.german: "Neukodierung",
},
GuiField.ff_starting: {
Language.english: "Starting",
Language.french: "Démarrage",
Language.german: "Starte",
},
GuiField.ff_speed: {
# Add a space at the end of the message if
# the language requires one before a colon
Language.english: "Speed",
Language.french: "Vitesse ",
Language.german: "Geschwindigkeit",
},
GuiField.cancel_button: {
Language.english: "Cancel",
Language.french: "Annuler",
Language.german: "Abbrechen",
},
GuiField.update: {
Language.english: "Update",
Language.french: "Mise à jour",
Language.german: "Aktualisierung",
},
}
return ui_text[field][_current_language]
_available_languages = {
Language.english: "English",
Language.french: "Français",
Language.german: "Deutsch",
}
_language_from_name = {
name: lang for lang, name in _available_languages.items()
}
def get_available_languages_name() -> List[str]:
"""
Returns a list of all the available languages in a human-readable form.
"""
return list(_available_languages.values())
def get_current_language_name() -> str:
"""
Get the name of the current language.
"""
return _available_languages[_current_language]
def set_current_language(name: str) -> None:
"""
Set the current language.
"name" must be available, else no changes will be made.
"""
if name not in _language_from_name:
return
global _current_language
_current_language = _language_from_name[name]