mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 02:43:44 +00:00
The NexusDashboard-parity dashboard (dDashboardServer) and everything built on it on the experimental branch: accounts, characters, properties and moderation tools, permissions shared with in-game slash commands, economy reports, World 3D and property 3D views with client scenery, scheduled events (features, vanity changes, live events, announcements, restarts), vanity files and events, the CDClient browser, the message inspector with saved captures, chat filter tools, community challenges, live ops, the AI moderator helper, and the server-side changes they need. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
1.7 KiB
C++
63 lines
1.7 KiB
C++
#include "Locale.h"
|
|
#include "tinyxml2.h"
|
|
#include "Logger.h"
|
|
|
|
namespace {
|
|
std::unordered_map<std::string, std::string> g_Phrases;
|
|
bool g_Loaded = false;
|
|
const std::string g_Empty;
|
|
}
|
|
|
|
void Locale::LoadFromFile(const std::string& filepath, const std::string& locale) {
|
|
tinyxml2::XMLDocument doc;
|
|
if (doc.LoadFile(filepath.c_str()) != tinyxml2::XML_SUCCESS) {
|
|
LOG("Failed to load locale file: %s", filepath.c_str());
|
|
return;
|
|
}
|
|
|
|
auto* root = doc.FirstChildElement("localization");
|
|
if (!root) return;
|
|
|
|
auto* phrases = root->FirstChildElement("phrases");
|
|
if (!phrases) return;
|
|
|
|
for (auto* phrase = phrases->FirstChildElement("phrase"); phrase; phrase = phrase->NextSiblingElement("phrase")) {
|
|
const char* id = phrase->Attribute("id");
|
|
if (!id) continue;
|
|
|
|
for (auto* trans = phrase->FirstChildElement("translation"); trans; trans = trans->NextSiblingElement("translation")) {
|
|
const char* loc = trans->Attribute("locale");
|
|
if (loc && locale == loc) {
|
|
const char* text = trans->GetText();
|
|
if (text) {
|
|
g_Phrases[id] = text;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
g_Loaded = true;
|
|
LOG("Loaded %zu locale phrases from %s (locale: %s)", g_Phrases.size(), filepath.c_str(), locale.c_str());
|
|
}
|
|
|
|
const std::string& Locale::GetPhrase(const std::string& phraseId) {
|
|
auto it = g_Phrases.find(phraseId);
|
|
if (it != g_Phrases.end()) return it->second;
|
|
return g_Empty;
|
|
}
|
|
|
|
bool Locale::IsLoaded() {
|
|
return g_Loaded;
|
|
}
|
|
|
|
std::vector<std::string> Locale::GetPhraseIdsWithPrefix(const std::string& prefix) {
|
|
std::vector<std::string> result;
|
|
for (const auto& [key, _] : g_Phrases) {
|
|
if (key.compare(0, prefix.size(), prefix) == 0) {
|
|
result.push_back(key);
|
|
}
|
|
}
|
|
return result;
|
|
}
|