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:
@@ -151,7 +151,6 @@ set (LOOT_API_SRC "${CMAKE_BINARY_DIR}/generated/loot_version.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/plugin/plugin_sorter.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/crc.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/git_helper.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/language.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/version.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/resource.rc")
|
||||
|
||||
@@ -164,12 +163,10 @@ set (LOOT_API_HEADERS "${CMAKE_SOURCE_DIR}/include/loot/api.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/file_access_error.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/git_state_error.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/enum/game_type.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/enum/language_code.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/enum/log_verbosity.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/enum/message_type.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/enum/plugin_cleanliness.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/game_interface.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/language.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/loot_version.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/metadata/conditional_metadata.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/metadata/file.h"
|
||||
@@ -213,7 +210,6 @@ set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/api/internals/game/game_t
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/game/load_order_handler_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/git_helper_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/crc_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/language_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/version_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/yaml_set_helpers_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/condition_evaluator_test.h"
|
||||
|
||||
@@ -19,14 +19,6 @@ Surprise pull requests aren't recommended because everything you touched may hav
|
||||
|
||||
When you do make a pull request, please do so from a branch which doesn't have the same name as they branch you're requesting your changes to be merged into. It's a lot easier to keep track of what pull request branches do when they're named something like `you:specific-cool-feature` rather than `you:master`.
|
||||
|
||||
### Adding Support For A New Language
|
||||
|
||||
If you're adding support for a new language, the LOOT API's source code must be updated to recognise it. The files and functions which must be updated are given below.
|
||||
|
||||
* In [language_code.h](include/loot/enum/language_code.h), append a value for the language to the `LanguageCode` enum.
|
||||
* In [language.cpp](src/api/helpers/language.cpp), define the value for the constant you added, and update `Language::Language(LanguageCode code)` and `Language::codes({...})` to include lines for your language.
|
||||
* In [localised_content.rst](docs/metadata/data_structures/localised_content.rst), add a row for your language to the Language Codes table.
|
||||
|
||||
## Code Style
|
||||
|
||||
LOOT's JavaScript uses a slightly tweaked version of the Airbnb style, and can be automatically linted by ESLint, so isn't covered here.
|
||||
|
||||
@@ -12,6 +12,11 @@ String Encoding
|
||||
* File paths are case-sensitive if and only if the underlying file system is
|
||||
case-sensitive.
|
||||
|
||||
Language Codes
|
||||
==============
|
||||
|
||||
All language strings in the API are codes of the form ``ll`` or ``ll_CC``, where ``ll`` is an ISO 639-1 language code and ``CC`` is an ISO 3166 country code. For example, the default language for metadata message content is English, identified by the code ``en``, and Brazilian Portuguese is ``pt_BR``.
|
||||
|
||||
Errors
|
||||
======
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ Enumerations
|
||||
|
||||
.. doxygenenum:: loot::GameType
|
||||
|
||||
.. doxygenenum:: loot::LanguageCode
|
||||
|
||||
.. doxygenenum:: loot::LogVerbosity
|
||||
|
||||
.. doxygenenum:: loot::MessageType
|
||||
@@ -58,9 +56,6 @@ Classes
|
||||
.. doxygenclass:: loot::File
|
||||
:members:
|
||||
|
||||
.. doxygenclass:: loot::Language
|
||||
:members:
|
||||
|
||||
.. doxygenclass:: loot::Location
|
||||
:members:
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ The localised content data structure is a key-value string map.
|
||||
|
||||
.. describe:: lang
|
||||
|
||||
**Required.** The language that ``text`` is written in, given as a POSIX language code. LOOT supports the following languages and language codes:
|
||||
**Required.** The language that ``text`` is written in, given as a code of the form ``ll`` or ``ll_CC``, where ``ll`` is an ISO 639-1 language code and ``CC`` is an ISO 3166 country code. For example,
|
||||
|
||||
==================== ==========
|
||||
Language POSIX Code
|
||||
==================== ==========
|
||||
==================== =====
|
||||
Language Code
|
||||
==================== =====
|
||||
Brazilian Portuguese pt_BR
|
||||
Chinese zh_CN
|
||||
Danish da
|
||||
@@ -26,4 +26,4 @@ The localised content data structure is a key-value string map.
|
||||
Russian ru
|
||||
Spanish es
|
||||
Swedish sv
|
||||
==================== ==========
|
||||
==================== =====
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,107 +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/>.
|
||||
*/
|
||||
|
||||
#include "loot/language.h"
|
||||
|
||||
namespace loot {
|
||||
const std::vector<LanguageCode> Language::codes({
|
||||
LanguageCode::english,
|
||||
LanguageCode::spanish,
|
||||
LanguageCode::russian,
|
||||
LanguageCode::french,
|
||||
LanguageCode::chinese,
|
||||
LanguageCode::polish,
|
||||
LanguageCode::brazilian_portuguese,
|
||||
LanguageCode::finnish,
|
||||
LanguageCode::german,
|
||||
LanguageCode::danish,
|
||||
LanguageCode::korean,
|
||||
LanguageCode::swedish
|
||||
});
|
||||
|
||||
Language::Language(LanguageCode code) : code_(code) {
|
||||
if (code_ == LanguageCode::spanish) {
|
||||
name_ = "Español";
|
||||
locale_ = "es";
|
||||
} else if (code_ == LanguageCode::russian) {
|
||||
name_ = "Русский";
|
||||
locale_ = "ru";
|
||||
} else if (code_ == LanguageCode::french) {
|
||||
name_ = "Français";
|
||||
locale_ = "fr";
|
||||
} else if (code_ == LanguageCode::chinese) {
|
||||
name_ = "简体中文";
|
||||
locale_ = "zh_CN";
|
||||
} else if (code_ == LanguageCode::polish) {
|
||||
name_ = "Polski";
|
||||
locale_ = "pl";
|
||||
} else if (code_ == LanguageCode::brazilian_portuguese) {
|
||||
name_ = "Português do Brasil";
|
||||
locale_ = "pt_BR";
|
||||
} else if (code_ == LanguageCode::finnish) {
|
||||
name_ = "suomi";
|
||||
locale_ = "fi";
|
||||
} else if (code_ == LanguageCode::german) {
|
||||
name_ = "Deutsch";
|
||||
locale_ = "de";
|
||||
} else if (code_ == LanguageCode::danish) {
|
||||
name_ = "Dansk";
|
||||
locale_ = "da";
|
||||
} else if (code_ == LanguageCode::korean) {
|
||||
name_ = "한국어";
|
||||
locale_ = "ko";
|
||||
} else if (code_ == LanguageCode::swedish) {
|
||||
name_ = "Svenska";
|
||||
locale_ = "sv";
|
||||
} else {
|
||||
code_ = LanguageCode::english;
|
||||
name_ = "English";
|
||||
locale_ = "en";
|
||||
}
|
||||
}
|
||||
|
||||
Language::Language(const std::string& locale) : Language(GetCode(locale)) {}
|
||||
|
||||
LanguageCode Language::GetCode(const std::string& locale) {
|
||||
for (LanguageCode code : codes) {
|
||||
if (locale == Language(code).GetLocale()) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
return LanguageCode::english;
|
||||
}
|
||||
|
||||
LanguageCode Language::GetCode() const {
|
||||
return code_;
|
||||
}
|
||||
|
||||
std::string Language::GetName() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
std::string Language::GetLocale() const {
|
||||
return locale_;
|
||||
}
|
||||
}
|
||||
@@ -28,14 +28,13 @@
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include "api/game/game.h"
|
||||
#include "loot/language.h"
|
||||
|
||||
namespace loot {
|
||||
Message::Message() : type_(MessageType::say) {}
|
||||
|
||||
Message::Message(const MessageType type, const std::string& content,
|
||||
const std::string& condition) : type_(type), ConditionalMetadata(condition) {
|
||||
content_.push_back(MessageContent(content, LanguageCode::english));
|
||||
content_.push_back(MessageContent(content));
|
||||
}
|
||||
|
||||
Message::Message(const MessageType type, const std::vector<MessageContent>& content,
|
||||
@@ -43,7 +42,7 @@ Message::Message(const MessageType type, const std::vector<MessageContent>& cont
|
||||
if (content.size() > 1) {
|
||||
bool englishStringExists = false;
|
||||
for (const auto &mc : content) {
|
||||
if (mc.GetLanguage() == LanguageCode::english)
|
||||
if (mc.GetLanguage() == MessageContent::defaultLanguage)
|
||||
englishStringExists = true;
|
||||
}
|
||||
if (!englishStringExists)
|
||||
@@ -53,7 +52,7 @@ Message::Message(const MessageType type, const std::vector<MessageContent>& cont
|
||||
|
||||
bool Message::operator < (const Message& rhs) const {
|
||||
if (!content_.empty() && !rhs.GetContent().empty())
|
||||
return boost::ilexicographical_compare(GetContent(LanguageCode::english).GetText(), rhs.GetContent(LanguageCode::english).GetText());
|
||||
return boost::ilexicographical_compare(GetContent(MessageContent::defaultLanguage).GetText(), rhs.GetContent(MessageContent::defaultLanguage).GetText());
|
||||
else if (content_.empty() && !rhs.GetContent().empty())
|
||||
return true;
|
||||
else
|
||||
@@ -71,10 +70,10 @@ MessageType Message::GetType() const {
|
||||
std::vector<MessageContent> Message::GetContent() const {
|
||||
return content_;
|
||||
}
|
||||
MessageContent Message::GetContent(const LanguageCode language) const {
|
||||
MessageContent Message::GetContent(const std::string& language) const {
|
||||
return MessageContent::Choose(content_, language);
|
||||
}
|
||||
SimpleMessage Message::ToSimpleMessage(const LanguageCode language) const {
|
||||
SimpleMessage Message::ToSimpleMessage(const std::string& language) const {
|
||||
MessageContent content = GetContent(language);
|
||||
SimpleMessage simpleMessage;
|
||||
|
||||
|
||||
@@ -26,18 +26,18 @@
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "loot/language.h"
|
||||
|
||||
namespace loot {
|
||||
MessageContent::MessageContent() : language_(LanguageCode::english) {}
|
||||
const std::string MessageContent::defaultLanguage = "en";
|
||||
|
||||
MessageContent::MessageContent(const std::string& text, const LanguageCode language) : text_(text), language_(language) {}
|
||||
MessageContent::MessageContent() : language_(MessageContent::defaultLanguage) {}
|
||||
|
||||
MessageContent::MessageContent(const std::string& text, const std::string& language) : text_(text), language_(language) {}
|
||||
|
||||
std::string MessageContent::GetText() const {
|
||||
return text_;
|
||||
}
|
||||
|
||||
LanguageCode MessageContent::GetLanguage() const {
|
||||
std::string MessageContent::GetLanguage() const {
|
||||
return language_;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ bool MessageContent::operator == (const MessageContent& rhs) const {
|
||||
return (boost::iequals(text_, rhs.GetText()));
|
||||
}
|
||||
MessageContent MessageContent::Choose(const std::vector<MessageContent> content,
|
||||
const LanguageCode language) {
|
||||
const std::string& language) {
|
||||
if (content.empty())
|
||||
return MessageContent();
|
||||
else if (content.size() == 1)
|
||||
@@ -59,7 +59,7 @@ MessageContent MessageContent::Choose(const std::vector<MessageContent> content,
|
||||
for (const auto &mc : content) {
|
||||
if (mc.GetLanguage() == language) {
|
||||
return mc;
|
||||
} else if (mc.GetLanguage() == LanguageCode::english)
|
||||
} else if (mc.GetLanguage() == MessageContent::defaultLanguage)
|
||||
english = mc;
|
||||
}
|
||||
return english;
|
||||
|
||||
@@ -77,7 +77,7 @@ std::vector<MessageContent> PluginCleaningData::GetInfo() const {
|
||||
return info_;
|
||||
}
|
||||
|
||||
MessageContent PluginCleaningData::ChooseInfo(const LanguageCode language) const {
|
||||
MessageContent PluginCleaningData::ChooseInfo(const std::string& language) const {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Choosing dirty info content.";
|
||||
return MessageContent::Choose(info_, language);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user