use df's translate_name function if available

requires dfhack/df-structures#666 (included)

needs testing on linux
develop
Kelly Kinkade 2023-09-30 03:01:26 -05:00
parent 7d23ea73ad
commit 34b86772d8
1 changed files with 25 additions and 1 deletions

@ -27,7 +27,7 @@ distribution.
#include <string>
#include <vector>
#include <map>
using namespace std;
#include <functional>
#include "modules/Translation.h"
#include "VersionInfo.h"
@ -36,6 +36,7 @@ using namespace std;
#include "ModuleFactory.h"
#include "Core.h"
#include "Error.h"
#include "Debug.h"
using namespace DFHack;
using namespace df::enums;
@ -44,10 +45,16 @@ using namespace df::enums;
#include "df/world.h"
#include "df/d_init.h"
using std::vector, std::string;
using df::global::world;
using df::global::d_init;
using df::global::gametype;
namespace DFHack {
DBG_DECLARE(core, translate, DebugCategory::LINFO);
}
bool Translation::IsValid ()
{
return (world && (world->raws.language.words.size() > 0) && (world->raws.language.translations.size() > 0));
@ -167,6 +174,23 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
CHECK_NULL_POINTER(name);
string out;
auto fp = df::global::translate_name;
if (fp) {
DEBUG(translate).print("using df provided translate_name function\n");
typedef std::function<void(const df::language_name&, std::string&, bool, bool)> fun_type;
auto f = reinterpret_cast<fun_type*>(fp);
try {
(*f)(*name, out, inEnglish, onlyLastPart);
return out;
}
catch (...) {
WARN(translate).print("df provided translate_name function threw an exception, falling back\n");
}
}
DEBUG(translate).print("using dfhack fallback translate_name function\n");
string word;
if (!onlyLastPart) {