Localization Class
The primary entry point for all localization operations. Auto-initializes on first access.
Properties
csharp
// Currently active locale (null if not initialized)
Locale CurrentLocale { get; }
// True when service is ready
bool IsInitialized { get; }
// All supported locales from settings
IReadOnlyList<Locale> AvailableLocales { get; }
// Current data provider
ILocalizationProvider ActiveProvider { get; }
// Loaded configuration
LocalizationSettings Settings { get; }
// Access or inject custom service (for DI/testing)
ILocalizationService Service { get; set; }Events
csharp
// Fired when locale changes
event Action<Locale> OnLocaleChanged;
// Fired when initialization completes
event Action OnLocalizationReady;Initialization
csharp
// Initialize with settings from Resources (recommended)
Localization.Initialize();
// Initialize with custom settings
Localization.Initialize(customSettings);
// Reset service (disposes current, clears singleton)
Localization.Reset();Locale Management
csharp
// Set locale by code
Localization.SetLocale("de");
// Set locale by object
Localization.SetLocale(germanLocale);
// Detect and return best matching system locale
Locale detected = Localization.DetectSystemLocale();String Retrieval
csharp
// Simple lookup (searches all tables)
string text = Localization.Get("ui.title");
// With format arguments
string message = Localization.Get("welcome.message", playerName, level);
// From specific table
string text = Localization.Get("ui", "title");
// From specific table with arguments
string message = Localization.Get("ui", "score.format", score);
// Check if translation exists
bool exists = Localization.HasTranslation("ui.title");
bool existsInLocale = Localization.HasTranslation("ui.title", "de");
bool existsInTable = Localization.HasTranslation("ui", "title", "de");Asset Retrieval
csharp
// Get localized asset (searches all tables)
Texture2D flag = Localization.GetAsset<Texture2D>("flags.country");
AudioClip voice = Localization.GetAsset<AudioClip>("voice.greeting");
Sprite icon = Localization.GetAsset<Sprite>("icons.help");
// From specific table
Texture2D texture = Localization.GetAsset<Texture2D>("textures", "splash");
// Safe retrieval with TryGet
if (Localization.TryGetAsset<Sprite>("icons.menu", out Sprite sprite))
{
image.sprite = sprite;
}
// Check asset existence
bool hasAsset = Localization.HasAsset("flags.country");Table Management
csharp
// Register table at runtime
Localization.RegisterTable(dynamicTable);
// Unregister table
bool removed = Localization.UnregisterTable("dynamic");
// Get loaded table
StringTable table = Localization.GetTable("main");
// Asset table equivalents
Localization.RegisterAssetTable(assetTable);
Localization.UnregisterAssetTable("textures");
AssetTable table = Localization.GetAssetTable("textures");Zero-Allocation Formatting
For performance-critical paths (requires LEXIS_ZSTRING for true zero-allocation):
csharp
Span<char> buffer = stackalloc char[128];
if (Localization.TryFormat(buffer, out int written, "ui.score", score))
{
ReadOnlySpan<char> result = buffer.Slice(0, written);
// Use result without heap allocation
}