FLocalizationManager
- Module
- Core
- Header
#include "Core/Localization.h"- Namespace
Mowo
Public functions
| Returns | Name | Description |
|---|---|---|
FLocalizationManager& | Get | |
void | SetLocale | Changing the locale bumps the revision and fires every registered callback, which is how already-built UI re-resolves without being torn down. |
const std::string& | GetLocale | |
void | SetFallbackLocale | The locale a miss in the active one falls through to before the source string. |
const std::string& | GetFallbackLocale | |
uint32_t | GetRevision | Incremented on every locale change. |
uint32_t | AddLocaleChangedCallback | Returns a handle for RemoveLocaleChangedCallback. |
void | RemoveLocaleChangedCallback | |
void | AddEntry | |
uint32_t | AddEntriesFromText | Parse "key=value" lines (blank lines skipped; whitespace around the key trimmed) into (locale, ns). |
const std::string* | Find | |
const FStringTableEntry* | FindEntry | |
std::string | Resolve | Active locale → fallback locale → the authored source string. |
EPluralCategory | PluralCategory | CLDR cardinal category of count under locale's rules (integer counts only — game quantities are integers). |
EPluralCategory | OrdinalCategory | CLDR ordinal category ("1st", "2nd", "3rd", "4th" in English; "1er" against everything else in French). |
const char* | PluralSuffix | "zero"/"one"/"two"/"few"/"many"/"other" |
std::string | ResolvePlural | Plural-aware resolve: variants live in the tables as key.one, key.few, key.many, key.other. |
std::string | ResolveSelect | Gender / arbitrary select: variants live as key.<form> with key.other as the catch-all, so "greeting.male" / "greeting.female" / "greeting.other" is one table and one call. |
std::vector<std::string> | GetLoadedLocales | Every locale that has at least one entry, sorted. |
void | SetPseudoLocalization | Pseudo-localization: every string that resolves through a table (or its source) comes back accented, about a third longer and bracketed — "[Ƥĺàý ~~]". |
bool | IsPseudoLocalizationEnabled | |
std::string | PseudoLocalize | |
void | SetMissingKeyPolicy | |
EMissingKeyPolicy | GetMissingKeyPolicy | |
const std::unordered_set<std::string>& | GetMissingKeys | Distinct (namespace, key) pairs that resolved to their source string while tables were loaded. |
void | Clear |
Function details
Get
static FLocalizationManager& Get()SetLocale
void SetLocale(const std::string& locale)Changing the locale bumps the revision and fires every registered callback, which is how already-built UI re-resolves without being torn down. Setting the locale it already has does neither.
GetLocale
const std::string& GetLocale() constSetFallbackLocale
void SetFallbackLocale(const std::string& locale)The locale a miss in the active one falls through to before the source string. Defaults to "en".
GetFallbackLocale
const std::string& GetFallbackLocale() constGetRevision
uint32_t GetRevision() constIncremented on every locale change. A cache keyed on it re-derives exactly once per switch instead of comparing strings every frame.
AddLocaleChangedCallback
uint32_t AddLocaleChangedCallback(std::function<void(const std::string&)> callback)Returns a handle for RemoveLocaleChangedCallback. The callback runs inside SetLocale, on the thread that called it.
RemoveLocaleChangedCallback
void RemoveLocaleChangedCallback(uint32_t handle)AddEntry
void AddEntry(const std::string& locale, const std::string& ns, const std::string& key, const std::string& value, const std::string& source = std::string())AddEntriesFromText
uint32_t AddEntriesFromText(const std::string& locale, const std::string& ns, const std::string& text)Parse "key=value" lines (blank lines skipped; whitespace around the key trimmed) into (locale, ns). A comment line of the form "# @source <text>" attaches that source string to the NEXT entry, which is how an extracted table records what its translations were made against; every other '#' line is ignored. Returns entries added.
Find
const std::string* Find(const std::string& locale, const std::string& ns, const std::string& key) constFindEntry
const FStringTableEntry* FindEntry(const std::string& locale, const std::string& ns, const std::string& key) constResolve
std::string Resolve(const std::string& ns, const std::string& key, const std::string& fallback) constActive locale → fallback locale → the authored source string.
PluralCategory
static EPluralCategory PluralCategory(const std::string& locale, int64_t count)CLDR cardinal category of count under locale's rules (integer counts only — game quantities are integers). Region subtags are ignored ("ru-RU" → "ru"); unknown languages use the English rule, so a new locale degrades to two forms instead of crashing or pluralizing Russian with an English rule silently — the table fallback below still finds .other. The rules are CLDR's cardinal rules for integers, generated by hand from plurals.xml: en de nl sv da nb fi et it es ca gl el hu tr bg ka (one/other), fr and pt-BR (0 and 1 are one; fr has many for exact millions), pt-PT, hi bn gu kn mr fa (0 and 1 are one), ru uk be, pl, cs sk, hr sr bs, lt, lv, ro, he, sl, mk, ar, cy, ga, and the no-plural group ja zh ko vi th id ms lo my km.
OrdinalCategory
static EPluralCategory OrdinalCategory(const std::string& locale, int64_t count)CLDR ordinal category ("1st", "2nd", "3rd", "4th" in English; "1er" against everything else in French). Unknown languages are Other.
PluralSuffix
static const char* PluralSuffix(EPluralCategory category)"zero"/"one"/"two"/"few"/"many"/"other"
ResolvePlural
std::string ResolvePlural(const std::string& ns, const std::string& key, int64_t count, const std::string& fallback) constPlural-aware resolve: variants live in the tables as key.one, key.few, key.many, key.other. Ladder: active-locale category → active-locale .other → fallback-locale category → fallback-locale .other → source. Every "{n}" in the winning pattern is replaced with the count, so callers write one line: ResolvePlural("Game", "cards_left", n, "{n} cards").
ResolveSelect
std::string ResolveSelect(const std::string& ns, const std::string& key, const std::string& form, const std::string& fallback) constGender / arbitrary select: variants live as key.<form> with key.other as the catch-all, so "greeting.male" / "greeting.female" / "greeting.other" is one table and one call. Same ladder as the plural resolve, with the caller's form in place of the plural category.
GetLoadedLocales
std::vector<std::string> GetLoadedLocales() constEvery locale that has at least one entry, sorted. This is what a language selector lists when nothing has enumerated the content directory for it.
SetPseudoLocalization
void SetPseudoLocalization(bool enabled)Pseudo-localization: every string that resolves through a table (or its source) comes back accented, about a third longer and bracketed — "[Ƥĺàý ~~]". A string that still reads in plain English was never localized; one whose bracket is cut off does not fit a longer language. Placeholders, |plural(...) forms, markup tags and entities are left intact. Switching it bumps the revision like a locale change.
IsPseudoLocalizationEnabled
bool IsPseudoLocalizationEnabled() constPseudoLocalize
static std::string PseudoLocalize(const std::string& text)SetMissingKeyPolicy
void SetMissingKeyPolicy(EMissingKeyPolicy policy)GetMissingKeyPolicy
EMissingKeyPolicy GetMissingKeyPolicy() constGetMissingKeys
const std::unordered_set<std::string>& GetMissingKeys() constDistinct (namespace, key) pairs that resolved to their source string while tables were loaded. A dev overlay and the tests read this instead of scraping stderr.
Clear
void Clear()