Localization
Loads i18n JSON into Persistent.configuration.i18n[language][key] at startup. Runtime lookups are state reads only.
Policy: Internal — no Unity adapter; current language is stored at the root of Persistent: Persistent.language.
State
| Path | Purpose |
|---|---|
Persistent.language | Current language / locale code (default en) |
Persistent.configuration.i18n | Nested languages → keys → strings |
How it looks in persistent.json
language at the Persistent root is the canonical persisted language field. Legacy saves may still have settings.language; it is migrated to the root on first read. i18n is filled when Configuration loads language packs — structure is configuration.i18n[languageCode][stringKey].
persistent.json
{
"Persistent": {
"language": "en",
"settings": {
"version": "1.0.0"
},
"configuration": {
"i18n": {
"en": {
"ui.example.greeting": "Hello"
}
}
}
}
}Real projects ship many keys per language; keys are whatever your JSON packs define.
Events
| Event id | When |
|---|---|
FACT_LOCALIZATION_LANGUAGE_CHANGED | After SetLanguage updates Persistent.language (payload built in GnosisLocalizationService) |
Functions
| Function | Parameters | Result |
|---|---|---|
GetCurrentLanguage | — | { language: string } |
SetLanguage | language | Persists + publishes FACT_LOCALIZATION_LANGUAGE_CHANGED (see Events) |
GetString | key, optional fallback | { value: string }; falls back to en then key |
Usage example — GetString
LocalizationService.Example1.cs
private string ReadUiString(string key, string fallback = "")
{
if (Context?.Store == null || Context.CallService == null)
return fallback;
var args = GnosisNode.CreateObject(Context.Store);
args.Set("key", key);
if (!string.IsNullOrEmpty(fallback))
args.Set("fallback", fallback);
var result = CallService("Localization", "GetString", args);
if (!result.Success || !result.Data.IsValid)
return fallback;
var n = result.Data["value"];
return n.IsValid && n.Type == GnosisValueType.String ? (string)n : fallback;
}Usage example — SetLanguage
LocalizationService.Example2.cs
private void SetRunLanguage(string code)
{
if (Context?.Store == null || Context.CallService == null)
return;
var args = GnosisNode.CreateObject(Context.Store);
args.Set("language", code);
CallService("Localization", "SetLanguage", args);
}Statistics
None.
Last updated on