feat(locale): load every locale in locale.xml on request

Locale::LoadFromFile can keep the other locales' phrases too, and
GetPhrase(id, locale) answers in one of them, falling back to the default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-29 20:42:01 -05:00
parent 8cbae8bb22
commit 40d9364770
2 changed files with 52 additions and 10 deletions

View File

@@ -5,8 +5,17 @@
#include <vector>
namespace Locale {
void LoadFromFile(const std::string& filepath, const std::string& locale = "en_US");
/**
* Load the client's locale.xml: the phrases of `locale` (the default, which GetPhrase(id) answers from) and, with
* `allLocales`, those of every other locale the file lists too. Replaces what an earlier load read. Call before
* other threads read phrases; lookups only read afterwards.
*/
void LoadFromFile(const std::string& filepath, const std::string& locale = "en_US", bool allLocales = false);
const std::string& GetPhrase(const std::string& phraseId);
// The phrase in `locale`, else in the default locale; empty when neither has it
const std::string& GetPhrase(const std::string& phraseId, const std::string& locale);
// The locales loaded ("en_US", "de_DE", ...), the default first; empty before a load
const std::vector<std::string>& GetLocales();
bool IsLoaded();
std::vector<std::string> GetPhraseIdsWithPrefix(const std::string& prefix);
};