Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/gui/translate/anime.cc Thu Jun 13 00:42:00 2024 -0400 +++ b/src/gui/translate/anime.cc Thu Jun 13 01:49:18 2024 -0400 @@ -34,14 +34,14 @@ } } -std::string ToString(const Anime::SeriesSeason season) { +std::string ToString(const Anime::Season::Name season) { switch (season) { - case Anime::SeriesSeason::Winter: return "Winter"; - case Anime::SeriesSeason::Summer: return "Summer"; - case Anime::SeriesSeason::Fall: return "Fall"; - case Anime::SeriesSeason::Spring: return "Spring"; + case Anime::Season::Name::Winter: return "Winter"; + case Anime::Season::Name::Summer: return "Summer"; + case Anime::Season::Name::Autumn: return "Autumn"; + case Anime::Season::Name::Spring: return "Spring"; default: - case Anime::SeriesSeason::Unknown: return "Unknown"; + case Anime::Season::Name::Unknown: return "Unknown"; } } @@ -89,83 +89,96 @@ Anime::ListStatus ToListStatus(const std::string& str) { static const std::unordered_map<std::string, Anime::ListStatus> map = { - {"Currently watching", Anime::ListStatus::Current }, - {"Plan to watch", Anime::ListStatus::Planning }, - {"Completed", Anime::ListStatus::Completed}, - {"Dropped", Anime::ListStatus::Dropped }, - {"On hold", Anime::ListStatus::Paused } - }; + {"currently watching", Anime::ListStatus::Current }, + {"plan to watch", Anime::ListStatus::Planning }, + {"completed", Anime::ListStatus::Completed}, + {"dropped", Anime::ListStatus::Dropped }, + {"on hold", Anime::ListStatus::Paused } + }; - if (map.find(str) == map.end()) + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) return Anime::ListStatus::NotInList; - return map.at(str); + return map.at(lower); } Anime::SeriesStatus ToSeriesStatus(const std::string& str) { static const std::unordered_map<std::string, Anime::SeriesStatus> map = { - {"Currently airing", Anime::SeriesStatus::Releasing }, - {"Finished airing", Anime::SeriesStatus::Finished }, - {"Not yet aired", Anime::SeriesStatus::NotYetReleased}, - {"Cancelled", Anime::SeriesStatus::Cancelled }, - {"On hiatus", Anime::SeriesStatus::Hiatus } - }; + {"currently airing", Anime::SeriesStatus::Releasing }, + {"finished airing", Anime::SeriesStatus::Finished }, + {"not yet aired", Anime::SeriesStatus::NotYetReleased}, + {"cancelled", Anime::SeriesStatus::Cancelled }, + {"on hiatus", Anime::SeriesStatus::Hiatus } + }; + + std::string lower = Strings::ToLower(str); if (map.find(str) == map.end()) return Anime::SeriesStatus::Unknown; return map.at(str); } -Anime::SeriesSeason ToSeriesSeason(const std::string& str) { - static const std::unordered_map<std::string, Anime::SeriesSeason> map = { - {"Winter", Anime::SeriesSeason::Winter}, - {"Summer", Anime::SeriesSeason::Summer}, - {"Fall", Anime::SeriesSeason::Fall }, - {"Spring", Anime::SeriesSeason::Spring} - }; +Anime::Season::Name ToSeriesSeason(const std::string& str) { + static const std::unordered_map<std::string, Anime::Season::Name> map = { + {"winter", Anime::Season::Name::Winter}, + {"summer", Anime::Season::Name::Summer}, + {"fall", Anime::Season::Name::Autumn}, + {"autumn", Anime::Season::Name::Autumn}, + {"spring", Anime::Season::Name::Spring}, + }; - if (map.find(str) == map.end()) - return Anime::SeriesSeason::Unknown; - return map.at(str); + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) + return Anime::Season::Name::Unknown; + return map.at(lower); } Anime::SeriesFormat ToSeriesFormat(const std::string& str) { static const std::unordered_map<std::string, Anime::SeriesFormat> map = { - {"TV", Anime::SeriesFormat::Tv }, - {"TV short", Anime::SeriesFormat::TvShort}, - {"OVA", Anime::SeriesFormat::Ova }, - {"Movie", Anime::SeriesFormat::Movie }, - {"Special", Anime::SeriesFormat::Special }, - {"ONA", Anime::SeriesFormat::Ona }, - {"Music", Anime::SeriesFormat::Music } - }; + {"tv", Anime::SeriesFormat::Tv }, + {"tv short", Anime::SeriesFormat::TvShort}, + {"ova", Anime::SeriesFormat::Ova }, + {"movie", Anime::SeriesFormat::Movie }, + {"special", Anime::SeriesFormat::Special }, + {"ona", Anime::SeriesFormat::Ona }, + {"music", Anime::SeriesFormat::Music } + }; - if (map.find(str) == map.end()) + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) return Anime::SeriesFormat::Unknown; - return map.at(str); + return map.at(lower); } Anime::Service ToService(const std::string& str) { static const std::unordered_map<std::string, Anime::Service> map = { - {"AniList", Anime::Service::AniList}, - {"MyAnimeList", Anime::Service::MyAnimeList}, - {"Kitsu", Anime::Service::Kitsu} - }; + {"anilist", Anime::Service::AniList}, + {"myanimelist", Anime::Service::MyAnimeList}, + {"kitsu", Anime::Service::Kitsu} + }; - if (map.find(str) == map.end()) + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) return Anime::Service::None; - return map.at(str); + return map.at(lower); } Anime::TitleLanguage ToLanguage(const std::string& str) { static const std::unordered_map<std::string, Anime::TitleLanguage> map = { - {"Romaji", Anime::TitleLanguage::Romaji }, - {"Native", Anime::TitleLanguage::Native }, - {"English", Anime::TitleLanguage::English} - }; + {"romaji", Anime::TitleLanguage::Romaji }, + {"native", Anime::TitleLanguage::Native }, + {"english", Anime::TitleLanguage::English} + }; - if (map.find(str) == map.end()) + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) return Anime::TitleLanguage::Romaji; - return map.at(str); + return map.at(lower); } Anime::ScoreFormat ToScoreFormat(const std::string& str) { @@ -173,19 +186,21 @@ {"3-point", Anime::ScoreFormat::Point3}, {"5-point", Anime::ScoreFormat::Point5}, {"10-point", Anime::ScoreFormat::Point10 }, - {"10-point Decimal", Anime::ScoreFormat::Point10Decimal}, + {"10-point decimal", Anime::ScoreFormat::Point10Decimal}, {"100-point", Anime::ScoreFormat::Point100 }, /* old values, provided for compatibility */ - {"POINT_3", Anime::ScoreFormat::Point3 }, - {"POINT_5", Anime::ScoreFormat::Point5 }, - {"POINT_10", Anime::ScoreFormat::Point10 }, - {"POINT_10_DECIMAL", Anime::ScoreFormat::Point10Decimal}, - {"POINT_100", Anime::ScoreFormat::Point100 } - }; + {"point_3", Anime::ScoreFormat::Point3 }, + {"point_5", Anime::ScoreFormat::Point5 }, + {"point_10", Anime::ScoreFormat::Point10 }, + {"point_10_decimal", Anime::ScoreFormat::Point10Decimal}, + {"point_100", Anime::ScoreFormat::Point100 }, + }; - if (map.find(str) == map.end()) + std::string lower = Strings::ToLower(str); + + if (map.find(lower) == map.end()) return Anime::ScoreFormat::Point100; - return map.at(str); + return map.at(lower); } /* Localized versions of ToString() functions. Meant for display to the user. */ @@ -216,17 +231,23 @@ } } -std::string ToLocalString(const Anime::SeriesSeason season) { +std::string ToLocalString(const Anime::Season::Name season) { switch (season) { - case Anime::SeriesSeason::Winter: return Strings::Translate("Winter"); - case Anime::SeriesSeason::Summer: return Strings::Translate("Summer"); - case Anime::SeriesSeason::Fall: return Strings::Translate("Fall"); - case Anime::SeriesSeason::Spring: return Strings::Translate("Spring"); + case Anime::Season::Name::Winter: return Strings::Translate("Winter"); + case Anime::Season::Name::Summer: return Strings::Translate("Summer"); + case Anime::Season::Name::Autumn: return Strings::Translate("Autumn"); + case Anime::Season::Name::Spring: return Strings::Translate("Spring"); default: - case Anime::SeriesSeason::Unknown: return Strings::Translate("Unknown"); + case Anime::Season::Name::Unknown: return Strings::Translate("Unknown"); } } +std::string ToLocalString(const Anime::Season& season) { + std::string year = (season.year) ? Strings::ToUtf8String(season.year) : Strings::Translate("Unknown"); + + return ToLocalString(season.season) + " " + year; +} + std::string ToLocalString(const Anime::SeriesStatus status) { switch (status) { case Anime::SeriesStatus::Releasing: return Strings::Translate("Currently airing");