view src/gui/translate/anilist.cc @ 334:948955c3ba81

services: use fmt for setting the status bar this should make localization easier
author Paper <paper@paper.us.eu.org>
date Mon, 17 Jun 2024 20:35:31 -0400
parents b5d6c27c308f
children
line wrap: on
line source

#include "gui/translate/anilist.h"
#include <unordered_map>

namespace Translate {
namespace AniList {

Anime::SeriesStatus ToSeriesStatus(const std::string& status) {
	static const std::unordered_map<std::string, Anime::SeriesStatus> map = {
	    {"FINISHED",         Anime::SeriesStatus::Finished        },
	    {"RELEASING",        Anime::SeriesStatus::Releasing       },
	    {"NOT_YET_RELEASED", Anime::SeriesStatus::NotYetReleased},
	    {"CANCELLED",        Anime::SeriesStatus::Cancelled       },
	    {"HIATUS",           Anime::SeriesStatus::Hiatus          }
    };

	if (map.find(status) == map.end())
		return Anime::SeriesStatus::Unknown;
	return map.at(status);
}

Anime::Season::Name ToSeriesSeason(const std::string& season) {
	static const std::unordered_map<std::string, Anime::Season::Name> map = {
	    {"WINTER", Anime::Season::Name::Winter},
	    {"SPRING", Anime::Season::Name::Spring},
	    {"SUMMER", Anime::Season::Name::Summer},
	    {"FALL",   Anime::Season::Name::Autumn}
    };

	if (map.find(season) == map.end())
		return Anime::Season::Name::Unknown;
	return map.at(season);
}

Anime::SeriesFormat ToSeriesFormat(const std::string& format) {
	static const std::unordered_map<std::string, enum Anime::SeriesFormat> map = {
	    {"TV",       Anime::SeriesFormat::Tv      },
        {"TV_SHORT", Anime::SeriesFormat::TvShort},
	    {"MOVIE",    Anime::SeriesFormat::Movie   },
        {"SPECIAL",  Anime::SeriesFormat::Special },
	    {"OVA",      Anime::SeriesFormat::Ova     },
        {"ONA",      Anime::SeriesFormat::Ona     },
	    {"MUSIC",    Anime::SeriesFormat::Music   }
    };

	if (map.find(format) == map.end())
		return Anime::SeriesFormat::Unknown;
	return map.at(format);
}

std::string ToString(Anime::Season::Name season) {
	switch (season) {
		default:
		case Anime::Season::Name::Winter: return "WINTER";
		case Anime::Season::Name::Autumn: return "FALL";
		case Anime::Season::Name::Summer: return "SUMMER";
		case Anime::Season::Name::Spring: return "SPRING";
	}
}

} // namespace AniList
} // namespace Translate