Added translation for thrown error strings, updated template file.

This commit is contained in:
WrinklyNinja
2013-09-20 15:09:15 +01:00
parent 0131b51b3d
commit c8b3641a73
11 changed files with 782 additions and 471 deletions
File diff suppressed because it is too large Load Diff
+23 -11
View File
@@ -33,6 +33,7 @@
using namespace std;
namespace fs = boost::filesystem;
namespace lc = boost::locale;
namespace boss {
@@ -90,8 +91,10 @@ namespace boss {
_masterFile = "FalloutNV.esm";
espm::InitPredefinedSettings("FalloutNV", espm_settings);
_masterlistURL = "https://github.com/boss-developers/boss-fallout-new-vegas.git";
} else
throw error(error::invalid_args, "Invalid game ID supplied.");
} else {
BOOST_LOG_TRIVIAL(error) << "Invalid game ID supplied.";
throw error(error::invalid_args, lc::translate("Invalid game ID supplied.").str());
}
if (!folder.empty())
bossFolderName = folder;
@@ -135,8 +138,10 @@ namespace boss {
}
}
if (gamePath.empty())
throw error(error::path_not_found, "Game path could not be detected.");
if (gamePath.empty()) {
BOOST_LOG_TRIVIAL(error) << "Game path could not be detected.";
throw error(error::path_not_found, lc::translate("Game path could not be detected.").str());
}
RefreshActivePluginsList();
CreateBOSSGameFolder();
@@ -232,7 +237,8 @@ namespace boss {
if (ret != LIBLO_OK && ret != LIBLO_WARN_LO_MISMATCH) {
const char * e;
lo_get_error_message(&e);
string err = string("libloadorder failed to create a game handle. Details: ") + e;
BOOST_LOG_TRIVIAL(error) << "libloadorder failed to create a game handle. Details: " << e;
string err = lc::translate("libloadorder failed to create a game handle. Details: ").str() + e;
lo_cleanup();
throw error(error::liblo_error, err);
}
@@ -243,7 +249,8 @@ namespace boss {
const char * e;
lo_get_error_message(&e);
lo_destroy_handle(gh);
string err = string("libloadorder total conversion support setup failed. Details: ") + e;
BOOST_LOG_TRIVIAL(error) << "libloadorder failed to initialise game master file support. Details: " << e;
string err = lc::translate("libloadorder failed to initialise game master file support. Details: ").str() + e;
lo_cleanup();
throw error(error::liblo_error, err);
}
@@ -252,7 +259,8 @@ namespace boss {
const char * e;
lo_get_error_message(&e);
lo_destroy_handle(gh);
string err = string("libloadorder failed to get the active plugins list. Details: ") + e;
BOOST_LOG_TRIVIAL(error) << "libloadorder failed to get the active plugins list. Details: " << e;
string err = lc::translate("libloadorder failed to get the active plugins list. Details: ").str() + e;
lo_cleanup();
throw error(error::liblo_error, err);
}
@@ -286,7 +294,8 @@ namespace boss {
if (ret != LIBLO_OK && ret != LIBLO_WARN_LO_MISMATCH) {
const char * e;
lo_get_error_message(&e);
string err = string("libloadorder game handle creation failed. Details: ") + e;
BOOST_LOG_TRIVIAL(error) << "libloadorder failed to create a game handle. Details: " << e;
string err = lc::translate("libloadorder failed to create a game handle. Details: ").str() + e;
lo_cleanup();
throw error(error::liblo_error, err);
}
@@ -297,7 +306,8 @@ namespace boss {
const char * e;
lo_get_error_message(&e);
lo_destroy_handle(gh);
string err = string("libloadorder total conversion support setup failed. Details: ") + e;
BOOST_LOG_TRIVIAL(error) << "libloadorder failed to initialise game master file support. Details: " << e;
string err = lc::translate("libloadorder failed to initialise game master file support. Details: ").str() + e;
lo_cleanup();
throw error(error::liblo_error, err);
}
@@ -318,7 +328,8 @@ namespace boss {
const char * e;
lo_get_error_message(&e);
lo_destroy_handle(gh);
string err = string("libloadorder failed to set the load order. Details: ") + e;
BOOST_LOG_TRIVIAL(error) << "libloadorder failed to set the load order. Details: " << e;
string err = lc::translate("libloadorder failed to set the load order. Details: ").str() + e;
lo_cleanup();
throw error(error::liblo_error, err);
}
@@ -336,7 +347,8 @@ namespace boss {
if (!fs::exists(g_path_local / bossFolderName))
fs::create_directory(g_path_local / bossFolderName);
} catch (fs::filesystem_error& e) {
throw error(error::path_write_fail, string("Could not create BOSS folder for game. Details: ") + e.what());
BOOST_LOG_TRIVIAL(error) << "Could not create BOSS folder for game. Details: " << e.what();
throw error(error::path_write_fail, lc::translate("Could not create BOSS folder for game. Details: ").str() + e.what());
}
}
}
+4 -2
View File
@@ -554,8 +554,10 @@ namespace boss {
AppendScripts(body);
if (!doc.save_file(file.c_str(), "\t", pugi::format_default | pugi::format_no_declaration))
throw boss::error(boss::error::path_write_fail, "Could not write BOSS report.");
if (!doc.save_file(file.c_str(), "\t", pugi::format_default | pugi::format_no_declaration)) {
BOOST_LOG_TRIVIAL(error) << "Could not write BOSS report.";
throw boss::error(boss::error::path_write_fail, boost::locale::translate("Could not write BOSS report.").str());
}
}
+14
View File
@@ -27,11 +27,25 @@
#include <boost/algorithm/string.hpp>
#include <boost/log/trivial.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/locale.hpp>
#include <boost/format.hpp>
using namespace std;
namespace lc = boost::locale;
namespace boss {
cycle_detector::cycle_detector() {}
void cycle_detector::back_edge(edge_t e, const PluginGraph& g) {
vertex_t vSource = boost::source(e, g);
vertex_t vTarget = boost::target(e, g);
BOOST_LOG_TRIVIAL(error) << "Back edge detected between plugins \"" << g[vSource].Name() << "\" and \"" << g[vTarget].Name() << "\".";
throw boss::error(boss::error::sorting_error, (boost::format(lc::translate("Back edge detected between plugins \"%1%\" and \"%2%\".")) % g[vSource].Name() % g[vTarget].Name()).str());
}
bool GetVertexByName(const PluginGraph& graph, const std::string& name, vertex_t& vertex) {
vertex_it vit, vit_end;
boost::tie(vit, vit_end) = boost::vertices(graph);
+2 -7
View File
@@ -42,14 +42,9 @@ namespace boss {
typedef boost::graph_traits<PluginGraph>::edge_iterator edge_it;
struct cycle_detector : public boost::dfs_visitor<> {
inline cycle_detector() { }
cycle_detector();
inline void back_edge(edge_t e, const PluginGraph& g) {
vertex_t vSource = boost::source(e, g);
vertex_t vTarget = boost::target(e, g);
throw boss::error(boss::error::sorting_error, "Back edge detected between plugins \"" + g[vSource].Name() + "\" and \"" + g[vTarget].Name() + "\".");
}
void back_edge(edge_t e, const PluginGraph& g);
};
bool GetVertexByName(const PluginGraph& graph, const std::string& name, vertex_t& vertex);
+11 -7
View File
@@ -30,6 +30,8 @@
#include <boost/crc.hpp>
#include <boost/regex.hpp>
#include <boost/log/trivial.hpp>
#include <boost/format.hpp>
#include <boost/locale.hpp>
#include <alphanum.hpp>
@@ -59,6 +61,7 @@ namespace boss {
using boost::algorithm::replace_first;
namespace karma = boost::spirit::karma;
namespace fs = boost::filesystem;
namespace lc = boost::locale;
/// REGEX expression definition
@@ -124,7 +127,7 @@ namespace boss {
static const size_t buffer_size = 8192;
char buffer[buffer_size];
boss::ifstream ifile(filename, ios::binary);
// LOG_TRACE("calculating CRC for: '%s'", filename.string().c_str());
BOOST_LOG_TRIVIAL(trace) << "Calculating CRC for: " << filename.string();
boost::crc_32_type result;
if (ifile) {
do {
@@ -133,9 +136,10 @@ namespace boss {
} while (ifile);
chksum = result.checksum();
} else {
throw error(error::path_read_fail, "Unable to open \"" + filename.string() + "\" for CRC calculation.");
BOOST_LOG_TRIVIAL(error) << "Unable to open \"" << filename.string() << "\" for CRC calculation.";
throw error(error::path_read_fail, (boost::format(lc::translate("Unable to open \"%1%\" for CRC calculation.")) % filename.string()).str());
}
// LOG_DEBUG("CRC32('%s'): 0x%x", filename.string().c_str(), chksum);
BOOST_LOG_TRIVIAL(debug) << "CRC32(\"" << filename.string() << "\"):" << chksum;
return chksum;
}
@@ -291,7 +295,7 @@ namespace boss {
//Create I/O pipes.
if (!CreatePipe(&consoleRead, &consoleWrite, &saAttr, 0)) {
BOOST_LOG_TRIVIAL(error) << "Could not create pipe for process.";
throw error(error::windows_error, "Could not create pipe for process.");
throw error(error::windows_error, lc::translate("Could not create pipe for process."));
}
//Create a child process.
@@ -324,7 +328,7 @@ namespace boss {
if (!result) {
BOOST_LOG_TRIVIAL(error) << "Could not create process.";
throw error(error::windows_error, "Could not create process.");
throw error(error::windows_error, lc::translate("Could not create process."));
}
BOOST_LOG_TRIVIAL(trace) << "Waiting for process to complete.";
@@ -335,14 +339,14 @@ namespace boss {
if (!GetExitCodeProcess(piProcInfo.hProcess, &exitCode)) {
BOOST_LOG_TRIVIAL(error) << "Could not get process exit code.";
throw error(error::windows_error, "Could not get process exit code.");
throw error(error::windows_error, lc::translate("Could not get process exit code."));
}
BOOST_LOG_TRIVIAL(trace) << "Getting the process output.";
if (!ReadFile(consoleRead, chBuf, BUFSIZE, &dwRead, NULL)) {
BOOST_LOG_TRIVIAL(error) << "Could not read process output.";
throw error(error::windows_error, "Could not read process output.");
throw error(error::windows_error, lc::translate("Could not read process output."));
}
output = string(chBuf, dwRead);
+9 -4
View File
@@ -411,8 +411,10 @@ namespace boss {
std::map<std::string, std::string>::const_iterator it = varConditionMap.find(boost::to_lower_copy(var));
if (it == varConditionMap.end())
throw boss::error(boss::error::condition_eval_fail, "The variable \"" + var + "\" was not previously defined.");
if (it == varConditionMap.end()) {
BOOST_LOG_TRIVIAL(error) << "The variable \"" << var << "\" was not previously defined.";
throw boss::error(boss::error::condition_eval_fail, "The variable \"" + var + "\" was not previously defined."); //Isn't used by BOSS application, so don't need to translate.
}
if (ifIfnotStr == "if ")
output = it->second;
@@ -686,7 +688,8 @@ namespace boss {
std::string context(errorpos, min(errorpos +50, last));
boost::trim(context);
throw boss::error(boss::error::condition_eval_fail, "Error parsing at \"" + context + "\", expected \"" + what.tag + "\"");
BOOST_LOG_TRIVIAL(error) << "Error parsing at \"" << context << "\", expected \"" << what.tag << "\".";
throw boss::error(boss::error::condition_eval_fail, "Expected \"" + what.tag + "\" at \"" + context + "\"."); //Isn't used by BOSS application, so don't need to translate.
}
};
@@ -712,8 +715,10 @@ namespace boss {
bool r = phrase_parse(begin, end, grammar, skipper, plugins);
if (!r || begin != end)
if (!r || begin != end) {
BOOST_LOG_TRIVIAL(error) << "Failed to read file: " << file.string();
throw boss::error(boss::error::path_read_fail, file.string());
}
}
}
#endif
+9 -3
View File
@@ -31,11 +31,14 @@
#include <boost/filesystem.hpp>
#include <boost/regex.hpp>
#include <boost/log/trivial.hpp>
#include <boost/locale.hpp>
using namespace std;
namespace boss {
namespace lc = boost::locale;
FormID::FormID() : id(0) {}
FormID::FormID(const std::string& sourcePlugin, const uint32_t objectID) : plugin(sourcePlugin), id(objectID) {}
@@ -106,11 +109,14 @@ namespace boss {
try {
r = boost::spirit::qi::phrase_parse(begin, end, grammar, skipper, eval);
} catch (boss::error& e) {
throw boss::error(boss::error::path_read_fail, "Parsing of condition \"" + _condition + "\" failed: " + e.what());
BOOST_LOG_TRIVIAL(error) << "Failed to parse condition \"" << _condition << "\": " << e.what();
throw boss::error(boss::error::path_read_fail, (boost::format(lc::translate("Failed to parse condition \"%1%\": %2%")) % _condition % e.what()).str());
}
if (!r || begin != end)
throw boss::error(boss::error::path_read_fail, "Parsing of condition \"" + _condition + "\" failed!");
if (!r || begin != end) {
BOOST_LOG_TRIVIAL(error) << "Failed to parse condition \"" << _condition << "\".";
throw boss::error(boss::error::path_read_fail, (boost::format(lc::translate("Failed to parse condition \"%1%\".")) % _condition).str());
}
game.conditionCache.emplace(boost::to_lower_copy(_condition), eval);
+10 -8
View File
@@ -29,12 +29,14 @@
#include <boost/log/trivial.hpp>
#include <boost/locale.hpp>
#include <boost/format.hpp>
#include <git2.h>
using namespace std;
namespace fs = boost::filesystem;
namespace lc = boost::locale;
namespace boss {
@@ -56,21 +58,21 @@ namespace boss {
git_commit * commit;
};
//Returns false for errors, true for OK.
void handle_error(int error_code, pointers_struct& pointers) {
if (!error_code)
return;
const git_error * error = giterr_last();
std::string error_message = "An error occurred during a Git operation. Error code: " + IntToString(error_code) + ".";
if (error != NULL)
error_message += string(" Message: ") + error->message;
BOOST_LOG_TRIVIAL(error) << error_message;
std::string error_message;
if (error == NULL)
error_message = IntToString(error_code) + ".";
else
error_message = IntToString(error_code) + "; " + error->message;
pointers.free();
giterr_clear();
throw boss::error(boss::error::git_error, error_message);
BOOST_LOG_TRIVIAL(error) << "Git operation failed. Error: " << error_message;
throw boss::error(boss::error::git_error, (boost::format(lc::translate("Git operation failed. Error: %1%")) % error_message).str());
}
std::string UpdateMasterlist(Game& game, std::list<Message>& parsingErrors, std::list<Plugin>& plugins, std::list<Message>& messages) {
+12 -10
View File
@@ -49,6 +49,8 @@
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_bind.hpp>
#include <boost/log/trivial.hpp>
#include <boost/locale.hpp>
#include <boost/format.hpp>
namespace YAML {
@@ -417,8 +419,8 @@ namespace boss {
}
if (!IsSafePath(file)) {
BOOST_LOG_TRIVIAL(error) << "The file path is invalid.";
throw boss::error(boss::error::invalid_args, "The file path \"" + file + "\" is invalid.");
BOOST_LOG_TRIVIAL(error) << "Invalid file path: " << file;
throw boss::error(boss::error::invalid_args, boost::locale::translate("Invalid file path: ").str() + file);
}
if (IsPlugin(file))
@@ -465,8 +467,8 @@ namespace boss {
}
if (boost::contains(parent, "../../")){
BOOST_LOG_TRIVIAL(error) << "The folder path \"" << parent << "\" is invalid.";
throw boss::error(boss::error::invalid_args, "The folder path \"" + parent + "\" is invalid.");
BOOST_LOG_TRIVIAL(error) << "Invalid folder path: " << parent;
throw boss::error(boss::error::invalid_args, boost::locale::translate("Invalid folder path: ").str() + parent);
}
//Now we have a valid parent path and a regex filename. Check that
@@ -480,8 +482,8 @@ namespace boss {
try {
regex = boost::regex(filename, boost::regex::perl|boost::regex::icase);
} catch (boost::regex_error& e) {
BOOST_LOG_TRIVIAL(error) << "The regex string \"" << filename << "\" is invalid.";
throw boss::error(boss::error::invalid_args, "The regex string \"" + filename + "\" is invalid.");
BOOST_LOG_TRIVIAL(error) << "Invalid regex string:" << filename;
throw boss::error(boss::error::invalid_args, boost::locale::translate("Invalid regex string:").str() + filename);
}
for (boost::filesystem::directory_iterator itr(parent_path); itr != boost::filesystem::directory_iterator(); ++itr) {
@@ -497,8 +499,8 @@ namespace boss {
BOOST_LOG_TRIVIAL(trace) << "Checking the CRC of the file \"" << file << "\".";
if (!IsSafePath(file)) {
BOOST_LOG_TRIVIAL(error) << "The file path is invalid.";
throw boss::error(boss::error::invalid_args, "The file path \"" + file + "\" is invalid.");
BOOST_LOG_TRIVIAL(error) << "Invalid file path: " << file;
throw boss::error(boss::error::invalid_args, boost::locale::translate("Invalid file path: ").str() + file);
}
uint32_t crc;
@@ -563,9 +565,9 @@ namespace boss {
std::string context(errorpos, min(errorpos +50, last));
boost::trim(context);
BOOST_LOG_TRIVIAL(error) << "Error parsing condition at \"" << context << "\", expected \"" << what.tag << "\"";
BOOST_LOG_TRIVIAL(error) << "Expected \"" << what.tag << "\" at \"" << context << "\".";
throw boss::error(boss::error::condition_eval_fail, "Error parsing condition at \"" + context + "\", expected \"" + what.tag + "\"");
throw boss::error(boss::error::condition_eval_fail, (boost::format(boost::locale::translate("Expected \"%1%\" at \"%2%\".")) % what.tag % context).str());
}
//Checks that the path (not regex) doesn't go outside any game folders.
+1 -1
View File
@@ -253,7 +253,7 @@ bool BossGUI::OnInit() {
//Need to also set up wxWidgets locale so that its default interface text comes out in the right language.
wxLoc = new wxLocale();
if (!wxLoc->Init(lang, wxLOCALE_LOAD_DEFAULT))
throw runtime_error("System GUI text could not be set.");
throw runtime_error(loc::translate("System GUI text could not be set.").str().c_str());
wxLocale::AddCatalogLookupPathPrefix(g_path_l10n.string().c_str());
wxLoc->AddCatalog("wxstd");
} catch(runtime_error &e) {