comparison src/gui/translate/anime.cc @ 327:b5d6c27c308f

anime: refactor Anime::SeriesSeason to Season class ToLocalString has also been altered to take in both season and year because lots of locales actually treat formatting seasons differently! most notably is Russian which adds a suffix at the end to notate seasons(??)
author Paper <paper@paper.us.eu.org>
date Thu, 13 Jun 2024 01:49:18 -0400
parents c32467cd06bb
children 5980a960f3e1
comparison
equal deleted inserted replaced
326:10096c5489e3 327:b5d6c27c308f
32 default: 32 default:
33 case Anime::SeriesFormat::Unknown: return "Unknown"; 33 case Anime::SeriesFormat::Unknown: return "Unknown";
34 } 34 }
35 } 35 }
36 36
37 std::string ToString(const Anime::SeriesSeason season) { 37 std::string ToString(const Anime::Season::Name season) {
38 switch (season) { 38 switch (season) {
39 case Anime::SeriesSeason::Winter: return "Winter"; 39 case Anime::Season::Name::Winter: return "Winter";
40 case Anime::SeriesSeason::Summer: return "Summer"; 40 case Anime::Season::Name::Summer: return "Summer";
41 case Anime::SeriesSeason::Fall: return "Fall"; 41 case Anime::Season::Name::Autumn: return "Autumn";
42 case Anime::SeriesSeason::Spring: return "Spring"; 42 case Anime::Season::Name::Spring: return "Spring";
43 default: 43 default:
44 case Anime::SeriesSeason::Unknown: return "Unknown"; 44 case Anime::Season::Name::Unknown: return "Unknown";
45 } 45 }
46 } 46 }
47 47
48 std::string ToString(const Anime::SeriesStatus status) { 48 std::string ToString(const Anime::SeriesStatus status) {
49 switch (status) { 49 switch (status) {
87 } 87 }
88 } 88 }
89 89
90 Anime::ListStatus ToListStatus(const std::string& str) { 90 Anime::ListStatus ToListStatus(const std::string& str) {
91 static const std::unordered_map<std::string, Anime::ListStatus> map = { 91 static const std::unordered_map<std::string, Anime::ListStatus> map = {
92 {"Currently watching", Anime::ListStatus::Current }, 92 {"currently watching", Anime::ListStatus::Current },
93 {"Plan to watch", Anime::ListStatus::Planning }, 93 {"plan to watch", Anime::ListStatus::Planning },
94 {"Completed", Anime::ListStatus::Completed}, 94 {"completed", Anime::ListStatus::Completed},
95 {"Dropped", Anime::ListStatus::Dropped }, 95 {"dropped", Anime::ListStatus::Dropped },
96 {"On hold", Anime::ListStatus::Paused } 96 {"on hold", Anime::ListStatus::Paused }
97 }; 97 };
98 98
99 if (map.find(str) == map.end()) 99 std::string lower = Strings::ToLower(str);
100
101 if (map.find(lower) == map.end())
100 return Anime::ListStatus::NotInList; 102 return Anime::ListStatus::NotInList;
101 return map.at(str); 103 return map.at(lower);
102 } 104 }
103 105
104 Anime::SeriesStatus ToSeriesStatus(const std::string& str) { 106 Anime::SeriesStatus ToSeriesStatus(const std::string& str) {
105 static const std::unordered_map<std::string, Anime::SeriesStatus> map = { 107 static const std::unordered_map<std::string, Anime::SeriesStatus> map = {
106 {"Currently airing", Anime::SeriesStatus::Releasing }, 108 {"currently airing", Anime::SeriesStatus::Releasing },
107 {"Finished airing", Anime::SeriesStatus::Finished }, 109 {"finished airing", Anime::SeriesStatus::Finished },
108 {"Not yet aired", Anime::SeriesStatus::NotYetReleased}, 110 {"not yet aired", Anime::SeriesStatus::NotYetReleased},
109 {"Cancelled", Anime::SeriesStatus::Cancelled }, 111 {"cancelled", Anime::SeriesStatus::Cancelled },
110 {"On hiatus", Anime::SeriesStatus::Hiatus } 112 {"on hiatus", Anime::SeriesStatus::Hiatus }
111 }; 113 };
114
115 std::string lower = Strings::ToLower(str);
112 116
113 if (map.find(str) == map.end()) 117 if (map.find(str) == map.end())
114 return Anime::SeriesStatus::Unknown; 118 return Anime::SeriesStatus::Unknown;
115 return map.at(str); 119 return map.at(str);
116 } 120 }
117 121
118 Anime::SeriesSeason ToSeriesSeason(const std::string& str) { 122 Anime::Season::Name ToSeriesSeason(const std::string& str) {
119 static const std::unordered_map<std::string, Anime::SeriesSeason> map = { 123 static const std::unordered_map<std::string, Anime::Season::Name> map = {
120 {"Winter", Anime::SeriesSeason::Winter}, 124 {"winter", Anime::Season::Name::Winter},
121 {"Summer", Anime::SeriesSeason::Summer}, 125 {"summer", Anime::Season::Name::Summer},
122 {"Fall", Anime::SeriesSeason::Fall }, 126 {"fall", Anime::Season::Name::Autumn},
123 {"Spring", Anime::SeriesSeason::Spring} 127 {"autumn", Anime::Season::Name::Autumn},
124 }; 128 {"spring", Anime::Season::Name::Spring},
125 129 };
126 if (map.find(str) == map.end()) 130
127 return Anime::SeriesSeason::Unknown; 131 std::string lower = Strings::ToLower(str);
128 return map.at(str); 132
133 if (map.find(lower) == map.end())
134 return Anime::Season::Name::Unknown;
135 return map.at(lower);
129 } 136 }
130 137
131 Anime::SeriesFormat ToSeriesFormat(const std::string& str) { 138 Anime::SeriesFormat ToSeriesFormat(const std::string& str) {
132 static const std::unordered_map<std::string, Anime::SeriesFormat> map = { 139 static const std::unordered_map<std::string, Anime::SeriesFormat> map = {
133 {"TV", Anime::SeriesFormat::Tv }, 140 {"tv", Anime::SeriesFormat::Tv },
134 {"TV short", Anime::SeriesFormat::TvShort}, 141 {"tv short", Anime::SeriesFormat::TvShort},
135 {"OVA", Anime::SeriesFormat::Ova }, 142 {"ova", Anime::SeriesFormat::Ova },
136 {"Movie", Anime::SeriesFormat::Movie }, 143 {"movie", Anime::SeriesFormat::Movie },
137 {"Special", Anime::SeriesFormat::Special }, 144 {"special", Anime::SeriesFormat::Special },
138 {"ONA", Anime::SeriesFormat::Ona }, 145 {"ona", Anime::SeriesFormat::Ona },
139 {"Music", Anime::SeriesFormat::Music } 146 {"music", Anime::SeriesFormat::Music }
140 }; 147 };
141 148
142 if (map.find(str) == map.end()) 149 std::string lower = Strings::ToLower(str);
150
151 if (map.find(lower) == map.end())
143 return Anime::SeriesFormat::Unknown; 152 return Anime::SeriesFormat::Unknown;
144 return map.at(str); 153 return map.at(lower);
145 } 154 }
146 155
147 Anime::Service ToService(const std::string& str) { 156 Anime::Service ToService(const std::string& str) {
148 static const std::unordered_map<std::string, Anime::Service> map = { 157 static const std::unordered_map<std::string, Anime::Service> map = {
149 {"AniList", Anime::Service::AniList}, 158 {"anilist", Anime::Service::AniList},
150 {"MyAnimeList", Anime::Service::MyAnimeList}, 159 {"myanimelist", Anime::Service::MyAnimeList},
151 {"Kitsu", Anime::Service::Kitsu} 160 {"kitsu", Anime::Service::Kitsu}
152 }; 161 };
153 162
154 if (map.find(str) == map.end()) 163 std::string lower = Strings::ToLower(str);
164
165 if (map.find(lower) == map.end())
155 return Anime::Service::None; 166 return Anime::Service::None;
156 return map.at(str); 167 return map.at(lower);
157 } 168 }
158 169
159 Anime::TitleLanguage ToLanguage(const std::string& str) { 170 Anime::TitleLanguage ToLanguage(const std::string& str) {
160 static const std::unordered_map<std::string, Anime::TitleLanguage> map = { 171 static const std::unordered_map<std::string, Anime::TitleLanguage> map = {
161 {"Romaji", Anime::TitleLanguage::Romaji }, 172 {"romaji", Anime::TitleLanguage::Romaji },
162 {"Native", Anime::TitleLanguage::Native }, 173 {"native", Anime::TitleLanguage::Native },
163 {"English", Anime::TitleLanguage::English} 174 {"english", Anime::TitleLanguage::English}
164 }; 175 };
165 176
166 if (map.find(str) == map.end()) 177 std::string lower = Strings::ToLower(str);
178
179 if (map.find(lower) == map.end())
167 return Anime::TitleLanguage::Romaji; 180 return Anime::TitleLanguage::Romaji;
168 return map.at(str); 181 return map.at(lower);
169 } 182 }
170 183
171 Anime::ScoreFormat ToScoreFormat(const std::string& str) { 184 Anime::ScoreFormat ToScoreFormat(const std::string& str) {
172 static const std::unordered_map<std::string, Anime::ScoreFormat> map = { 185 static const std::unordered_map<std::string, Anime::ScoreFormat> map = {
173 {"3-point", Anime::ScoreFormat::Point3}, 186 {"3-point", Anime::ScoreFormat::Point3},
174 {"5-point", Anime::ScoreFormat::Point5}, 187 {"5-point", Anime::ScoreFormat::Point5},
175 {"10-point", Anime::ScoreFormat::Point10 }, 188 {"10-point", Anime::ScoreFormat::Point10 },
176 {"10-point Decimal", Anime::ScoreFormat::Point10Decimal}, 189 {"10-point decimal", Anime::ScoreFormat::Point10Decimal},
177 {"100-point", Anime::ScoreFormat::Point100 }, 190 {"100-point", Anime::ScoreFormat::Point100 },
178 /* old values, provided for compatibility */ 191 /* old values, provided for compatibility */
179 {"POINT_3", Anime::ScoreFormat::Point3 }, 192 {"point_3", Anime::ScoreFormat::Point3 },
180 {"POINT_5", Anime::ScoreFormat::Point5 }, 193 {"point_5", Anime::ScoreFormat::Point5 },
181 {"POINT_10", Anime::ScoreFormat::Point10 }, 194 {"point_10", Anime::ScoreFormat::Point10 },
182 {"POINT_10_DECIMAL", Anime::ScoreFormat::Point10Decimal}, 195 {"point_10_decimal", Anime::ScoreFormat::Point10Decimal},
183 {"POINT_100", Anime::ScoreFormat::Point100 } 196 {"point_100", Anime::ScoreFormat::Point100 },
184 }; 197 };
185 198
186 if (map.find(str) == map.end()) 199 std::string lower = Strings::ToLower(str);
200
201 if (map.find(lower) == map.end())
187 return Anime::ScoreFormat::Point100; 202 return Anime::ScoreFormat::Point100;
188 return map.at(str); 203 return map.at(lower);
189 } 204 }
190 205
191 /* Localized versions of ToString() functions. Meant for display to the user. */ 206 /* Localized versions of ToString() functions. Meant for display to the user. */
192 207
193 std::string ToLocalString(const Anime::ListStatus status) { 208 std::string ToLocalString(const Anime::ListStatus status) {
214 default: 229 default:
215 case Anime::SeriesFormat::Unknown: return Strings::Translate("Unknown"); 230 case Anime::SeriesFormat::Unknown: return Strings::Translate("Unknown");
216 } 231 }
217 } 232 }
218 233
219 std::string ToLocalString(const Anime::SeriesSeason season) { 234 std::string ToLocalString(const Anime::Season::Name season) {
220 switch (season) { 235 switch (season) {
221 case Anime::SeriesSeason::Winter: return Strings::Translate("Winter"); 236 case Anime::Season::Name::Winter: return Strings::Translate("Winter");
222 case Anime::SeriesSeason::Summer: return Strings::Translate("Summer"); 237 case Anime::Season::Name::Summer: return Strings::Translate("Summer");
223 case Anime::SeriesSeason::Fall: return Strings::Translate("Fall"); 238 case Anime::Season::Name::Autumn: return Strings::Translate("Autumn");
224 case Anime::SeriesSeason::Spring: return Strings::Translate("Spring"); 239 case Anime::Season::Name::Spring: return Strings::Translate("Spring");
225 default: 240 default:
226 case Anime::SeriesSeason::Unknown: return Strings::Translate("Unknown"); 241 case Anime::Season::Name::Unknown: return Strings::Translate("Unknown");
227 } 242 }
243 }
244
245 std::string ToLocalString(const Anime::Season& season) {
246 std::string year = (season.year) ? Strings::ToUtf8String(season.year) : Strings::Translate("Unknown");
247
248 return ToLocalString(season.season) + " " + year;
228 } 249 }
229 250
230 std::string ToLocalString(const Anime::SeriesStatus status) { 251 std::string ToLocalString(const Anime::SeriesStatus status) {
231 switch (status) { 252 switch (status) {
232 case Anime::SeriesStatus::Releasing: return Strings::Translate("Currently airing"); 253 case Anime::SeriesStatus::Releasing: return Strings::Translate("Currently airing");