mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Remove Language and LanguageCode structures
Use ISO language codes directly instead, which has the advantage that new languages can be used in metadata without having up update the API to support them. Closes #5.
This commit is contained in:
@@ -27,7 +27,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "loot/enum/language_code.h"
|
||||
#include "loot/enum/plugin_cleanliness.h"
|
||||
#include "loot/metadata/message.h"
|
||||
#include "loot/metadata/plugin_metadata.h"
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2012-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_LANGUAGE_CODE
|
||||
#define LOOT_LANGUAGE_CODE
|
||||
|
||||
/**
|
||||
* The namespace used by the LOOT API.
|
||||
*/
|
||||
namespace loot {
|
||||
/**
|
||||
* @brief Codes used to specify the preferred language for messages.
|
||||
* @details If a message is not available in the preferred language, its English
|
||||
* string will be used. Note that messages with only one language
|
||||
* string are assumed to be written in English, but this cannot be
|
||||
* guaranteed (any violations should be reported as bugs so that they
|
||||
* can be fixed).
|
||||
*/
|
||||
enum struct LanguageCode : unsigned int {
|
||||
english,
|
||||
spanish,
|
||||
russian,
|
||||
french,
|
||||
chinese,
|
||||
polish,
|
||||
brazilian_portuguese,
|
||||
finnish,
|
||||
german,
|
||||
danish,
|
||||
korean,
|
||||
swedish
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,92 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2012-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_LANGUAGE
|
||||
#define LOOT_LANGUAGE
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "loot/api_decorator.h"
|
||||
#include "loot/enum/language_code.h"
|
||||
|
||||
namespace loot {
|
||||
/**
|
||||
* @brief Represents a language, and used to map between API language codes,
|
||||
* locale codes and language names.
|
||||
*/
|
||||
class Language {
|
||||
public:
|
||||
/**
|
||||
* @brief A convenience constant that contains all available language codes.
|
||||
*/
|
||||
LOOT_API static const std::vector<LanguageCode> codes;
|
||||
|
||||
/**
|
||||
* @brief Construct a Language object.
|
||||
* @param code
|
||||
* A LOOT API language code.
|
||||
* @return A Language object for the given code.
|
||||
*/
|
||||
LOOT_API Language(const LanguageCode code);
|
||||
|
||||
/**
|
||||
* @brief Construct a Language object.
|
||||
* @param locale
|
||||
* A POSIX locale code.
|
||||
* @return A Language object. If the locale code corresponds to a language
|
||||
* with a LanguageCode value, the object is for that language,
|
||||
* otherwise it is for English.
|
||||
*/
|
||||
LOOT_API Language(const std::string& locale);
|
||||
|
||||
/**
|
||||
* Get the language's LanguageCode.
|
||||
* @return The language's LanguageCode.
|
||||
*/
|
||||
LOOT_API LanguageCode GetCode() const;
|
||||
|
||||
/**
|
||||
* Get the language's name for itself.
|
||||
*
|
||||
* For example, ``Русский``, not ``Russian``.
|
||||
* @return The language's name.
|
||||
*/
|
||||
LOOT_API std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Get the language's POSIX locale code.
|
||||
* @return The language's POSIX locale code.
|
||||
*/
|
||||
LOOT_API std::string GetLocale() const;
|
||||
private:
|
||||
static LanguageCode GetCode(const std::string& locale);
|
||||
|
||||
LanguageCode code_;
|
||||
std::string name_;
|
||||
std::string locale_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "loot/api_decorator.h"
|
||||
#include "loot/metadata/conditional_metadata.h"
|
||||
#include "loot/metadata/message_content.h"
|
||||
#include "loot/enum/language_code.h"
|
||||
#include "loot/enum/message_type.h"
|
||||
#include "loot/struct/simple_message.h"
|
||||
|
||||
@@ -111,7 +110,7 @@ public:
|
||||
* @return A MessageContent object for the preferred language, or for English
|
||||
* if a MessageContent object is not available for the given language.
|
||||
*/
|
||||
LOOT_API MessageContent GetContent(const LanguageCode language) const;
|
||||
LOOT_API MessageContent GetContent(const std::string& language) const;
|
||||
|
||||
/**
|
||||
* Get the message as a SimpleMessage given a language.
|
||||
@@ -120,7 +119,7 @@ public:
|
||||
* @return A SimpleMessage object for the preferred language, or for English
|
||||
* if message text is not available for the given language.
|
||||
*/
|
||||
LOOT_API SimpleMessage ToSimpleMessage(const LanguageCode language) const;
|
||||
LOOT_API SimpleMessage ToSimpleMessage(const std::string& language) const;
|
||||
private:
|
||||
MessageType type_;
|
||||
std::vector<MessageContent> content_;
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
#define LOOT_METADATA_MESSAGE_CONTENT
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "loot/api_decorator.h"
|
||||
#include "loot/language.h"
|
||||
|
||||
namespace loot {
|
||||
/**
|
||||
@@ -35,6 +35,12 @@ namespace loot {
|
||||
*/
|
||||
class MessageContent {
|
||||
public:
|
||||
/**
|
||||
* The code for the default language assumed for message content, which is
|
||||
* English.
|
||||
*/
|
||||
static const std::string defaultLanguage;
|
||||
|
||||
/**
|
||||
* Construct a MessageContent object with an empty English message string.
|
||||
* @return A MessageContent object.
|
||||
@@ -49,7 +55,8 @@ public:
|
||||
* The language that the message is written in.
|
||||
* @return A MessageContent object.
|
||||
*/
|
||||
LOOT_API MessageContent(const std::string& text, const LanguageCode language);
|
||||
LOOT_API MessageContent(const std::string& text,
|
||||
const std::string& language = defaultLanguage);
|
||||
|
||||
/**
|
||||
* Get the message text.
|
||||
@@ -61,7 +68,7 @@ public:
|
||||
* Get the message language.
|
||||
* @return A code representing the language that the message is written in.
|
||||
*/
|
||||
LOOT_API LanguageCode GetLanguage() const;
|
||||
LOOT_API std::string GetLanguage() const;
|
||||
|
||||
/**
|
||||
* A less-than operator implemented with no semantics so that MessageContent
|
||||
@@ -83,17 +90,17 @@ public:
|
||||
* @param content
|
||||
* The MessageContent objects to choose between.
|
||||
* @param language
|
||||
* The LanguageCode for the preferred language to select. If no
|
||||
* The language code for the preferred language to select. If no
|
||||
* message in the preferred language is present, the English
|
||||
* MessageContent will be returned.
|
||||
* @return A MessageContent object. If the given vector is empty, a
|
||||
* default-constructed MessageContent is returned.
|
||||
*/
|
||||
LOOT_API static MessageContent Choose(const std::vector<MessageContent> content,
|
||||
const LanguageCode language);
|
||||
const std::string& language);
|
||||
private:
|
||||
std::string text_;
|
||||
LanguageCode language_;
|
||||
std::string language_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -138,11 +138,11 @@ public:
|
||||
/**
|
||||
* Choose an info MessageContent object given a preferred language.
|
||||
* @param language
|
||||
* The preferred language's LanguageCode.
|
||||
* The preferred language's code.
|
||||
* @return The MessageContent object for the preferred language, or if one
|
||||
* does not exist, the English-language MessageContent object.
|
||||
*/
|
||||
LOOT_API MessageContent ChooseInfo(const LanguageCode language) const;
|
||||
LOOT_API MessageContent ChooseInfo(const std::string& language) const;
|
||||
private:
|
||||
uint32_t crc_;
|
||||
unsigned int itm_;
|
||||
|
||||
@@ -176,7 +176,7 @@ public:
|
||||
* The language to create the SimpleMessage objects for.
|
||||
* @return The plugin's messages as SimpleMessage objects.
|
||||
*/
|
||||
LOOT_API std::vector<SimpleMessage> GetSimpleMessages(const LanguageCode language) const;
|
||||
LOOT_API std::vector<SimpleMessage> GetSimpleMessages(const std::string& language) const;
|
||||
|
||||
/**
|
||||
* Set whether the plugin metadata is enabled for use during sorting or not.
|
||||
|
||||
@@ -33,7 +33,7 @@ struct SimpleMessage {
|
||||
MessageType type;
|
||||
|
||||
/** @brief The language the message string is written in. */
|
||||
LanguageCode language;
|
||||
std::string language;
|
||||
|
||||
/**
|
||||
* @brief The message string, which may be formatted using
|
||||
|
||||
@@ -74,14 +74,14 @@ struct convert<loot::Message> {
|
||||
if (node["content"].IsSequence())
|
||||
content = node["content"].as< std::vector<loot::MessageContent> >();
|
||||
else {
|
||||
content.push_back(loot::MessageContent(node["content"].as<std::string>(), loot::LanguageCode::english));
|
||||
content.push_back(loot::MessageContent(node["content"].as<std::string>()));
|
||||
}
|
||||
|
||||
//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.GetLanguage() == loot::LanguageCode::english)
|
||||
if (mc.GetLanguage() == loot::MessageContent::defaultLanguage)
|
||||
found = true;
|
||||
}
|
||||
if (!found)
|
||||
|
||||
@@ -36,7 +36,7 @@ struct convert<loot::MessageContent> {
|
||||
static Node encode(const loot::MessageContent& rhs) {
|
||||
Node node;
|
||||
node["text"] = rhs.GetText();
|
||||
node["lang"] = loot::Language(rhs.GetLanguage()).GetLocale();
|
||||
node["lang"] = rhs.GetLanguage();
|
||||
|
||||
return node;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ struct convert<loot::MessageContent> {
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'lang' key missing from 'message content' object");
|
||||
|
||||
std::string text = node["text"].as<std::string>();
|
||||
loot::LanguageCode lang = loot::Language(node["lang"].as<std::string>()).GetCode();
|
||||
std::string lang = node["lang"].as<std::string>();
|
||||
|
||||
rhs = loot::MessageContent(text, lang);
|
||||
|
||||
@@ -61,7 +61,7 @@ struct convert<loot::MessageContent> {
|
||||
inline Emitter& operator << (Emitter& out, const loot::MessageContent& rhs) {
|
||||
out << BeginMap;
|
||||
|
||||
out << Key << "lang" << Value << loot::Language(rhs.GetLanguage()).GetLocale();
|
||||
out << Key << "lang" << Value << rhs.GetLanguage();
|
||||
|
||||
out << Key << "text" << Value << YAML::SingleQuoted << rhs.GetText();
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ struct convert<loot::PluginCleaningData> {
|
||||
if (node["info"].IsSequence())
|
||||
info = node["info"].as<std::vector<loot::MessageContent>>();
|
||||
else {
|
||||
info.push_back(loot::MessageContent(node["info"].as<std::string>(), loot::LanguageCode::english));
|
||||
info.push_back(loot::MessageContent(node["info"].as<std::string>()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ struct convert<loot::PluginCleaningData> {
|
||||
if (info.size() > 1) {
|
||||
bool found = false;
|
||||
for (const auto &mc : info) {
|
||||
if (mc.GetLanguage() == loot::LanguageCode::english)
|
||||
if (mc.GetLanguage() == loot::MessageContent::defaultLanguage)
|
||||
found = true;
|
||||
}
|
||||
if (!found)
|
||||
|
||||
Reference in New Issue
Block a user