1 /* Language.cpp */
2
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4 *
5 * This file is part of sayonara player
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "Language.h"
22 #include "Algorithm.h"
23 #include "StandardPaths.h"
24 #include "Utils.h"
25
26 #include <QDir>
27 #include <QRegExp>
28 #include <QStringList>
29 #include <QLocale>
30
LanguageString(const QString & other)31 LanguageString::LanguageString(const QString& other) :
32 QString(other)
33 {}
34
operator =(const QString & other)35 LanguageString& LanguageString::operator=(const QString& other)
36 {
37 QString::operator=(other);
38 return *this;
39 }
toFirstUpper()40 LanguageString& LanguageString::toFirstUpper()
41 {
42 this->replace(0, 1, this->at(0).toUpper());
43 return *this;
44 }
45
space()46 LanguageString& LanguageString::space()
47 {
48 this->append(' ');
49 return *this;
50 }
51
question()52 LanguageString& LanguageString::question()
53 {
54 this->append('?');
55 return *this;
56 }
57
triplePt()58 LanguageString& LanguageString::triplePt()
59 {
60 this->append("...");
61 return *this;
62 }
63
64 Lang::Lang() = default;
65
66 Lang::~Lang() = default;
67
get(Lang::Term term,bool * ok)68 LanguageString Lang::get(Lang::Term term, bool* ok)
69 {
70 if(ok){
71 *ok = true;
72 }
73
74 Lang l;
75 switch(term)
76 {
77 case About:
78 return l.tr("About");
79 case Action:
80 return l.tr("Action");
81 case Actions:
82 return l.tr("Actions");
83 case Activate:
84 return l.tr("Activate");
85 case Active:
86 return l.tr("Active");
87 case Add:
88 return l.tr("Add");
89 case AddArtist:
90 return l.tr("Add artist");
91 case AddTab:
92 return l.tr("Add tab");
93 case Album:
94 return l.tr("Album");
95 case AlbumArtist:
96 return l.tr("Album artist");
97 case AlbumArtists:
98 return l.tr("Album artists");
99 case Albums:
100 return l.tr("Albums");
101 case All:
102 return l.tr("All");
103 case Append:
104 return l.tr("Append");
105 case Application:
106 return l.tr("Application");
107 case Apply:
108 return l.tr("Apply");
109 case Artist:
110 return l.tr("Artist");
111 case Artists:
112 return l.tr("Artists");
113 case Ascending:
114 return l.tr("Ascending");
115 case Automatic:
116 return l.tr("Automatic");
117 case Bitrate:
118 return l.tr("Bitrate");
119 case Bookmarks:
120 return l.tr("Bookmarks");
121 case Broadcast:
122 return l.tr("Broadcast");
123 case By:
124 // "Beat it" by "Michael Jackson"
125 return l.tr("by");
126 case Cancel:
127 return l.tr("Cancel");
128 case CannotFindLame:
129 return l.tr("Cannot find Lame MP3 encoder");
130 case Clear:
131 return l.tr("Clear");
132 case ClearSelection:
133 return l.tr("Clear selection");
134 case Close:
135 return l.tr("Close");
136 case CloseOthers:
137 return l.tr("Close others");
138 case CloseTab:
139 return l.tr("Close tab");
140 case Comment:
141 return l.tr("Comment");
142 case Continue:
143 return l.tr("Continue");
144 case Covers:
145 return l.tr("Covers");
146 case Created:
147 return l.tr("Created");
148 case CreateDirectory:
149 return l.tr("Create new directory");
150 case CreateNewLibrary:
151 return l.tr("Create a new library");
152 case DarkMode:
153 return l.tr("Dark Mode");
154 case Date:
155 return l.tr("Date");
156 case Days:
157 return l.tr("Days");
158 case DaysShort:
159 // short form of day
160 return l.tr("d");
161 case Default:
162 return l.tr("Default");
163 case Delete:
164 return l.tr("Delete");
165 case Descending:
166 return l.tr("Descending");
167 case Directory:
168 return l.tr("Directory");
169 case Directories:
170 return l.tr("Directories");
171 case Disc:
172 return l.tr("Disc");
173 case Duration:
174 return l.tr("Duration");
175 case DurationShort:
176 // short form of duration
177 return l.tr("Dur.");
178 case DynamicPlayback:
179 return l.tr("Dynamic playback");
180 case Edit:
181 return l.tr("Edit");
182 case EmptyInput:
183 return l.tr("Empty input");
184 case EnterName:
185 return l.tr("Enter name");
186 case EnterNewName:
187 return l.tr("Please enter new name");
188 case EnterUrl:
189 return l.tr("Enter URL");
190 case Entry:
191 return l.tr("Entry");
192 case Entries:
193 return l.tr("Entries");
194 case Error:
195 return l.tr("Error");
196 case Fast:
197 return l.tr("Fast");
198 case File:
199 return l.tr("File");
200 case Filename:
201 return l.tr("Filename");
202 case Files:
203 return l.tr("Files");
204 case Filesize:
205 return l.tr("Filesize");
206 case Filetype:
207 return l.tr("File type");
208 case Filter:
209 return l.tr("Filter");
210 case First:
211 return l.tr("1st");
212 case Font:
213 return l.tr("Font");
214 case Fonts:
215 return l.tr("Fonts");
216 case Fulltext:
217 return l.tr("Fulltext");
218 case GaplessPlayback:
219 return l.tr("Gapless playback");
220 case GB:
221 return l.tr("GB");
222 case Genre:
223 return l.tr("Genre");
224 case Genres:
225 return l.tr("Genres");
226 case Hide:
227 return l.tr("Hide");
228 case Hours:
229 return l.tr("Hours");
230 case HoursShort:
231 // short form of hours
232 return l.tr("h");
233 case ImportDir:
234 return l.tr("Import directory");
235 case ImportFiles:
236 return l.tr("Import files");
237 case Inactive:
238 return l.tr("Inactive");
239 case Info:
240 return l.tr("Info");
241 case Loading:
242 return l.tr("Loading");
243 case LoadingArg:
244 return l.tr("Loading %1");
245 case InvalidChars:
246 return l.tr("Invalid characters");
247 case KB:
248 return l.tr("KB");
249 case Key_Find:
250 return l.tr("Ctrl+f");
251 case Key_Delete:
252 return l.tr("Delete");
253 case Key_Escape:
254 return l.tr("Esc");
255 case Key_Control:
256 return l.tr("Ctrl");
257 case Key_Alt:
258 return l.tr("Alt");
259 case Key_Shift:
260 return l.tr("Shift");
261 case Key_Backspace:
262 return l.tr("Backspace");
263 case Key_Tab:
264 return l.tr("Tab");
265 case Library:
266 return l.tr("Library");
267 case LibraryPath:
268 return l.tr("Library path");
269 case LibraryView:
270 return l.tr("Library view type");
271 case Listen:
272 return l.tr("Listen");
273 case LiveSearch:
274 return l.tr("Live Search");
275 case Logger:
276 return l.tr("Logger");
277 case LogLevel:
278 return l.tr("Log level");
279 case Lyrics:
280 return l.tr("Lyrics");
281 case MB:
282 return l.tr("MB");
283 case Menu:
284 return l.tr("Menu");
285 case Minimize:
286 return l.tr("Minimize");
287 case Minutes:
288 return l.tr("Minutes");
289 case MinutesShort:
290 // short form of minutes
291 return l.tr("m");
292 case Missing:
293 return l.tr("Missing");
294 case Modified:
295 return l.tr("Modified");
296 case Months:
297 return l.tr("Months");
298 case MuteOn:
299 return l.tr("Mute");
300 case MuteOff:
301 return l.tr("Mute off");
302 case Name:
303 return l.tr("Name");
304 case New:
305 return l.tr("New");
306 case NextPage:
307 return l.tr("Next page");
308 case NextTrack:
309 return l.tr("Next track");
310 case No:
311 return l.tr("No");
312 case NoAlbums:
313 return l.tr("No albums");
314 case NumTracks:
315 return l.tr("Tracks");
316 case MoveDown:
317 return l.tr("Move down");
318 case MoveUp:
319 return l.tr("Move up");
320 case OK:
321 return l.tr("OK");
322 case On:
323 // 5th track on "Thriller"
324 return l.tr("on");
325 case Open:
326 return l.tr("Open");
327 case OpenDir:
328 return l.tr("Open directory");
329 case OpenFile:
330 return l.tr("Open file");
331 case Or:
332 return l.tr("or");
333 case Overwrite:
334 return l.tr("Overwrite");
335 case Pause:
336 return l.tr("Pause");
337 case Play:
338 return l.tr("Play");
339 case PlayingTime:
340 return l.tr("Playing time");
341 case PlayInNewTab:
342 return l.tr("Play in new tab");
343 case Playlist:
344 return l.tr("Playlist");
345 case Playlists:
346 return l.tr("Playlists");
347 case PlayNext:
348 return l.tr("Play next");
349 case PlayPause:
350 return l.tr("Play/Pause");
351 case Plugin:
352 return l.tr("Plugin");
353 case Podcasts:
354 return l.tr("Podcasts");
355 case Preferences:
356 return l.tr("Preferences");
357 case PreviousPage:
358 return l.tr("Previous page");
359 case PreviousTrack:
360 return l.tr("Previous track");
361 case PurchaseUrl:
362 return l.tr("Purchase Url");
363 case Quit:
364 return l.tr("Quit");
365 case Radio:
366 return l.tr("Radio");
367 case RadioStation:
368 return l.tr("Radio Station");
369 case Rating:
370 return l.tr("Rating");
371 case Really:
372 return l.tr("Really");
373 case Refresh:
374 return l.tr("Refresh");
375 case ReloadLibrary:
376 return l.tr("Reload Library");
377 case Remove:
378 return l.tr("Remove");
379 case Rename:
380 return l.tr("Rename");
381 case Repeat1:
382 return l.tr("Repeat 1");
383 case RepeatAll:
384 return l.tr("Repeat all");
385 case Replace:
386 return l.tr("Replace");
387 case Reset:
388 return l.tr("Reset");
389 case Retry:
390 return l.tr("Retry");
391 case ReverseOrder:
392 return l.tr("Reverse order");
393 case Sampler:
394 return l.tr("Sampler");
395 case Shuffle:
396 return l.tr("Shuffle");
397 case Shutdown:
398 return l.tr("Shutdown");
399 case Save:
400 return l.tr("Save");
401 case SaveAs:
402 return l.tr("Save as");
403 case SaveToFile:
404 return l.tr("Save to file");
405 case ScanForFiles:
406 return l.tr("Scan for audio files");
407 case SearchNoun:
408 return l.tr("Search"); // the noun of search
409 case SearchVerb:
410 return l.tr("Search"); // the verb of the searching process
411 case SearchNext:
412 return l.tr("Search next");
413 case SearchPrev:
414 return l.tr("Search previous");
415 case Second:
416 return l.tr("2nd");
417 case Seconds:
418 return l.tr("Seconds");
419 case SecondsShort:
420 // short form of seconds
421 return l.tr("s");
422 case SeekBackward:
423 return l.tr("Seek backward");
424 case SeekForward:
425 return l.tr("Seek forward");
426 case Show:
427 return l.tr("Show");
428 case ShowAlbumArtists:
429 return l.tr("Show Album Artists");
430 case ShowCovers:
431 return l.tr("Show Covers");
432 case ShowLibrary:
433 return l.tr("Show Library");
434 case SimilarArtists:
435 return l.tr("Similar artists");
436 case SortBy:
437 return l.tr("Sort by"); // for example "sort by year"
438 case Stop:
439 return l.tr("Stop");
440 case Streams:
441 return l.tr("Streams");
442 case StreamUrl:
443 return l.tr("Stream URL");
444 case Success:
445 return l.tr("Success");
446 case Th:
447 return l.tr("th");
448 case Third:
449 return l.tr("3rd");
450 case Title:
451 return l.tr("Title");
452 case Track:
453 return l.tr("Track");
454 case TrackNo:
455 return l.tr("Track number");
456 case TrackOn:
457 return l.tr("track on");
458 case Tracks:
459 return l.tr("Tracks");
460 case Tree:
461 return l.tr("Tree");
462 case Undo:
463 return l.tr("Undo");
464 case UnknownAlbum:
465 return l.tr("Unknown album");
466 case UnknownArtist:
467 return l.tr("Unknown artist");
468 case UnknownTitle:
469 return l.tr("Unknown title");
470 case UnknownGenre:
471 return l.tr("Unknown genre");
472 case UnknownPlaceholder:
473 return l.tr("Unknown placeholder");
474 case UnknownYear:
475 {
476 QString s = l.tr("Unknown year");
477 Q_UNUSED(s)
478 }
479 return LanguageString("-");
480
481 case Various:
482 return l.tr("Various");
483 case VariousAlbums:
484 return l.tr("Various albums");
485 case VariousArtists:
486 return l.tr("Various artists");
487 case VariousTracks:
488 return l.tr("Various tracks");
489 case Version:
490 return l.tr("Version");
491 case VolumeDown:
492 return l.tr("Volume down");
493 case VolumeUp:
494 return l.tr("Volume up");
495 case Warning:
496 return l.tr("Warning");
497 case Weeks:
498 return l.tr("Weeks");
499 case Year:
500 return l.tr("Year");
501 case Years:
502 return l.tr("Years");
503 case Yes:
504 return l.tr("Yes");
505 case Zoom:
506 return l.tr("Zoom");
507 default:
508 if(ok){
509 *ok = false;
510 }
511 return QString();
512 }
513 }
514
515
getWithNumber(TermNr term,int param,bool * ok)516 LanguageString Lang::getWithNumber(TermNr term, int param, bool* ok)
517 {
518 if(ok){
519 *ok = true;
520 }
521
522 Lang l;
523
524 switch(term)
525 {
526 case NrDirectories:
527 if(param == 0){
528 return l.tr("No directories");
529 }
530
531 return l.tr("%n directory(s)", "", param);
532
533 case NrFiles:
534 if(param == 0){
535 return l.tr("No files");
536 }
537
538 return l.tr("%n file(s)", "", param);
539
540 case NrPlaylists:
541 if(param == 0){
542 return l.tr("No playlists");
543 }
544
545 return l.tr("%n playlist(s)", "", param);
546
547 case NrTracks:
548 if(param == 0) {
549 return l.tr("No tracks");
550 }
551
552 return l.tr("%n track(s)", "", param);
553
554 case NrTracksFound:
555 if(param == 0) {
556 return l.tr("No tracks found");
557 }
558
559 return l.tr("%n track(s) found", "", param);
560
561 default:
562 if(ok) {
563 *ok = false;
564 }
565
566 return QString();
567 }
568 }
569