comparison src/gui/translate/anime.cc @ 202:71832ffe425a

animia: re-add kvm fd source this is all being merged from my wildly out-of-date laptop. SORRY! in other news, I edited the CI file to install the wayland client as well, so the linux CI build might finally get wayland stuff.
author Paper <paper@paper.us.eu.org>
date Tue, 02 Jan 2024 06:05:06 -0500
parents 9613d72b097e
children 862d0d8619f6
comparison
equal deleted inserted replaced
201:8f6f8dd2eb23 202:71832ffe425a
1 #include "core/anime.h" 1 #include "core/anime.h"
2 #include "core/strings.h" 2 #include "core/strings.h"
3 #include "gui/translate/anime.h" 3 #include "gui/translate/anime.h"
4
4 #include <QCoreApplication> 5 #include <QCoreApplication>
5 6
7 #include <unordered_map>
8
6 namespace Translate { 9 namespace Translate {
7 10
8 std::string ToString(const Anime::ListStatus status) { 11 std::string ToString(const Anime::ListStatus status) {
12 switch (status) {
13 case Anime::ListStatus::CURRENT: return "Currently watching";
14 case Anime::ListStatus::PLANNING: return "Plan to watch";
15 case Anime::ListStatus::COMPLETED: return "Completed";
16 case Anime::ListStatus::DROPPED: return "Dropped";
17 case Anime::ListStatus::PAUSED: return "On hold";
18 default:
19 case Anime::ListStatus::NOT_IN_LIST: return "Not in list";
20 }
21 }
22
23 std::string ToString(const Anime::SeriesFormat format) {
24 switch (format) {
25 case Anime::SeriesFormat::TV: return "TV";
26 case Anime::SeriesFormat::TV_SHORT: return "TV short";
27 case Anime::SeriesFormat::OVA: return "OVA";
28 case Anime::SeriesFormat::MOVIE: return "Movie";
29 case Anime::SeriesFormat::SPECIAL: return "Special";
30 case Anime::SeriesFormat::ONA: return "ONA";
31 case Anime::SeriesFormat::MUSIC: return "Music";
32 default:
33 case Anime::SeriesFormat::UNKNOWN: return "Unknown";
34 }
35 }
36
37 std::string ToString(const Anime::SeriesSeason season) {
38 switch (season) {
39 case Anime::SeriesSeason::WINTER: return "Winter";
40 case Anime::SeriesSeason::SUMMER: return "Summer";
41 case Anime::SeriesSeason::FALL: return "Fall";
42 case Anime::SeriesSeason::SPRING: return "Spring";
43 default:
44 case Anime::SeriesSeason::UNKNOWN: return "Unknown";
45 }
46 }
47
48 std::string ToString(const Anime::SeriesStatus status) {
49 switch (status) {
50 case Anime::SeriesStatus::RELEASING: return "Currently airing";
51 case Anime::SeriesStatus::FINISHED: return "Finished airing";
52 case Anime::SeriesStatus::NOT_YET_RELEASED: return "Not yet aired";
53 case Anime::SeriesStatus::CANCELLED: return "Cancelled";
54 case Anime::SeriesStatus::HIATUS: return "On hiatus";
55 default:
56 case Anime::SeriesStatus::UNKNOWN: return "Unknown";
57 }
58 }
59
60 std::string ToString(const Anime::Services service) {
61 switch (service) {
62 case Anime::Services::ANILIST: return "AniList";
63 default:
64 case Anime::Services::NONE: return "None";
65 }
66 }
67
68 std::string ToString(const Anime::TitleLanguage language) {
69 switch (language) {
70 case Anime::TitleLanguage::NATIVE: return "Native";
71 case Anime::TitleLanguage::ENGLISH: return "English";
72 default:
73 case Anime::TitleLanguage::ROMAJI: return "Romaji";
74 }
75 }
76
77 std::string ToString(const Anime::ScoreFormat format) {
78 switch (format) {
79 case Anime::ScoreFormat::POINT_3: return "POINT_3";
80 case Anime::ScoreFormat::POINT_5: return "POINT_5";
81 case Anime::ScoreFormat::POINT_10: return "POINT_10";
82 case Anime::ScoreFormat::POINT_10_DECIMAL: return "POINT_10_DECIMAL";
83 default:
84 case Anime::ScoreFormat::POINT_100: return "POINT_100";
85 }
86 }
87
88 Anime::ListStatus ToListStatus(const std::string& str) {
89 static const std::unordered_map<std::string, Anime::ListStatus> map = {
90 {"Currently watching", Anime::ListStatus::CURRENT},
91 {"Plan to watch", Anime::ListStatus::PLANNING},
92 {"Completed", Anime::ListStatus::COMPLETED},
93 {"Dropped", Anime::ListStatus::DROPPED},
94 {"On hold", Anime::ListStatus::PAUSED}
95 };
96
97 if (map.find(str) == map.end())
98 return Anime::ListStatus::NOT_IN_LIST;
99 return map.at(str);
100 }
101
102 Anime::SeriesStatus ToSeriesStatus(const std::string& str) {
103 static const std::unordered_map<std::string, Anime::SeriesStatus> map = {
104 {"Currently airing", Anime::SeriesStatus::RELEASING},
105 {"Finished airing", Anime::SeriesStatus::FINISHED},
106 {"Not yet aired", Anime::SeriesStatus::NOT_YET_RELEASED},
107 {"Cancelled", Anime::SeriesStatus::CANCELLED},
108 {"On hiatus", Anime::SeriesStatus::HIATUS}
109 };
110
111 if (map.find(str) == map.end())
112 return Anime::SeriesStatus::UNKNOWN;
113 return map.at(str);
114 }
115
116 Anime::SeriesSeason ToSeriesSeason(const std::string& str) {
117 static const std::unordered_map<std::string, Anime::SeriesSeason> map = {
118 {"Winter", Anime::SeriesSeason::WINTER},
119 {"Summer", Anime::SeriesSeason::SUMMER},
120 {"Fall", Anime::SeriesSeason::FALL},
121 {"Spring", Anime::SeriesSeason::SPRING}
122 };
123
124 if (map.find(str) == map.end())
125 return Anime::SeriesSeason::UNKNOWN;
126 return map.at(str);
127 }
128
129 Anime::SeriesFormat ToSeriesFormat(const std::string& str) {
130 static const std::unordered_map<std::string, Anime::SeriesFormat> map = {
131 {"TV", Anime::SeriesFormat::TV},
132 {"TV short", Anime::SeriesFormat::TV_SHORT},
133 {"OVA", Anime::SeriesFormat::OVA},
134 {"Movie", Anime::SeriesFormat::MOVIE},
135 {"Special", Anime::SeriesFormat::SPECIAL},
136 {"ONA", Anime::SeriesFormat::ONA},
137 {"Music", Anime::SeriesFormat::MUSIC}
138 };
139
140 if (map.find(str) == map.end())
141 return Anime::SeriesFormat::UNKNOWN;
142 return map.at(str);
143 }
144
145 Anime::Services ToService(const std::string& str) {
146 static const std::unordered_map<std::string, Anime::Services> map = {
147 {"AniList", Anime::Services::ANILIST}
148 };
149
150 if (map.find(str) == map.end())
151 return Anime::Services::NONE;
152 return map.at(str);
153 }
154
155 Anime::TitleLanguage ToLanguage(const std::string& str) {
156 static const std::unordered_map<std::string, Anime::TitleLanguage> map = {
157 {"Romaji", Anime::TitleLanguage::ROMAJI},
158 {"Native", Anime::TitleLanguage::NATIVE},
159 {"English", Anime::TitleLanguage::ENGLISH}
160 };
161
162 if (map.find(str) == map.end())
163 return Anime::TitleLanguage::ROMAJI;
164 return map.at(str);
165 }
166
167 Anime::ScoreFormat ToScoreFormat(const std::string& str) {
168 static const std::unordered_map<std::string, Anime::ScoreFormat> map = {
169 {"POINT_3", Anime::ScoreFormat::POINT_3},
170 {"POINT_5", Anime::ScoreFormat::POINT_5},
171 {"POINT_10", Anime::ScoreFormat::POINT_10},
172 {"POINT_10_DECIMAL", Anime::ScoreFormat::POINT_10_DECIMAL},
173 {"POINT_100", Anime::ScoreFormat::POINT_100}
174 };
175
176 if (map.find(str) == map.end())
177 return Anime::ScoreFormat::POINT_100;
178 return map.at(str);
179 }
180
181 /* Localized versions of ToString() functions. Meant for display to the user. */
182
183 std::string ToLocalString(const Anime::ListStatus status) {
9 switch (status) { 184 switch (status) {
10 case Anime::ListStatus::CURRENT: return Strings::ToUtf8String(QCoreApplication::tr("Currently watching")); 185 case Anime::ListStatus::CURRENT: return Strings::ToUtf8String(QCoreApplication::tr("Currently watching"));
11 case Anime::ListStatus::PLANNING: return Strings::ToUtf8String(QCoreApplication::tr("Plan to watch")); 186 case Anime::ListStatus::PLANNING: return Strings::ToUtf8String(QCoreApplication::tr("Plan to watch"));
12 case Anime::ListStatus::COMPLETED: return Strings::ToUtf8String(QCoreApplication::tr("Completed")); 187 case Anime::ListStatus::COMPLETED: return Strings::ToUtf8String(QCoreApplication::tr("Completed"));
13 case Anime::ListStatus::DROPPED: return Strings::ToUtf8String(QCoreApplication::tr("Dropped")); 188 case Anime::ListStatus::DROPPED: return Strings::ToUtf8String(QCoreApplication::tr("Dropped"));
15 default: 190 default:
16 case Anime::ListStatus::NOT_IN_LIST: return Strings::ToUtf8String(QCoreApplication::tr("Not in list")); 191 case Anime::ListStatus::NOT_IN_LIST: return Strings::ToUtf8String(QCoreApplication::tr("Not in list"));
17 } 192 }
18 } 193 }
19 194
20 std::string ToString(const Anime::SeriesFormat format) { 195 std::string ToLocalString(const Anime::SeriesFormat format) {
21 switch (format) { 196 switch (format) {
22 case Anime::SeriesFormat::TV: return Strings::ToUtf8String(QCoreApplication::tr("TV")); 197 case Anime::SeriesFormat::TV: return Strings::ToUtf8String(QCoreApplication::tr("TV"));
23 case Anime::SeriesFormat::TV_SHORT: return Strings::ToUtf8String(QCoreApplication::tr("TV short")); 198 case Anime::SeriesFormat::TV_SHORT: return Strings::ToUtf8String(QCoreApplication::tr("TV short"));
24 case Anime::SeriesFormat::OVA: return Strings::ToUtf8String(QCoreApplication::tr("OVA")); 199 case Anime::SeriesFormat::OVA: return Strings::ToUtf8String(QCoreApplication::tr("OVA"));
25 case Anime::SeriesFormat::MOVIE: return Strings::ToUtf8String(QCoreApplication::tr("Movie")); 200 case Anime::SeriesFormat::MOVIE: return Strings::ToUtf8String(QCoreApplication::tr("Movie"));
29 default: 204 default:
30 case Anime::SeriesFormat::UNKNOWN: return Strings::ToUtf8String(QCoreApplication::tr("Unknown")); 205 case Anime::SeriesFormat::UNKNOWN: return Strings::ToUtf8String(QCoreApplication::tr("Unknown"));
31 } 206 }
32 } 207 }
33 208
34 std::string ToString(const Anime::SeriesSeason season) { 209 std::string ToLocalString(const Anime::SeriesSeason season) {
35 switch (season) { 210 switch (season) {
36 case Anime::SeriesSeason::WINTER: return Strings::ToUtf8String(QCoreApplication::tr("Winter")); 211 case Anime::SeriesSeason::WINTER: return Strings::ToUtf8String(QCoreApplication::tr("Winter"));
37 case Anime::SeriesSeason::SUMMER: return Strings::ToUtf8String(QCoreApplication::tr("Summer")); 212 case Anime::SeriesSeason::SUMMER: return Strings::ToUtf8String(QCoreApplication::tr("Summer"));
38 case Anime::SeriesSeason::FALL: return Strings::ToUtf8String(QCoreApplication::tr("Fall")); 213 case Anime::SeriesSeason::FALL: return Strings::ToUtf8String(QCoreApplication::tr("Fall"));
39 case Anime::SeriesSeason::SPRING: return Strings::ToUtf8String(QCoreApplication::tr("Spring")); 214 case Anime::SeriesSeason::SPRING: return Strings::ToUtf8String(QCoreApplication::tr("Spring"));
40 default: 215 default:
41 case Anime::SeriesSeason::UNKNOWN: return Strings::ToUtf8String(QCoreApplication::tr("Unknown")); 216 case Anime::SeriesSeason::UNKNOWN: return Strings::ToUtf8String(QCoreApplication::tr("Unknown"));
42 } 217 }
43 } 218 }
44 219
45 std::string ToString(const Anime::SeriesStatus status) { 220 std::string ToLocalString(const Anime::SeriesStatus status) {
46 switch (status) { 221 switch (status) {
47 case Anime::SeriesStatus::RELEASING: return Strings::ToUtf8String(QCoreApplication::tr("Currently airing")); 222 case Anime::SeriesStatus::RELEASING: return Strings::ToUtf8String(QCoreApplication::tr("Currently airing"));
48 case Anime::SeriesStatus::FINISHED: return Strings::ToUtf8String(QCoreApplication::tr("Finished airing")); 223 case Anime::SeriesStatus::FINISHED: return Strings::ToUtf8String(QCoreApplication::tr("Finished airing"));
49 case Anime::SeriesStatus::NOT_YET_RELEASED: return Strings::ToUtf8String(QCoreApplication::tr("Not yet aired")); 224 case Anime::SeriesStatus::NOT_YET_RELEASED: return Strings::ToUtf8String(QCoreApplication::tr("Not yet aired"));
50 case Anime::SeriesStatus::CANCELLED: return Strings::ToUtf8String(QCoreApplication::tr("Cancelled")); 225 case Anime::SeriesStatus::CANCELLED: return Strings::ToUtf8String(QCoreApplication::tr("Cancelled"));
52 default: 227 default:
53 case Anime::SeriesStatus::UNKNOWN: return Strings::ToUtf8String(QCoreApplication::tr("Unknown")); 228 case Anime::SeriesStatus::UNKNOWN: return Strings::ToUtf8String(QCoreApplication::tr("Unknown"));
54 } 229 }
55 } 230 }
56 231
57 std::string ToString(const Anime::Services service) { 232 std::string ToLocalString(const Anime::Services service) {
58 switch (service) { 233 switch (service) {
59 case Anime::Services::ANILIST: return Strings::ToUtf8String(QCoreApplication::tr("AniList")); 234 case Anime::Services::ANILIST: return Strings::ToUtf8String(QCoreApplication::tr("AniList"));
60 default: 235 default:
61 case Anime::Services::NONE: return Strings::ToUtf8String(QCoreApplication::tr("None")); 236 case Anime::Services::NONE: return Strings::ToUtf8String(QCoreApplication::tr("None"));
62 } 237 }
63 } 238 }
64 239
65 Anime::Services ToService(const std::string& str) { 240 std::string ToLocalString(const Anime::TitleLanguage language) {
66 const std::unordered_map<std::string, Anime::Services> map = {
67 {"None", Anime::Services::NONE },
68 {"AniList", Anime::Services::ANILIST}
69 };
70
71 if (map.find(str) == map.end())
72 return Anime::Services::NONE;
73 return map.at(str);
74 }
75
76 std::string ToString(const Anime::TitleLanguage language) {
77 switch (language) { 241 switch (language) {
78 case Anime::TitleLanguage::NATIVE: return Strings::ToUtf8String(QCoreApplication::tr("Native")); 242 case Anime::TitleLanguage::NATIVE: return Strings::ToUtf8String(QCoreApplication::tr("Native"));
79 case Anime::TitleLanguage::ENGLISH: return Strings::ToUtf8String(QCoreApplication::tr("English")); 243 case Anime::TitleLanguage::ENGLISH: return Strings::ToUtf8String(QCoreApplication::tr("English"));
80 default: 244 default:
81 case Anime::TitleLanguage::ROMAJI: return Strings::ToUtf8String(QCoreApplication::tr("Romaji")); 245 case Anime::TitleLanguage::ROMAJI: return Strings::ToUtf8String(QCoreApplication::tr("Romaji"));
82 } 246 }
83 } 247 }
84 248
85 Anime::TitleLanguage ToLanguage(const std::string& str) { 249 std::string ToLocalString(const Anime::ScoreFormat format) {
86 const std::unordered_map<std::string, Anime::TitleLanguage> map = { 250 switch (format) {
87 {"Romaji", Anime::TitleLanguage::ROMAJI}, 251 case Anime::ScoreFormat::POINT_3: return Strings::ToUtf8String(QCoreApplication::tr("3-point"));
88 {"Native", Anime::TitleLanguage::NATIVE}, 252 case Anime::ScoreFormat::POINT_5: return Strings::ToUtf8String(QCoreApplication::tr("5-point"));
89 {"English", Anime::TitleLanguage::ENGLISH} 253 case Anime::ScoreFormat::POINT_10: return Strings::ToUtf8String(QCoreApplication::tr("10-point"));
90 }; 254 case Anime::ScoreFormat::POINT_10_DECIMAL: return Strings::ToUtf8String(QCoreApplication::tr("10-point (Decimal)"));
91 255 default:
92 if (map.find(str) == map.end()) 256 case Anime::ScoreFormat::POINT_100: return Strings::ToUtf8String(QCoreApplication::tr("100-point"));
93 return Anime::TitleLanguage::ROMAJI; 257 }
94 return map.at(str);
95 } 258 }
96 259
97 } // namespace Translate 260 } // namespace Translate