Reimplement language codes as strongly-typed enums

This commit is contained in:
Oliver Hamlet
2016-07-13 20:48:18 +01:00
parent 93a2e266cc
commit 8265ca916e
27 changed files with 246 additions and 271 deletions
+15 -15
View File
@@ -72,17 +72,17 @@ const unsigned int loot_message_warn = static_cast<unsigned int>(loot::Message::
const unsigned int loot_message_error = static_cast<unsigned int>(loot::Message::Type::error);
// LOOT message languages.
const unsigned int loot_lang_english = loot::Language::english;
const unsigned int loot_lang_spanish = loot::Language::spanish;
const unsigned int loot_lang_russian = loot::Language::russian;
const unsigned int loot_lang_french = loot::Language::french;
const unsigned int loot_lang_chinese = loot::Language::chinese;
const unsigned int loot_lang_polish = loot::Language::polish;
const unsigned int loot_lang_brazilian_portuguese = loot::Language::brazilian_portuguese;
const unsigned int loot_lang_finnish = loot::Language::finnish;
const unsigned int loot_lang_german = loot::Language::german;
const unsigned int loot_lang_danish = loot::Language::danish;
const unsigned int loot_lang_korean = loot::Language::korean;
const unsigned int loot_lang_english = static_cast<unsigned int>(loot::Language::Code::english);
const unsigned int loot_lang_spanish = static_cast<unsigned int>(loot::Language::Code::spanish);
const unsigned int loot_lang_russian = static_cast<unsigned int>(loot::Language::Code::russian);
const unsigned int loot_lang_french = static_cast<unsigned int>(loot::Language::Code::french);
const unsigned int loot_lang_chinese = static_cast<unsigned int>(loot::Language::Code::chinese);
const unsigned int loot_lang_polish = static_cast<unsigned int>(loot::Language::Code::polish);
const unsigned int loot_lang_brazilian_portuguese = static_cast<unsigned int>(loot::Language::Code::brazilian_portuguese);
const unsigned int loot_lang_finnish = static_cast<unsigned int>(loot::Language::Code::finnish);
const unsigned int loot_lang_german = static_cast<unsigned int>(loot::Language::Code::german);
const unsigned int loot_lang_danish = static_cast<unsigned int>(loot::Language::Code::danish);
const unsigned int loot_lang_korean = static_cast<unsigned int>(loot::Language::Code::korean);
// LOOT cleanliness codes.
const unsigned int loot_needs_cleaning_no = 0;
@@ -302,8 +302,8 @@ LOOT_API unsigned int loot_eval_lists(loot_db * const db, const unsigned int lan
loot::MetadataList userTemp = db->getUnevaluatedUserlist();
try {
// Refresh active plugins before evaluating conditions.
temp.EvalAllConditions(*db, language);
userTemp.EvalAllConditions(*db, language);
temp.EvalAllConditions(*db, loot::Language::Code(language));
userTemp.EvalAllConditions(*db, loot::Language::Code(language));
}
catch (Error& e) {
return c_error(e);
@@ -335,7 +335,7 @@ LOOT_API unsigned int loot_sort_plugins(loot_db * const db,
//Sort plugins into their load order.
loot::PluginSorter sorter;
db->setPluginNames(sorter.Sort(*db, loot::Language::english));
db->setPluginNames(sorter.Sort(*db, loot::Language::Code::english));
}
catch (Error &e) {
return c_error(e);
@@ -608,7 +608,7 @@ LOOT_API unsigned int loot_get_dirty_info(loot_db * const db, const char * const
messages.insert(messages.end(), temp.begin(), temp.end());
for (const auto& message : messages) {
if (boost::starts_with(message.ChooseContent(loot::Language::english).Text(), "Do not clean")) {
if (boost::starts_with(message.ChooseContent(loot::Language::Code::english).GetText(), "Do not clean")) {
*needsCleaning = loot_needs_cleaning_no;
break;
}
+1 -1
View File
@@ -102,7 +102,7 @@ void loot_db::setPluginMessages(const std::list<loot::Message>& pluginMessages)
size_t i = 0;
for (const auto& message : pluginMessages) {
pluginMessageStrings[i] = message.ChooseContent(loot::Language::english).Text();
pluginMessageStrings[i] = message.ChooseContent(loot::Language::Code::english).GetText();
cPluginMessages[i].type = static_cast<unsigned int>(message.GetType());
cPluginMessages[i].message = pluginMessageStrings[i].c_str();
+2 -2
View File
@@ -49,7 +49,7 @@ namespace loot {
enableDebugLogging(false),
updateMasterlist(true),
game("auto"),
language(Language(Language::english)),
language(Language(Language::Code::english)),
lastGame("auto") {}
void LootSettings::load(YAML::Node& settings) {
@@ -206,7 +206,7 @@ namespace loot {
node["enableDebugLogging"] = enableDebugLogging;
node["updateMasterlist"] = updateMasterlist;
node["game"] = game;
node["language"] = language.Locale();
node["language"] = language.GetLocale();
node["lastGame"] = lastGame;
node["lastVersion"] = lastVersion;
+4 -4
View File
@@ -109,7 +109,7 @@ namespace loot {
gen.add_messages_domain("loot");
//Boost.Locale initialisation: Generate and imbue locales.
locale::global(gen(Language(Language::english).Locale() + ".UTF-8"));
locale::global(gen(Language(Language::Code::english).GetLocale() + ".UTF-8"));
boost::filesystem::path::imbue(locale());
// Check if the LOOT local app data folder exists, and create it if not.
@@ -161,13 +161,13 @@ namespace loot {
fs::remove(LootPaths::getLootDataPath() / "CEFDebugLog.txt");
// Now that settings have been loaded, set the locale again to handle translations.
if (getLanguage().Code() != Language::english) {
if (getLanguage().GetCode() != Language::Code::english) {
BOOST_LOG_TRIVIAL(debug) << "Initialising language settings.";
loot::Language lang(getLanguage());
BOOST_LOG_TRIVIAL(debug) << "Selected language: " << lang.Name();
BOOST_LOG_TRIVIAL(debug) << "Selected language: " << lang.GetName();
//Boost.Locale initialisation: Generate and imbue locales.
locale::global(gen(lang.Locale() + ".UTF-8"));
locale::global(gen(lang.GetLocale() + ".UTF-8"));
boost::filesystem::path::imbue(locale());
}
+36 -63
View File
@@ -25,121 +25,94 @@
#include "language.h"
namespace loot {
const unsigned int Language::english = 1;
const unsigned int Language::spanish = 2;
const unsigned int Language::russian = 3;
const unsigned int Language::french = 4;
const unsigned int Language::chinese = 5;
const unsigned int Language::polish = 6;
const unsigned int Language::brazilian_portuguese = 7;
const unsigned int Language::finnish = 8;
const unsigned int Language::german = 9;
const unsigned int Language::danish = 10;
const unsigned int Language::korean = 11;
Language::Language(const unsigned int code) {
Language::Language(const Code code) {
Construct(code);
}
Language::Language(const std::string& locale) {
if (locale == Language(Language::english).Locale())
Construct(Language::english);
else if (locale == Language(Language::spanish).Locale())
Construct(Language::spanish);
else if (locale == Language(Language::russian).Locale())
Construct(Language::russian);
else if (locale == Language(Language::french).Locale())
Construct(Language::french);
else if (locale == Language(Language::chinese).Locale())
Construct(Language::chinese);
else if (locale == Language(Language::polish).Locale())
Construct(Language::polish);
else if (locale == Language(Language::brazilian_portuguese).Locale())
Construct(Language::brazilian_portuguese);
else if (locale == Language(Language::finnish).Locale())
Construct(Language::finnish);
else if (locale == Language(Language::german).Locale())
Construct(Language::german);
else if (locale == Language(Language::danish).Locale())
Construct(Language::danish);
else if (locale == Language(Language::korean).Locale())
Construct(Language::korean);
else
Construct(Language::english);
for (Code code : Codes) {
if (locale == Language(code).GetLocale()) {
Construct(code);
return;
}
}
Construct(Code::english);
}
void Language::Construct(const unsigned int code) {
void Language::Construct(const Code code) {
_code = code;
if (_code == Language::spanish) {
if (_code == Code::spanish) {
_name = "Español";
_locale = "es";
}
else if (_code == Language::russian) {
else if (_code == Code::russian) {
_name = "Русский";
_locale = "ru";
}
else if (_code == Language::french) {
else if (_code == Code::french) {
_name = "Français";
_locale = "fr";
}
else if (_code == Language::chinese) {
else if (_code == Code::chinese) {
_name = "简体中文";
_locale = "zh_CN";
}
else if (_code == Language::polish) {
else if (_code == Code::polish) {
_name = "Polski";
_locale = "pl";
}
else if (_code == Language::brazilian_portuguese) {
else if (_code == Code::brazilian_portuguese) {
_name = "Português do Brasil";
_locale = "pt_BR";
}
else if (_code == Language::finnish) {
else if (_code == Code::finnish) {
_name = "suomi";
_locale = "fi";
}
else if (_code == Language::german) {
else if (_code == Code::german) {
_name = "Deutsch";
_locale = "de";
}
else if (_code == Language::danish) {
else if (_code == Code::danish) {
_name = "Dansk";
_locale = "da";
}
else if (_code == Language::korean) {
else if (_code == Code::korean) {
_name = "한국어";
_locale = "ko";
}
else {
_code = Language::english;
_code = Code::english;
_name = "English";
_locale = "en";
}
}
unsigned int Language::Code() const {
Language::Code Language::GetCode() const {
return _code;
}
std::string Language::Name() const {
std::string Language::GetName() const {
return _name;
}
std::string Language::Locale() const {
std::string Language::GetLocale() const {
return _locale;
}
const std::vector<unsigned int> Language::Codes({
Language::english,
Language::spanish,
Language::russian,
Language::french,
Language::chinese,
Language::polish,
Language::brazilian_portuguese,
Language::finnish,
Language::german,
Language::danish,
Language::korean
const std::vector<Language::Code> Language::Codes({
Code::english,
Code::spanish,
Code::russian,
Code::french,
Code::chinese,
Code::polish,
Code::brazilian_portuguese,
Code::finnish,
Code::german,
Code::danish,
Code::korean
});
}
+21 -19
View File
@@ -32,32 +32,34 @@ namespace loot {
//Language class for simpler language support.
class Language {
public:
Language(const unsigned int code);
enum struct Code : unsigned int {
english = 1,
spanish = 2,
russian = 3,
french = 4,
chinese = 5,
polish = 6,
brazilian_portuguese = 7,
finnish = 8,
german = 9,
danish = 10,
korean = 11,
};
Language(const Code code);
Language(const std::string& locale);
unsigned int Code() const;
std::string Name() const;
std::string Locale() const;
Code GetCode() const;
std::string GetName() const;
std::string GetLocale() const;
static const unsigned int english;
static const unsigned int spanish;
static const unsigned int russian;
static const unsigned int french;
static const unsigned int chinese;
static const unsigned int polish;
static const unsigned int brazilian_portuguese;
static const unsigned int finnish;
static const unsigned int german;
static const unsigned int danish;
static const unsigned int korean;
static const std::vector<unsigned int> Codes;
static const std::vector<Code> Codes;
private:
unsigned int _code;
Code _code;
std::string _name;
std::string _locale;
void Construct(const unsigned int code);
void Construct(const Code code);
};
}
+9 -9
View File
@@ -35,7 +35,7 @@ namespace loot {
Message::Message(const Type type, const std::string& content,
const std::string& condition) : _type(type), ConditionalMetadata(condition) {
_content.push_back(MessageContent(content, Language::english));
_content.push_back(MessageContent(content, Language::Code::english));
}
Message::Message(const Type type, const std::vector<MessageContent>& content,
@@ -43,7 +43,7 @@ namespace loot {
if (content.size() > 1) {
bool englishStringExists = false;
for (const auto &mc : content) {
if (mc.Language() == loot::Language::english)
if (mc.GetLanguage() == loot::Language::Code::english)
englishStringExists = true;
}
if (!englishStringExists)
@@ -53,7 +53,7 @@ namespace loot {
bool Message::operator < (const Message& rhs) const {
if (!_content.empty() && !rhs.GetContent().empty())
return boost::ilexicographical_compare(ChooseContent(Language::english).Text(), rhs.ChooseContent(Language::english).Text());
return boost::ilexicographical_compare(ChooseContent(Language::Code::english).GetText(), rhs.ChooseContent(Language::Code::english).GetText());
else if (_content.empty() && !rhs.GetContent().empty())
return true;
else
@@ -64,14 +64,14 @@ namespace loot {
return (_content == rhs.GetContent());
}
bool Message::EvalCondition(loot::Game& game, const unsigned int language) {
BOOST_LOG_TRIVIAL(trace) << "Choosing message content for language: " << Language(language).Name();
bool Message::EvalCondition(loot::Game& game, const Language::Code language) {
BOOST_LOG_TRIVIAL(trace) << "Choosing message content for language: " << Language(language).GetName();
_content.assign({ChooseContent(language)});
return ConditionalMetadata::EvalCondition(game);
}
MessageContent Message::ChooseContent(const unsigned int language) const {
MessageContent Message::ChooseContent(const Language::Code language) const {
BOOST_LOG_TRIVIAL(trace) << "Choosing message content.";
if (_content.empty())
return MessageContent();
@@ -80,10 +80,10 @@ namespace loot {
else {
MessageContent english;
for (const auto &mc : _content) {
if (mc.Language() == language) {
if (mc.GetLanguage() == language) {
return mc;
}
else if (mc.Language() == Language::english)
else if (mc.GetLanguage() == Language::Code::english)
english = mc;
}
return english;
@@ -111,7 +111,7 @@ namespace YAML {
out << Key << "type" << Value << "error";
if (rhs.GetContent().size() == 1)
out << Key << "content" << Value << YAML::SingleQuoted << rhs.GetContent().front().Text();
out << Key << "content" << Value << YAML::SingleQuoted << rhs.GetContent().front().GetText();
else
out << Key << "content" << Value << rhs.GetContent();
+6 -6
View File
@@ -56,11 +56,11 @@ namespace loot {
bool operator < (const Message& rhs) const;
bool operator == (const Message& rhs) const;
bool EvalCondition(Game& game, const unsigned int language);
bool EvalCondition(Game& game, const Language::Code language);
Type GetType() const;
std::vector<MessageContent> GetContent() const;
MessageContent ChooseContent(const unsigned int language) const;
MessageContent ChooseContent(const Language::Code language) const;
private:
Type _type;
std::vector<MessageContent> _content;
@@ -108,14 +108,14 @@ namespace YAML {
if (node["content"].IsSequence())
content = node["content"].as< std::vector<loot::MessageContent> >();
else {
content.push_back(loot::MessageContent(node["content"].as<std::string>(), loot::Language::english));
content.push_back(loot::MessageContent(node["content"].as<std::string>(), loot::Language::Code::english));
}
//Check now that at least one item in content is English if there are multiple items.
if (content.size() > 1) {
bool found = false;
for (const auto &mc : content) {
if (mc.Language() == loot::Language::english)
if (mc.GetLanguage() == loot::Language::Code::english)
found = true;
}
if (!found)
@@ -126,14 +126,14 @@ namespace YAML {
if (node["subs"]) {
std::vector<std::string> subs = node["subs"].as<std::vector<std::string>>();
for (auto& mc : content) {
boost::format f(mc.Text());
boost::format f(mc.GetText());
for (const auto& sub : subs) {
f = f % sub;
}
try {
mc = loot::MessageContent(f.str(), mc.Language());
mc = loot::MessageContent(f.str(), mc.GetLanguage());
}
catch (boost::io::format_error& e) {
throw RepresentationException(node.Mark(), std::string("bad conversion: content substitution error: ") + e.what());
+8 -8
View File
@@ -30,24 +30,24 @@
using namespace std;
namespace loot {
MessageContent::MessageContent() : _language(Language::english) {}
MessageContent::MessageContent() : _language(Language::Code::english) {}
MessageContent::MessageContent(const std::string& str, const unsigned int language) : _str(str), _language(language) {}
MessageContent::MessageContent(const std::string& str, const Language::Code language) : _str(str), _language(language) {}
std::string MessageContent::Text() const {
std::string MessageContent::GetText() const {
return _str;
}
unsigned int MessageContent::Language() const {
Language::Code MessageContent::GetLanguage() const {
return _language;
}
bool MessageContent::operator < (const MessageContent& rhs) const {
return boost::ilexicographical_compare(_str, rhs.Text());
return boost::ilexicographical_compare(_str, rhs.GetText());
}
bool MessageContent::operator == (const MessageContent& rhs) const {
return (boost::iequals(_str, rhs.Text()));
return (boost::iequals(_str, rhs.GetText()));
}
}
@@ -55,9 +55,9 @@ namespace YAML {
Emitter& operator << (Emitter& out, const loot::MessageContent& rhs) {
out << BeginMap;
out << Key << "lang" << Value << loot::Language(rhs.Language()).Locale();
out << Key << "lang" << Value << loot::Language(rhs.GetLanguage()).GetLocale();
out << Key << "str" << Value << YAML::SingleQuoted << rhs.Text();
out << Key << "str" << Value << YAML::SingleQuoted << rhs.GetText();
out << EndMap;
+7 -7
View File
@@ -34,16 +34,16 @@ namespace loot {
class MessageContent {
public:
MessageContent();
MessageContent(const std::string& str, const unsigned int language);
MessageContent(const std::string& str, const Language::Code language);
std::string Text() const;
unsigned int Language() const;
std::string GetText() const;
Language::Code GetLanguage() const;
bool operator < (const MessageContent& rhs) const;
bool operator == (const MessageContent& rhs) const;
private:
std::string _str;
unsigned int _language;
Language::Code _language;
};
}
@@ -52,8 +52,8 @@ namespace YAML {
struct convert < loot::MessageContent > {
static Node encode(const loot::MessageContent& rhs) {
Node node;
node["str"] = rhs.Text();
node["lang"] = loot::Language(rhs.Language()).Locale();
node["str"] = rhs.GetText();
node["lang"] = loot::Language(rhs.GetLanguage()).GetLocale();
return node;
}
@@ -67,7 +67,7 @@ namespace YAML {
throw RepresentationException(node.Mark(), "bad conversion: 'lang' key missing from 'message content' object");
std::string str = node["str"].as<std::string>();
unsigned int lang = loot::Language(node["lang"].as<std::string>()).Code();
loot::Language::Code lang = loot::Language(node["lang"].as<std::string>()).GetCode();
rhs = loot::MessageContent(str, lang);
+1 -1
View File
@@ -318,7 +318,7 @@ namespace loot {
_locations = locations;
}
PluginMetadata& PluginMetadata::EvalAllConditions(Game& game, const unsigned int language) {
PluginMetadata& PluginMetadata::EvalAllConditions(Game& game, const Language::Code language) {
for (auto it = loadAfter.begin(); it != loadAfter.end();) {
if (!it->EvalCondition(game))
loadAfter.erase(it++);
+1 -1
View File
@@ -91,7 +91,7 @@ namespace loot {
void DirtyInfo(const std::set<PluginDirtyInfo>& info);
void Locations(const std::set<Location>& locations);
PluginMetadata& EvalAllConditions(Game& game, const unsigned int language);
PluginMetadata& EvalAllConditions(Game& game, const Language::Code language);
bool HasNameOnly() const;
bool IsRegexPlugin() const;
+1 -1
View File
@@ -146,7 +146,7 @@ namespace loot {
messages.push_back(message);
}
void MetadataList::EvalAllConditions(Game& game, const unsigned int language) {
void MetadataList::EvalAllConditions(Game& game, const Language::Code language) {
unordered_set<PluginMetadata> replacementSet;
for (auto &plugin : plugins) {
PluginMetadata p(plugin);
+1 -1
View File
@@ -67,7 +67,7 @@ namespace loot {
void AppendMessage(const Message& message);
// Eval plugin conditions.
void EvalAllConditions(Game& game, const unsigned int language);
void EvalAllConditions(Game& game, const Language::Code language);
protected:
std::set<std::string> bashTags_;
+2 -2
View File
@@ -96,7 +96,7 @@ namespace loot {
vertex_t target;
};
std::list<Plugin> PluginSorter::Sort(Game& game, const unsigned int language) {
std::list<Plugin> PluginSorter::Sort(Game& game, const Language::Code language) {
// Clear existing data.
graph.clear();
indexMap.clear();
@@ -164,7 +164,7 @@ namespace loot {
return plugins;
}
void PluginSorter::addPluginVertices(Game& game, const unsigned int language) {
void PluginSorter::addPluginVertices(Game& game, const Language::Code language) {
BOOST_LOG_TRIVIAL(info) << "Merging masterlist, userlist into plugin list, evaluating conditions and checking for install validity.";
// The resolution of tie-breaks in the plugin graph may be dependent
+2 -2
View File
@@ -41,7 +41,7 @@ namespace loot {
class PluginSorter {
public:
std::list<Plugin> Sort(Game& game, const unsigned int language);
std::list<Plugin> Sort(Game& game, const Language::Code language);
private:
PluginGraph graph;
std::map<vertex_t, size_t> indexMap;
@@ -56,7 +56,7 @@ namespace loot {
void PropagatePriorities();
void addPluginVertices(Game& game, const unsigned int language);
void addPluginVertices(Game& game, const Language::Code language);
void AddSpecificEdges();
void AddPriorityEdges();
void AddOverlapEdges();
+3 -3
View File
@@ -102,13 +102,13 @@ namespace loot {
// Need to set the global locale for this process so that messages will
// be translated.
BOOST_LOG_TRIVIAL(debug) << "Initialising language settings in UI thread.";
if (lootState_.getLanguage().Code() != Language::english) {
if (lootState_.getLanguage().GetCode() != Language::Code::english) {
boost::locale::generator gen;
gen.add_messages_path(LootPaths::getL10nPath().string());
gen.add_messages_domain("loot");
BOOST_LOG_TRIVIAL(debug) << "Selected language: " << lootState_.getLanguage().Name();
locale::global(gen(lootState_.getLanguage().Locale() + ".UTF-8"));
BOOST_LOG_TRIVIAL(debug) << "Selected language: " << lootState_.getLanguage().GetName();
locale::global(gen(lootState_.getLanguage().GetLocale() + ".UTF-8"));
boost::filesystem::path::imbue(locale());
}
+8 -8
View File
@@ -582,8 +582,8 @@ namespace loot {
for (const auto& code : Language::Codes) {
YAML::Node lang;
Language language(code);
lang["name"] = language.Name();
lang["locale"] = language.Locale();
lang["name"] = language.GetName();
lang["locale"] = language.GetLocale();
temp.push_back(lang);
}
return JSON::stringify(temp);
@@ -902,7 +902,7 @@ namespace loot {
void QueryHandler::SortPlugins(CefRefPtr<CefFrame> frame, CefRefPtr<Callback> callback) {
BOOST_LOG_TRIVIAL(info) << "Beginning sorting operation.";
BOOST_LOG_TRIVIAL(info) << "Using message language: " << _lootState.getLanguage().Name();
BOOST_LOG_TRIVIAL(info) << "Using message language: " << _lootState.getLanguage().GetName();
try {
// Always reload all the plugins.
@@ -912,7 +912,7 @@ namespace loot {
//Sort plugins into their load order.
SendProgressUpdate(frame, loc::translate("Sorting load order..."));
PluginSorter sorter;
list<Plugin> plugins = sorter.Sort(_lootState.CurrentGame(), _lootState.getLanguage().Code());
list<Plugin> plugins = sorter.Sort(_lootState.CurrentGame(), _lootState.getLanguage().GetCode());
// If TESV or FO4, check if load order has been changed.
if ((_lootState.CurrentGame().Id() == Game::tes5 || _lootState.CurrentGame().Id() == Game::fo4)
@@ -989,10 +989,10 @@ namespace loot {
end(gameMessages));
try {
BOOST_LOG_TRIVIAL(info) << "Using message language: " << _lootState.getLanguage().Name();
BOOST_LOG_TRIVIAL(info) << "Using message language: " << _lootState.getLanguage().GetName();
auto it = begin(messages);
while (it != end(messages)) {
if (!it->EvalCondition(_lootState.CurrentGame(), _lootState.getLanguage().Code()))
if (!it->EvalCondition(_lootState.CurrentGame(), _lootState.getLanguage().GetCode()))
it = messages.erase(it);
else
++it;
@@ -1007,7 +1007,7 @@ namespace loot {
}
YAML::Node QueryHandler::GenerateDerivedMetadata(const Plugin& file, const PluginMetadata& masterlist, const PluginMetadata& userlist) {
BOOST_LOG_TRIVIAL(info) << "Using message language: " << _lootState.getLanguage().Name();
BOOST_LOG_TRIVIAL(info) << "Using message language: " << _lootState.getLanguage().GetName();
// Now rederive the displayed metadata from the masterlist and userlist.
Plugin tempPlugin(file);
@@ -1018,7 +1018,7 @@ namespace loot {
//Evaluate any conditions
BOOST_LOG_TRIVIAL(trace) << "Evaluate conditions for merged plugin data.";
try {
tempPlugin.EvalAllConditions(_lootState.CurrentGame(), _lootState.getLanguage().Code());
tempPlugin.EvalAllConditions(_lootState.CurrentGame(), _lootState.getLanguage().GetCode());
}
catch (std::exception& e) {
BOOST_LOG_TRIVIAL(error) << "\"" << tempPlugin.Name() << "\" contains a condition that could not be evaluated. Details: " << e.what();
+5 -5
View File
@@ -60,7 +60,7 @@ namespace loot {
EXPECT_FALSE(settings.isDebugLoggingEnabled());
EXPECT_EQ("auto", settings.getGame());
EXPECT_EQ("en", settings.getLanguage().Locale());
EXPECT_EQ("en", settings.getLanguage().GetLocale());
EXPECT_EQ("auto", settings.getLastGame());
EXPECT_FALSE(settings.isWindowPositionStored());
@@ -157,7 +157,7 @@ namespace loot {
EXPECT_EQ(enableDebugLogging, settings.isDebugLoggingEnabled());
EXPECT_EQ(game, settings.getGame());
EXPECT_EQ(language, settings.getLanguage().Locale());
EXPECT_EQ(language, settings.getLanguage().GetLocale());
EXPECT_EQ(lastGame, settings.getLastGame());
EXPECT_EQ(1, settings.getWindowPosition().top);
@@ -209,7 +209,7 @@ namespace loot {
EXPECT_TRUE(settings.isDebugLoggingEnabled());
EXPECT_EQ(UpdateMasterlist, outputYaml["updateMasterlist"].as<bool>());
EXPECT_EQ(Game, settings.getGame());
EXPECT_EQ(Language, settings.getLanguage().Locale());
EXPECT_EQ(Language, settings.getLanguage().GetLocale());
EXPECT_EQ(LastGame, settings.getLastGame());
EXPECT_EQ(Games[0].Name(), settings.getGameSettings()[0].Name());
@@ -260,7 +260,7 @@ namespace loot {
EXPECT_EQ(enableDebugLogging, settings.isDebugLoggingEnabled());
EXPECT_EQ(updateMasterlist, outputYaml["updateMasterlist"].as<bool>());
EXPECT_EQ(game, settings.getGame());
EXPECT_EQ(language, settings.getLanguage().Locale());
EXPECT_EQ(language, settings.getLanguage().GetLocale());
EXPECT_EQ(lastGame, settings.getLastGame());
EXPECT_EQ(games[0].Name(), settings.getGameSettings()[0].Name());
@@ -342,7 +342,7 @@ namespace loot {
settings.load(inputYaml);
EXPECT_EQ("fr", settings.getLanguage().Locale());
EXPECT_EQ("fr", settings.getLanguage().GetLocale());
}
TEST_F(LootSettingsTest, isWindowPositionStoredShouldReturnFalseIfAllPositionValuesAreZero) {
+33 -33
View File
@@ -32,56 +32,56 @@ along with LOOT. If not, see
namespace loot {
namespace test {
TEST(Language, codeConstructorShouldSetTheCorrectData) {
Language lang(Language::english);
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
Language lang(Language::Code::english);
EXPECT_EQ(Language::Code::english, lang.GetCode());
EXPECT_EQ("English", lang.GetName());
EXPECT_EQ("en", lang.GetLocale());
lang = Language(Language::polish);
EXPECT_EQ(Language::polish, lang.Code());
EXPECT_EQ("Polski", lang.Name());
EXPECT_EQ("pl", lang.Locale());
lang = Language(Language::Code::polish);
EXPECT_EQ(Language::Code::polish, lang.GetCode());
EXPECT_EQ("Polski", lang.GetName());
EXPECT_EQ("pl", lang.GetLocale());
}
TEST(Language, localeConstructorShouldSetTheCorrectData) {
Language lang("en");
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
EXPECT_EQ(Language::Code::english, lang.GetCode());
EXPECT_EQ("English", lang.GetName());
EXPECT_EQ("en", lang.GetLocale());
lang = Language("de");
EXPECT_EQ(Language::german, lang.Code());
EXPECT_EQ("Deutsch", lang.Name());
EXPECT_EQ("de", lang.Locale());
EXPECT_EQ(Language::Code::german, lang.GetCode());
EXPECT_EQ("Deutsch", lang.GetName());
EXPECT_EQ("de", lang.GetLocale());
}
TEST(Language, codeConstructorShouldTreatAnInvalidCodeAsEnglish) {
Language lang(1000);
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
Language lang(Language::Code(1000));
EXPECT_EQ(Language::Code::english, lang.GetCode());
EXPECT_EQ("English", lang.GetName());
EXPECT_EQ("en", lang.GetLocale());
}
TEST(Language, localeConstructorShouldTreatAnInvalidLocaleAsEnglish) {
Language lang("foo");
EXPECT_EQ(Language::english, lang.Code());
EXPECT_EQ("English", lang.Name());
EXPECT_EQ("en", lang.Locale());
EXPECT_EQ(Language::Code::english, lang.GetCode());
EXPECT_EQ("English", lang.GetName());
EXPECT_EQ("en", lang.GetLocale());
}
TEST(Language, codesShouldContainAllExpectedLanguageCodes) {
std::vector<unsigned int> codes = {
Language::english,
Language::spanish,
Language::russian,
Language::french,
Language::chinese,
Language::polish,
Language::brazilian_portuguese,
Language::finnish,
Language::german,
Language::danish,
Language::korean
std::vector<Language::Code> codes = {
Language::Code::english,
Language::Code::spanish,
Language::Code::russian,
Language::Code::french,
Language::Code::chinese,
Language::Code::polish,
Language::Code::brazilian_portuguese,
Language::Code::finnish,
Language::Code::german,
Language::Code::danish,
Language::Code::korean
};
EXPECT_EQ(codes, Language::Codes);

Some files were not shown because too many files have changed in this diff Show More