35#include "spdlog/fmt/fmt.h"
37#include "boost/assert.hpp"
55 for (
const auto &filePath : s_localizationFiles[locale]) {
56 tinyxml2::XMLDocument doc;
57 doc.LoadFile(filePath.c_str());
58 BOOST_ASSERT_MSG(!doc.Error(), doc.ErrorStr());
60 tinyxml2::XMLElement *plist = doc.FirstChildElement(
"plist");
61 BOOST_ASSERT_MSG(plist,
"plist not found in localization file!");
63 tinyxml2::XMLElement *rootDict = plist->FirstChildElement(
"dict");
64 BOOST_ASSERT_MSG(rootDict,
"Dictionary not found in localization file!");
66 tinyxml2::XMLElement *keyElement = rootDict->FirstChildElement(
"key");
69 tinyxml2::XMLText *keyTextNode = keyElement->FirstChild()->ToText();
70 tinyxml2::XMLElement *stringElement = keyElement->NextSiblingElement(
"string");
71 BOOST_ASSERT_MSG(stringElement, fmt::format(
"String for key '{}' not found in localization file!", keyTextNode->Value()).c_str());
73 tinyxml2::XMLText *stringTextNode = stringElement->FirstChild()->ToText();
74 s_localeTable[keyTextNode->Value()] = stringTextNode->Value();
76 keyElement = stringElement->NextSiblingElement(
"key");
83 if (s_localeTable.find(key) == s_localeTable.end()) {
88 return s_localeTable.
at(key);
96 Engine::Error(
"Localization file '{}' does not exist!", filename);
100 s_localizationFiles[locale].push_back(filename);
void Error(Args &&... args)
void Warn(Args &&... args)
std::string GetLocalized(const std::string &key)
void SetLocale(Locale locale)
bool AddLocalizationFile(Locale locale, const std::string &filename)